diff options
author | Matthew Newhook <matthew@zeroc.com> | 2002-04-22 19:33:40 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2002-04-22 19:33:40 +0000 |
commit | 8c1949ea4e31a0df137711f57f68eea014032e10 (patch) | |
tree | 87a8229d1f23f0829e5f2f00f73a95a43d6dd1e8 /cpp/src/IceUtil/RWRecMutex.cpp | |
parent | update config. Call router->shutdown on termination (diff) | |
download | ice-8c1949ea4e31a0df137711f57f68eea014032e10.tar.bz2 ice-8c1949ea4e31a0df137711f57f68eea014032e10.tar.xz ice-8c1949ea4e31a0df137711f57f68eea014032e10.zip |
Added IceUtil/Time.h
Diffstat (limited to 'cpp/src/IceUtil/RWRecMutex.cpp')
-rw-r--r-- | cpp/src/IceUtil/RWRecMutex.cpp | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/cpp/src/IceUtil/RWRecMutex.cpp b/cpp/src/IceUtil/RWRecMutex.cpp index 44942c2cd9e..9fd75fd8c27 100644 --- a/cpp/src/IceUtil/RWRecMutex.cpp +++ b/cpp/src/IceUtil/RWRecMutex.cpp @@ -10,6 +10,7 @@ #include <IceUtil/RWRecMutex.h> #include <IceUtil/Exception.h> +#include <IceUtil/Time.h> #include <assert.h> @@ -64,11 +65,15 @@ IceUtil::RWRecMutex::timedTryReadlock(int timeout) const // Wait while a writer holds the lock or while writers are waiting // to get the lock. // - // TODO: This needs to check the time after each notify... - // + Time end = Time::now() + Time::milliSeconds(timeout); while (_count < 0 || _waitingWriters != 0) { - if (!_readers.timedWait(lock, timeout)) + long t = (end - Time::now()).milliSeconds(); + if (t > 0) + { + _readers.timedWait(lock, t); + } + else { throw LockedException(__FILE__, __LINE__); } @@ -165,27 +170,25 @@ IceUtil::RWRecMutex::timedTryWritelock(int timeout) const // Wait for the lock to become available and increment the number // of waiting writers. // - // TODO: This needs to check the time after each notify... - // - if (_count != 0) + Time end = Time::now() + Time::milliSeconds(timeout); + while (_count != 0) { - _waitingWriters++; - bool timedOut; - try + long t = (end - Time::now()).milliSeconds(); + if (t > 0) { - timedOut = !_writers.timedWait(lock, timeout); - } - catch(...) - { - --_waitingWriters; - throw; + _waitingWriters++; + try + { + _writers.timedWait(lock, t); + } + catch(...) + { + --_waitingWriters; + throw; + } + _waitingWriters--; } - _waitingWriters--; - - // - // If a timeout occurred then the lock wasn't acquired. - // - if (timedOut) + else { throw LockedException(__FILE__, __LINE__); } @@ -316,29 +319,30 @@ IceUtil::RWRecMutex::timedUpgrade(int timeout) const // // Wait to acquire the write lock. // - // TODO: This needs to check the time after each notify... - // + Time end = Time::now() + Time::milliSeconds(timeout); while (_count != 0) { - _waitingWriters++; - bool timedOut; - try + long t = (end - Time::now()).milliSeconds(); + if (t > 0) { - timedOut = !_writers.timedWait(lock, timeout); - } - catch(...) - { - --_waitingWriters; - throw; + _waitingWriters++; + try + { + _writers.timedWait(lock, timeout); + } + catch(...) + { + --_waitingWriters; + throw; + } + _waitingWriters--; } - _waitingWriters--; - - // - // If a timeout occurred then the lock wasn't acquired. Ensure - // that the _count is increased again before returning. - // - if (timedOut) + else { + // + // If a timeout occurred then the lock wasn't acquired. Ensure + // that the _count is increased again before returning. + // ++_count; throw LockedException(__FILE__, __LINE__); } |