diff options
Diffstat (limited to '')
-rw-r--r-- | src/stable/synchroqueue.h | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/stable/synchroqueue.h b/src/stable/synchroqueue.h index a0335f6..7ba299f 100644 --- a/src/stable/synchroqueue.h +++ b/src/stable/synchroqueue.h | |||
@@ -56,6 +56,7 @@ namespace Bu | |||
56 | */ | 56 | */ |
57 | ~SynchroQueue() | 57 | ~SynchroQueue() |
58 | { | 58 | { |
59 | cBlock.lock(); | ||
59 | Item *pCur = pStart; | 60 | Item *pCur = pStart; |
60 | while( pCur ) | 61 | while( pCur ) |
61 | { | 62 | { |
@@ -63,6 +64,7 @@ namespace Bu | |||
63 | delete pCur; | 64 | delete pCur; |
64 | pCur = pTmp; | 65 | pCur = pTmp; |
65 | } | 66 | } |
67 | cBlock.unlock(); | ||
66 | } | 68 | } |
67 | 69 | ||
68 | /** | 70 | /** |
@@ -74,7 +76,7 @@ namespace Bu | |||
74 | */ | 76 | */ |
75 | void enqueue( T pData ) | 77 | void enqueue( T pData ) |
76 | { | 78 | { |
77 | mOperate.lock(); | 79 | cBlock.lock(); |
78 | 80 | ||
79 | if( pStart == NULL ) | 81 | if( pStart == NULL ) |
80 | { | 82 | { |
@@ -93,8 +95,8 @@ namespace Bu | |||
93 | } | 95 | } |
94 | 96 | ||
95 | cBlock.signal(); | 97 | cBlock.signal(); |
96 | 98 | ||
97 | mOperate.unlock(); | 99 | cBlock.unlock(); |
98 | } | 100 | } |
99 | 101 | ||
100 | /** | 102 | /** |
@@ -117,17 +119,20 @@ namespace Bu | |||
117 | */ | 119 | */ |
118 | T dequeue( bool bBlock=false ) | 120 | T dequeue( bool bBlock=false ) |
119 | { | 121 | { |
120 | mOperate.lock(); | 122 | cBlock.lock(); |
121 | if( pStart == NULL ) | 123 | if( pStart == NULL ) |
122 | { | 124 | { |
123 | mOperate.unlock(); | ||
124 | |||
125 | if( bBlock ) | 125 | if( bBlock ) |
126 | { | 126 | { |
127 | cBlock.lock(); | 127 | for(;;) |
128 | 128 | { | |
129 | while( pStart == NULL ) | 129 | if( pStart != NULL ) |
130 | { | ||
131 | cBlock.unlock(); | ||
132 | break; | ||
133 | } | ||
130 | cBlock.wait(); | 134 | cBlock.wait(); |
135 | } | ||
131 | 136 | ||
132 | T tmp = dequeue( false ); | 137 | T tmp = dequeue( false ); |
133 | 138 | ||
@@ -146,7 +151,7 @@ namespace Bu | |||
146 | delete pDel; | 151 | delete pDel; |
147 | nSize--; | 152 | nSize--; |
148 | 153 | ||
149 | mOperate.unlock(); | 154 | cBlock.unlock(); |
150 | return pTmp; | 155 | return pTmp; |
151 | } | 156 | } |
152 | } | 157 | } |
@@ -164,13 +169,9 @@ namespace Bu | |||
164 | */ | 169 | */ |
165 | T dequeue( int nSec, int nUSec ) | 170 | T dequeue( int nSec, int nUSec ) |
166 | { | 171 | { |
167 | mOperate.lock(); | 172 | cBlock.lock(); |
168 | if( pStart == NULL ) | 173 | if( pStart == NULL ) |
169 | { | 174 | { |
170 | mOperate.unlock(); | ||
171 | |||
172 | cBlock.lock(); | ||
173 | |||
174 | cBlock.wait( nSec, nUSec ); | 175 | cBlock.wait( nSec, nUSec ); |
175 | 176 | ||
176 | if( pStart == NULL ) | 177 | if( pStart == NULL ) |
@@ -179,13 +180,11 @@ namespace Bu | |||
179 | return NULL; | 180 | return NULL; |
180 | } | 181 | } |
181 | 182 | ||
182 | mOperate.lock(); | ||
183 | T pTmp = pStart->pData; | 183 | T pTmp = pStart->pData; |
184 | Item *pDel = pStart; | 184 | Item *pDel = pStart; |
185 | pStart = pStart->pNext; | 185 | pStart = pStart->pNext; |
186 | delete pDel; | 186 | delete pDel; |
187 | nSize--; | 187 | nSize--; |
188 | mOperate.unlock(); | ||
189 | 188 | ||
190 | cBlock.unlock(); | 189 | cBlock.unlock(); |
191 | return pTmp; | 190 | return pTmp; |
@@ -198,7 +197,7 @@ namespace Bu | |||
198 | delete pDel; | 197 | delete pDel; |
199 | nSize--; | 198 | nSize--; |
200 | 199 | ||
201 | mOperate.unlock(); | 200 | cBlock.unlock(); |
202 | return pTmp; | 201 | return pTmp; |
203 | } | 202 | } |
204 | } | 203 | } |
@@ -211,18 +210,18 @@ namespace Bu | |||
211 | */ | 210 | */ |
212 | bool isEmpty() | 211 | bool isEmpty() |
213 | { | 212 | { |
214 | mOperate.lock(); | 213 | cBlock.lock(); |
215 | bool bEmpty = (pStart == NULL ); | 214 | bool bEmpty = (pStart == NULL ); |
216 | mOperate.unlock(); | 215 | cBlock.unlock(); |
217 | 216 | ||
218 | return bEmpty; | 217 | return bEmpty; |
219 | } | 218 | } |
220 | 219 | ||
221 | long getSize() | 220 | long getSize() |
222 | { | 221 | { |
223 | mOperate.lock(); | 222 | cBlock.lock(); |
224 | long nRet = nSize; | 223 | long nRet = nSize; |
225 | mOperate.unlock(); | 224 | cBlock.unlock(); |
226 | 225 | ||
227 | return nRet; | 226 | return nRet; |
228 | } | 227 | } |
@@ -232,7 +231,6 @@ namespace Bu | |||
232 | Item *pEnd; /**< The end of the queue, the last element to dequeue. */ | 231 | Item *pEnd; /**< The end of the queue, the last element to dequeue. */ |
233 | long nSize; /**< The number of items in the queue. */ | 232 | long nSize; /**< The number of items in the queue. */ |
234 | 233 | ||
235 | Mutex mOperate; /**< The master mutex, used on all operations. */ | ||
236 | Condition cBlock; /**< The condition for blocking dequeues. */ | 234 | Condition cBlock; /**< The condition for blocking dequeues. */ |
237 | }; | 235 | }; |
238 | } | 236 | } |