source: sbliveos2/trunk/drv16/queue.cpp@ 178

Last change on this file since 178 was 142, checked in by ktk, 25 years ago

Import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: queue.cpp 142 2000-04-23 14:55:46Z ktk $ */
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
28PQUEUEELEMENT QUEUEHEAD::Head(void)
29{
30 return(pHead);
31}
32
33PQUEUEELEMENT QUEUEHEAD::Tail(void)
34{
35 return(pTail);
36}
37
38void QUEUEHEAD::PushOnHead(PQUEUEELEMENT pElement)
39{
40 if (pHead == NULL) {
41 pElement->pNext = NULL;
42 pHead = pElement;
43 pTail = pElement;
44 }
45 else {
46 pElement->pNext = pHead;
47 pHead = pElement;
48 } /* endif */
49
50}
51void QUEUEHEAD::PushOnTail(PQUEUEELEMENT pElement)
52{
53 pElement->pNext = NULL;
54 if (pHead == NULL) {
55 pHead = pElement;
56 pTail = pElement;
57 }
58 else {
59 pTail->pNext = pElement;
60 pTail = pElement;
61 } /* endif */
62
63}
64PQUEUEELEMENT QUEUEHEAD::PopHead(void)
65{
66 PQUEUEELEMENT temp = pHead;
67
68 if (temp) {
69 pHead = temp->pNext;
70 if (pHead == NULL)
71 pTail = NULL;
72 temp->pNext = NULL;
73 }
74 return(temp);
75}
76PQUEUEELEMENT QUEUEHEAD::PopTail(void)
77{
78 PQUEUEELEMENT temp = pTail;
79 PQUEUEELEMENT temp2 = pHead;
80
81 // only 1 element on queue or it's empty
82 // zapp the head and tail pointers
83 // zapp the next pointer in the element being returned
84 // get out of here
85 if (pHead == pTail) {
86 pHead = NULL;
87 pTail = NULL;
88 if (temp)
89 temp->pNext = NULL;
90 return(temp);
91 }
92 else {
93 if (temp) {
94 while (temp2->pNext != temp)
95 temp2 = temp2->pNext;
96 pTail = temp2;
97
98 if (pTail == NULL)
99 pHead = NULL;
100 else
101 pTail->pNext = NULL;
102 temp->pNext = NULL;
103 }
104 }
105 return(temp);
106}
107
108USHORT QUEUEHEAD::DestroyElement(PQUEUEELEMENT pElement)
109{
110 if (PopElement(pElement)) {
111 delete(pElement);
112 return(1);
113 }
114 else
115 return(0);
116
117
118}
119PQUEUEELEMENT QUEUEHEAD::PopElement(PQUEUEELEMENT pElement)
120{
121 PQUEUEELEMENT temp;
122
123 // if the queue is empty return NULL
124 if (pHead == NULL)
125 return (NULL);
126
127 // Popping the head element
128 if (pElement == pHead)
129 return(PopHead());
130
131 // Popping the tail element
132 if (pElement == pTail)
133 return(PopTail());
134
135 temp = pHead;
136 // walk the queue till we find the element or we hit the end
137 while ((temp->pNext != pElement) && (temp->pNext != NULL))
138 temp = temp->pNext;
139 if (temp == NULL) // element not found
140 return(NULL);
141 temp->pNext = pElement->pNext;
142 return(pElement);
143
144}
145ULONG QUEUEHEAD::IsElements(void)
146{
147 if (pHead == NULL)
148 return(0);
149 else
150 return(1);
151}
152
153QUEUEHEAD::QUEUEHEAD(void)
154{
155 pHead = NULL;
156 pTail = NULL;
157}
Note: See TracBrowser for help on using the repository browser.