268 |
#endif |
#endif |
269 |
} |
} |
270 |
|
|
271 |
|
#ifndef WIN32 |
272 |
|
namespace { |
273 |
|
// If the thread is cancelled while waiting for the condition |
274 |
|
// variable, the mutex will be locked. It needs to be unlocked so |
275 |
|
// the Condition can be reused if the thread is restarted. |
276 |
|
void condition_cleanup(void* c) { |
277 |
|
static_cast<Condition*>(c)->Unlock(); |
278 |
|
} |
279 |
|
} |
280 |
|
#endif |
281 |
|
|
282 |
int Condition::WaitIf(bool bCondition, long TimeoutSeconds, long TimeoutNanoSeconds) { |
int Condition::WaitIf(bool bCondition, long TimeoutSeconds, long TimeoutNanoSeconds) { |
283 |
dmsg(7,("Condition::WaitIf: bCondition=%d TimeoutSeconds=%d TimeoutNanoSeconds=%d\n",bCondition, TimeoutSeconds, TimeoutNanoSeconds)); |
dmsg(7,("Condition::WaitIf: bCondition=%d TimeoutSeconds=%d TimeoutNanoSeconds=%d\n",bCondition, TimeoutSeconds, TimeoutNanoSeconds)); |
284 |
dmsg(7,("Condition::Waitif() -> LOCK()\n")); |
dmsg(7,("Condition::Waitif() -> LOCK()\n")); |
285 |
Lock(); |
Lock(); |
286 |
dmsg(7,("Condition::Waitif() -> LOCK() passed\n")); |
dmsg(7,("Condition::Waitif() -> LOCK() passed\n")); |
287 |
int res = 0; |
int res = 0; |
288 |
|
#ifndef WIN32 |
289 |
|
pthread_cleanup_push(condition_cleanup, this); |
290 |
|
#endif |
291 |
if (this->bCondition == bCondition) { |
if (this->bCondition == bCondition) { |
292 |
if (bCondition) { // wait until condition turned 'false' |
if (bCondition) { // wait until condition turned 'false' |
293 |
#if defined(WIN32) |
#if defined(WIN32) |
342 |
#endif |
#endif |
343 |
} |
} |
344 |
} |
} |
345 |
|
#ifndef WIN32 |
346 |
|
pthread_cleanup_pop(0); |
347 |
|
#endif |
348 |
return res; |
return res; |
349 |
} |
} |
350 |
|
|