version 1.4, 2006/08/21 08:48:20
|
version 1.5, 2006/08/21 15:31:03
|
|
|
#include <Pegasus/Common/IPCExceptions.h> | #include <Pegasus/Common/IPCExceptions.h> |
#include "Semaphore.h" | #include "Semaphore.h" |
| |
PEGASUS_NAMESPACE_BEGIN |
PEGASUS_NAMESPACE_BEGIN static const Uint32 PEGASUS_SEM_VALUE_MAX = 0x0000ffff; |
|
|
static const Uint32 PEGASUS_SEM_VALUE_MAX = 0x0000ffff; |
|
| |
//============================================================================== | //============================================================================== |
// | // |
|
|
#ifndef PEGASUS_PLATFORM_AIX_RS_IBMCXX | #ifndef PEGASUS_PLATFORM_AIX_RS_IBMCXX |
pthread_mutex_lock(&_rep.mutex); | pthread_mutex_lock(&_rep.mutex); |
int r=0; | int r=0; |
while( r=pthread_cond_destroy(&_rep.cond) == EBUSY || (r==-1 && errno == EBUSY) ) |
while ((r = pthread_cond_destroy(&_rep.cond) == EBUSY) || |
|
(r == -1 && errno == EBUSY)) |
{ | { |
pthread_mutex_unlock(&_rep.mutex); | pthread_mutex_unlock(&_rep.mutex); |
Threads::yield(); | Threads::yield(); |
|
|
#else | #else |
int val; | int val; |
val = pthread_mutex_destroy(&_rep.mutex); | val = pthread_mutex_destroy(&_rep.mutex); |
|
|
if (val != 0) | if (val != 0) |
pthread_cond_destroy(&_rep.cond); | pthread_cond_destroy(&_rep.cond); |
else | else |
|
|
_count--; | _count--; |
| |
// Since we push an unlock onto the cleanup stack | // Since we push an unlock onto the cleanup stack |
// We will pop it off to release the mutex when leaving the critical section. |
// We will pop it off to release the mutex when leaving the critical |
|
// section. |
#if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) | #if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) |
Threads::cleanup_pop(1); | Threads::cleanup_pop(1); |
#endif | #endif |
|
|
| |
while ((_count == 0) && !timedOut) | while ((_count == 0) && !timedOut) |
{ | { |
int r = pthread_cond_timedwait( |
int r = pthread_cond_timedwait(&_rep.cond, &_rep.mutex, &waittime); |
&_rep.cond, &_rep.mutex, &waittime); |
|
| |
if (((r == -1 && errno == ETIMEDOUT) || (r == ETIMEDOUT)) && _count == 0) |
if (((r == -1 && errno == ETIMEDOUT) || (r == ETIMEDOUT)) && |
|
_count == 0) |
{ | { |
timedOut = true; | timedOut = true; |
} | } |
|
|
| |
#if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) | #if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) |
// Since we push an unlock onto the cleanup stack | // Since we push an unlock onto the cleanup stack |
// We will pop it off to release the mutex when leaving the critical section. |
// We will pop it off to release the mutex when leaving the critical |
|
// section. |
Threads::cleanup_pop(1); | Threads::cleanup_pop(1); |
#endif | #endif |
| |
|
|
if (ignoreInterrupt == false) | if (ignoreInterrupt == false) |
throw(WaitInterrupted(_rep.owner)); | throw(WaitInterrupted(_rep.owner)); |
} | } |
else throw(WaitFailed(_rep.owner)); |
else |
|
throw(WaitFailed(_rep.owner)); |
| |
// keep going if above conditions fail | // keep going if above conditions fail |
} while (true); |
} |
|
while (true); |
| |
} | } |
| |
|
|
do | do |
{ | { |
retcode = sem_trywait(&_rep.sem); | retcode = sem_trywait(&_rep.sem); |
} while (retcode == -1 && errno == EINTR); |
} |
|
while (retcode == -1 && errno == EINTR); |
| |
if ( retcode == 0 ) | if ( retcode == 0 ) |
return ; | return ; |