source: cmedia/trunk/Drv16/queue.cpp@ 354

Last change on this file since 354 was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 3.8 KB
Line 
1/* $Id: queue.cpp,v 1.1 2000/04/23 14:55:19 ktk Exp $ */
2
3/* SCCSID = %W% %E% */
4/****************************************************************************
5 * *
6 * Copyright (c) IBM Corporation 1994 - 1997. *
7 * *
8 * The following IBM OS/2 source code is provided to you solely for the *
9 * the purpose of assisting you in your development of OS/2 device drivers. *
10 * You may use this code in accordance with the IBM License Agreement *
11 * provided in the IBM Device Driver Source Kit for OS/2. *
12 * *
13 ****************************************************************************/
14/**@internal %W%
15 * @notes
16 * @version %I%
17 * @context Unless otherwise noted, all interfaces are Ring-0, 16-bit,
18 * <stack context>.
19 * @history
20 *
21 */
22#define INCL_NOPMAPI
23//#define INCL_DOSERRORS // for ERROR_INVALID_FUNCTION
24#include <os2.h>
25#include "queue.hpp"
26
27/*
28Rudi: now inlined ...
29PQUEUEELEMENT QUEUEHEAD::Head(void)
30{
31 return(pHead);
32}
33
34PQUEUEELEMENT QUEUEHEAD::Tail(void)
35{
36 return(pTail);
37}
38*/
39
40void QUEUEHEAD::PushOnHead(PQUEUEELEMENT pElement)
41{
42 if (pHead == NULL) {
43 pElement->pNext = NULL;
44 pHead = pElement;
45 pTail = pElement;
46 }
47 else {
48 pElement->pNext = pHead;
49 pHead = pElement;
50 } /* endif */
51
52}
53void QUEUEHEAD::PushOnTail(PQUEUEELEMENT pElement)
54{
55 pElement->pNext = NULL;
56 if (pHead == NULL) {
57 pHead = pElement;
58 pTail = pElement;
59 }
60 else {
61 pTail->pNext = pElement;
62 pTail = pElement;
63 } /* endif */
64
65}
66PQUEUEELEMENT QUEUEHEAD::PopHead(void)
67{
68 PQUEUEELEMENT temp = pHead;
69
70 if (temp) {
71 pHead = temp->pNext;
72 if (pHead == NULL)
73 pTail = NULL;
74 temp->pNext = NULL;
75 }
76 return(temp);
77}
78PQUEUEELEMENT QUEUEHEAD::PopTail(void)
79{
80 PQUEUEELEMENT temp = pTail;
81 PQUEUEELEMENT temp2 = pHead;
82
83 // only 1 element on queue or it's empty
84 // zapp the head and tail pointers
85 // zapp the next pointer in the element being returned
86 // get out of here
87 if (pHead == pTail) {
88 pHead = NULL;
89 pTail = NULL;
90 if (temp)
91 temp->pNext = NULL;
92 return(temp);
93 }
94 else {
95 if (temp) {
96 while (temp2->pNext != temp)
97 temp2 = temp2->pNext;
98 pTail = temp2;
99
100 if (pTail == NULL)
101 pHead = NULL;
102 else
103 pTail->pNext = NULL;
104 temp->pNext = NULL;
105 }
106 }
107 return(temp);
108}
109
110USHORT QUEUEHEAD::DestroyElement(PQUEUEELEMENT pElement)
111{
112 if (PopElement(pElement)) {
113 delete(pElement);
114 return(1);
115 }
116 else
117 return(0);
118
119
120}
121PQUEUEELEMENT QUEUEHEAD::PopElement(PQUEUEELEMENT pElement)
122{
123 PQUEUEELEMENT temp;
124
125 // if the queue is empty return NULL
126 if (pHead == NULL)
127 return (NULL);
128
129 // Popping the head element
130 if (pElement == pHead)
131 return(PopHead());
132
133 // Popping the tail element
134 if (pElement == pTail)
135 return(PopTail());
136
137 temp = pHead;
138 // walk the queue till we find the element or we hit the end
139 while ((temp->pNext != pElement) && (temp->pNext != NULL))
140 temp = temp->pNext;
141 if (temp == NULL) // element not found
142 return(NULL);
143 temp->pNext = pElement->pNext;
144 return(pElement);
145
146}
147
148/*
149Rudi: now inlined, return value changed from ULONG to BOOL
150BOOL QUEUEHEAD::IsElements(void)
151{
152 if (pHead == NULL)
153 return(0);
154 else
155 return(1);
156}
157
158
159QUEUEHEAD::QUEUEHEAD(void)
160{
161 pHead = NULL;
162 pTail = NULL;
163}
164
165*/
Note: See TracBrowser for help on using the repository browser.