version 1.7, 2006/09/22 18:58:22
|
version 1.13, 2008/08/15 17:24:52
|
|
|
| |
void lock(); | void lock(); |
| |
void try_lock(); |
/** |
|
Attempts to lock the mutex without blocking. |
void timed_lock(Uint32 milliseconds); |
@return A Boolean indicating whether the lock was acquired. |
|
*/ |
|
Boolean try_lock(); |
|
|
|
/** |
|
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) || \ |
|
(defined(PEGASUS_OS_ZOS) && !(__TARGET_LIB__ < 0x41090000)) |
|
/** |
|
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 |
|
unsafe. |
|
*/ |
|
void reinitialize(); |
|
#endif |
|
|
private: | private: |
Mutex(const Mutex&); | Mutex(const Mutex&); |
Mutex& operator=(const Mutex&); | Mutex& operator=(const Mutex&); |
|
|
// | // |
//============================================================================== | //============================================================================== |
| |
// Use of this macro ensures that a static Mutex is not locked during a fork(). |
// Use of this macro ensures that a static Mutex is not locked across a fork(). |
#if defined(PEGASUS_HAVE_PTHREADS) && \ |
|
!defined(PEGASUS_OS_ZOS) && \ |
#if !defined(PEGASUS_HAVE_PTHREADS) || \ |
!defined(PEGASUS_OS_VMS) |
(defined(PEGASUS_OS_ZOS) && (__TARGET_LIB__ < 0x41090000)) || \ |
|
defined(PEGASUS_OS_VMS) |
|
|
|
# define PEGASUS_FORK_SAFE_MUTEX(mutex) |
|
|
|
#elif defined(PEGASUS_OS_LINUX) || \ |
|
(defined(PEGASUS_OS_ZOS) && !(__TARGET_LIB__ < 0x41090000)) |
|
|
|
# define PEGASUS_FORK_SAFE_MUTEX(mutex) \ |
|
class ForkSafeMutex ## mutex \ |
|
{ \ |
|
public: \ |
|
ForkSafeMutex ## mutex() \ |
|
{ \ |
|
pthread_atfork( \ |
|
0, \ |
|
0, \ |
|
_reinitializeMutex); \ |
|
} \ |
|
\ |
|
private: \ |
|
static void _reinitializeMutex() \ |
|
{ \ |
|
mutex.reinitialize(); \ |
|
} \ |
|
}; \ |
|
\ |
|
static ForkSafeMutex ## mutex __forkSafeMutex ## mutex; |
|
|
|
#else |
|
|
# define PEGASUS_FORK_SAFE_MUTEX(mutex) \ | # define PEGASUS_FORK_SAFE_MUTEX(mutex) \ |
class ForkSafeMutex ## mutex \ | class ForkSafeMutex ## mutex \ |
{ \ | { \ |
|
|
}; \ | }; \ |
\ | \ |
static ForkSafeMutex ## mutex __forkSafeMutex ## mutex; | static ForkSafeMutex ## mutex __forkSafeMutex ## mutex; |
#else |
|
# define PEGASUS_FORK_SAFE_MUTEX(mutex) |
|
#endif | #endif |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |