version 1.10.2.2, 2007/09/11 18:18:09
|
version 1.12.2.1, 2008/08/20 23:05:50
|
|
|
// | // |
//============================================================================== | //============================================================================== |
| |
#if defined(PEGASUS_HAVE_PTHREADS) && defined(PEGASUS_HAVE_RECURSIVE_MUTEXES) |
#if defined(PEGASUS_HAVE_PTHREADS) |
typedef pthread_mutex_t MutexType; | typedef pthread_mutex_t MutexType; |
inline void mutex_lock(MutexType* mutex) { pthread_mutex_lock(mutex); } | inline void mutex_lock(MutexType* mutex) { pthread_mutex_lock(mutex); } |
inline void mutex_unlock(MutexType* mutex) { pthread_mutex_unlock(mutex); } | inline void mutex_unlock(MutexType* mutex) { pthread_mutex_unlock(mutex); } |
|
|
# define PEGASUS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER | # define PEGASUS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER |
#endif | #endif |
| |
#if defined(PEGASUS_HAVE_PTHREADS) && !defined(PEGASUS_HAVE_RECURSIVE_MUTEXES) |
|
typedef pthread_mutex_t MutexType; |
|
inline void mutex_lock(MutexType* mutex) { pthread_mutex_lock(mutex); } |
|
inline void mutex_unlock(MutexType* mutex) { pthread_mutex_unlock(mutex); } |
|
struct MutexRep |
|
{ |
|
int recursive; |
|
pthread_mutex_t mutex; |
|
pthread_cond_t cond; |
|
pthread_t owner; |
|
int count; |
|
}; |
|
# define PEGASUS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER |
|
#endif |
|
|
|
#if defined(PEGASUS_HAVE_WINDOWS_THREADS) | #if defined(PEGASUS_HAVE_WINDOWS_THREADS) |
typedef HANDLE MutexType; | typedef HANDLE MutexType; |
inline void mutex_lock(MutexType* m) { WaitForSingleObject(*m, INFINITE); } | inline void mutex_lock(MutexType* m) { WaitForSingleObject(*m, INFINITE); } |
|
|
| |
void lock(); | void lock(); |
| |
void try_lock(); |
/** |
|
Attempts to lock the mutex without blocking. |
|
@return A Boolean indicating whether the lock was acquired. |
|
*/ |
|
Boolean try_lock(); |
| |
void timed_lock(Uint32 milliseconds); |
/** |
|
Attempts to lock the mutex within the specified time. |
|
@param milliseconds The maximum time to block while attempting to |
|
acquire the lock. |
|
@return A Boolean indicating whether the lock was acquired. |
|
*/ |
|
Boolean timed_lock(Uint32 milliseconds); |
| |
void unlock(); | void unlock(); |
| |
#if defined(PEGASUS_OS_LINUX) |
#if defined(PEGASUS_OS_LINUX) || \ |
|
(defined(PEGASUS_OS_ZOS) && !(__TARGET_LIB__ < 0x41090000)) |
/** | /** |
This method must only be called after a fork() to reset the mutex | This method must only be called after a fork() to reset the mutex |
lock status in the new process. Any other use of this method is | lock status in the new process. Any other use of this method is |
|
|
| |
#if !defined(PEGASUS_HAVE_PTHREADS) || \ | #if !defined(PEGASUS_HAVE_PTHREADS) || \ |
(defined(PEGASUS_OS_ZOS) && (__TARGET_LIB__ < 0x41090000)) || \ | (defined(PEGASUS_OS_ZOS) && (__TARGET_LIB__ < 0x41090000)) || \ |
defined(PEGASUS_OS_VMS) || \ |
defined(PEGASUS_OS_VMS) |
defined(PEGASUS_OS_VXWORKS) |
|
| |
# define PEGASUS_FORK_SAFE_MUTEX(mutex) | # define PEGASUS_FORK_SAFE_MUTEX(mutex) |
| |
#elif defined(PEGASUS_OS_LINUX) |
#elif defined(PEGASUS_OS_LINUX) || \ |
|
(defined(PEGASUS_OS_ZOS) && !(__TARGET_LIB__ < 0x41090000)) |
| |
# define PEGASUS_FORK_SAFE_MUTEX(mutex) \ | # define PEGASUS_FORK_SAFE_MUTEX(mutex) \ |
class ForkSafeMutex ## mutex \ | class ForkSafeMutex ## mutex \ |