version 1.1.2.6, 2006/07/28 21:19:53
|
version 1.1.2.10, 2006/07/28 23:56:54
|
|
|
#include "ReadWriteSem.h" | #include "ReadWriteSem.h" |
#include "Time.h" | #include "Time.h" |
#include "PegasusAssert.h" | #include "PegasusAssert.h" |
|
#include "Threads.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
|
|
//============================================================================== | //============================================================================== |
// | // |
// PEGASUS_USE_POSIX_RWLOCK | // PEGASUS_USE_POSIX_RWLOCK |
// | // |
//============================================================================== | //============================================================================== |
|
|
#ifdef PEGASUS_USE_POSIX_RWLOCK | #ifdef PEGASUS_USE_POSIX_RWLOCK |
|
|
ReadWriteSem::ReadWriteSem():_readers(0), _writers(0) | ReadWriteSem::ReadWriteSem():_readers(0), _writers(0) |
{ | { |
pthread_rwlock_init(&_rwlock.rwlock, NULL); | pthread_rwlock_init(&_rwlock.rwlock, NULL); |
|
|
void ReadWriteSem::timed_wait(Uint32 mode, | void ReadWriteSem::timed_wait(Uint32 mode, |
ThreadType caller, int milliseconds) | ThreadType caller, int milliseconds) |
{ | { |
int errorcode = 0, timeout; |
int errorcode = 0, timeout = 0; |
struct timeval now, finish, remaining; | struct timeval now, finish, remaining; |
Uint32 usec; | Uint32 usec; |
| |
|
|
| |
int ReadWriteSem::read_count() const | int ReadWriteSem::read_count() const |
{ | { |
#if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
|
PEGASUS_ASSERT(_readers.get() == _rwlock.rwlock.__rw_readers); |
|
#endif |
|
return (_readers.get()); | return (_readers.get()); |
} | } |
| |
int ReadWriteSem::write_count() const | int ReadWriteSem::write_count() const |
{ | { |
#if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
|
if (_rwlock.rwlock.__rw_writer != NULL) |
|
{ |
|
PEGASUS_ASSERT(_writers.get() == 1); |
|
} |
|
#endif |
|
return (_writers.get()); | return (_writers.get()); |
} | } |
| |
|
|
void ReadWriteSem::timed_wait(Uint32 mode, ThreadType caller, | void ReadWriteSem::timed_wait(Uint32 mode, ThreadType caller, |
int milliseconds) | int milliseconds) |
{ | { |
|
|
//----------------------------------------------------------------- | //----------------------------------------------------------------- |
// Lock this object to maintain integrity while we decide | // Lock this object to maintain integrity while we decide |
// exactly what to do next. | // exactly what to do next. |
|
|
| |
// cleanup stack frame | // cleanup stack frame |
{ | { |
|
|
Threads::cleanup_push(extricate_read_write, this); | Threads::cleanup_push(extricate_read_write, this); |
| |
try | try |