version 1.1, 2005/11/03 00:24:42
|
version 1.3, 2005/11/03 02:36:59
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include "SpinLock.h" | #include "SpinLock.h" |
|
|
|
#if !defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC) |
|
# define PEGASUS_SPINLOCK_USE_PTHREADS |
|
#endif |
|
|
|
#ifdef PEGASUS_SPINLOCK_USE_PTHREADS |
|
# include <pthread.h> |
|
#else |
#include "IPC.h" | #include "IPC.h" |
|
#endif |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
SpinLock sharedSpinLocks[PEGASUS_NUM_SHARED_SPIN_LOCKS]; | SpinLock sharedSpinLocks[PEGASUS_NUM_SHARED_SPIN_LOCKS]; |
| |
|
#ifdef PEGASUS_SPINLOCK_USE_PTHREADS |
|
pthread_mutex_t _spinLockInitMutex = PTHREAD_MUTEX_INITIALIZER; |
|
#else |
static Mutex _spinLockInitMutex; | static Mutex _spinLockInitMutex; |
|
#endif |
| |
void SpinLockConditionalCreate(SpinLock& lock) | void SpinLockConditionalCreate(SpinLock& lock) |
{ | { |
|
|
| |
if (lock.initialized == 0) | if (lock.initialized == 0) |
{ | { |
|
#ifdef PEGASUS_SPINLOCK_USE_PTHREADS |
|
pthread_mutex_lock(&_spinLockInitMutex); |
|
#else |
_spinLockInitMutex.lock(pegasus_thread_self()); | _spinLockInitMutex.lock(pegasus_thread_self()); |
|
#endif |
| |
if (lock.initialized == 0) | if (lock.initialized == 0) |
SpinLockCreate(lock); | SpinLockCreate(lock); |
| |
|
#ifdef PEGASUS_SPINLOCK_USE_PTHREADS |
|
pthread_mutex_unlock(&_spinLockInitMutex); |
|
#else |
_spinLockInitMutex.unlock(); | _spinLockInitMutex.unlock(); |
|
#endif |
} | } |
} | } |
| |