version 1.5.2.1, 2007/10/05 01:40:13
|
version 1.6.2.1, 2008/06/03 13:59:18
|
|
|
# define PEGASUS_USE_POSIX_RWLOCK | # define PEGASUS_USE_POSIX_RWLOCK |
#elif defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) | #elif defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) |
# define PEGASUS_USE_POSIX_RWLOCK | # define PEGASUS_USE_POSIX_RWLOCK |
|
#elif defined(PEGASUS_PLATFORM_SOLARIS_IX86_CC) |
|
# define PEGASUS_USE_POSIX_RWLOCK |
|
#elif defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) |
|
# define PEGASUS_USE_POSIX_RWLOCK |
#elif defined(PEGASUS_PLATFORM_TRU64_ALPHA_DECCXX) | #elif defined(PEGASUS_PLATFORM_TRU64_ALPHA_DECCXX) |
# define PEGASUS_USE_POSIX_RWLOCK | # define PEGASUS_USE_POSIX_RWLOCK |
#elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) | #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) |
|
|
wait(PEG_SEM_WRITE, caller); | wait(PEG_SEM_WRITE, caller); |
} | } |
| |
// @exception Deadlock |
|
// @exception Permission |
|
// @exception AlreadyLocked |
|
// @exception WaitFailed |
|
inline void try_wait_read(ThreadType caller) |
|
{ |
|
try_wait(PEG_SEM_READ, caller); |
|
} |
|
|
|
// @exception Deadlock |
|
// @exception Permission |
|
// @exception AlreadyLocked |
|
// @exception WaitFailed |
|
inline void try_wait_write(ThreadType caller) |
|
{ |
|
try_wait(PEG_SEM_WRITE, caller); |
|
} |
|
|
|
// @exception Deadlock |
|
// @exception Permission |
|
// @exception TimeOut |
|
// @exception WaitFailed |
|
inline void timed_wait_read(ThreadType caller, int milliseconds) |
|
{ |
|
timed_wait(PEG_SEM_READ, caller, milliseconds); |
|
} |
|
|
|
// @exception Deadlock |
|
// @exception Permission |
|
// @exception TimeOut |
|
// @exception WaitFailed |
|
inline void timed_wait_write(ThreadType caller, int milliseconds) |
|
{ |
|
timed_wait(PEG_SEM_WRITE, caller, milliseconds); |
|
} |
|
|
|
// @exception Permission | // @exception Permission |
inline void unlock_read(ThreadType caller) | inline void unlock_read(ThreadType caller) |
{ | { |
|
|
// @exception TooManyReaders | // @exception TooManyReaders |
void wait(Uint32 mode, ThreadType caller); | void wait(Uint32 mode, ThreadType caller); |
| |
// @exception Deadlock |
|
// @exception Permission |
|
// @exception WaitFailed |
|
// @exception TooManyReaders |
|
void try_wait(Uint32 mode, ThreadType caller); |
|
|
|
// @exception Timeout |
|
// @exception Deadlock |
|
// @exception Permission |
|
// @exception WaitFailed |
|
// @exception TooManyReaders |
|
void timed_wait(Uint32 mode, ThreadType caller, int milliseconds); |
|
|
|
// @exception Permission | // @exception Permission |
void unlock(Uint32 mode, ThreadType caller); | void unlock(Uint32 mode, ThreadType caller); |
| |
|
|
ReadWriteSem & _rwsem; | ReadWriteSem & _rwsem; |
}; | }; |
| |
//============================================================================== |
|
// |
|
// ConditionalReadLock |
|
// |
|
// Like ReadLock but only locks/unlocks if cond parameter is true. |
|
// |
|
//============================================================================== |
|
|
|
class ConditionalReadLock |
|
{ |
|
public: |
|
|
|
ConditionalReadLock(ReadWriteSem& sem, bool cond) : _sem(sem), _cond(cond) |
|
{ |
|
if (_cond) |
|
_sem.wait_read(Threads::self()); |
|
} |
|
|
|
~ConditionalReadLock() |
|
{ |
|
if (_cond) |
|
_sem.unlock_read(Threads::self()); |
|
} |
|
|
|
private: |
|
ReadWriteSem& _sem; |
|
bool _cond; |
|
}; |
|
|
|
//============================================================================== |
|
// |
|
// ConditionalWriteLock |
|
// |
|
// Like WriteLock but only locks/unlocks if cond parameter is true. |
|
// |
|
//============================================================================== |
|
|
|
class ConditionalWriteLock |
|
{ |
|
public: |
|
|
|
ConditionalWriteLock(ReadWriteSem& sem, bool cond) : _sem(sem), _cond(cond) |
|
{ |
|
if (_cond) |
|
_sem.wait_write(Threads::self()); |
|
} |
|
|
|
~ConditionalWriteLock() |
|
{ |
|
if (_cond) |
|
_sem.unlock_write(Threads::self()); |
|
} |
|
|
|
private: |
|
ReadWriteSem& _sem; |
|
bool _cond; |
|
}; |
|
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |
| |
#endif /* Pegasus_ReadWriteSem_h */ | #endif /* Pegasus_ReadWriteSem_h */ |