diff options
author | Paradox <none@none> | 2009-02-17 20:10:49 -0600 |
---|---|---|
committer | Paradox <none@none> | 2009-02-17 20:10:49 -0600 |
commit | 3931b802f1b8b890a615e5b2a4c0ed70407468d7 (patch) | |
tree | b1386a80454be7ba341d4fcd4f87c133d9af95a7 /dep/src/zthread/RecursiveMutexImpl.cxx | |
parent | 14234c86fa4f1b31436a0289cdac5f92ab430804 (diff) |
Yet more tabs to spaces
--HG--
branch : trunk
Diffstat (limited to 'dep/src/zthread/RecursiveMutexImpl.cxx')
-rw-r--r-- | dep/src/zthread/RecursiveMutexImpl.cxx | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/dep/src/zthread/RecursiveMutexImpl.cxx b/dep/src/zthread/RecursiveMutexImpl.cxx index 41ca03547f8..adee8004278 100644 --- a/dep/src/zthread/RecursiveMutexImpl.cxx +++ b/dep/src/zthread/RecursiveMutexImpl.cxx @@ -39,9 +39,9 @@ namespace ZThread { * @exception Initialization_Exception thrown if resources could not be * properly allocated */ - RecursiveMutexImpl::RecursiveMutexImpl() + RecursiveMutexImpl::RecursiveMutexImpl() : _owner(0), _count(0) { - + } /** @@ -52,14 +52,14 @@ namespace ZThread { #ifndef NDEBUG // It is an error to destroy a mutex that has not been released - if(_owner != 0) { + if(_owner != 0) { ZTDEBUG("** You are destroying a mutex which was never released. **\n"); assert(0); // Destroyed mutex while in use } - if(!_waiters.empty()) { + if(!_waiters.empty()) { ZTDEBUG("** You are destroying a mutex which is blocking %d threads. **\n", _waiters.size()); assert(0); // Destroyed mutex while in use @@ -78,10 +78,10 @@ namespace ZThread { Monitor::STATE state; Guard<FastLock> g1(_lock); - - // If there is an entry count and the current thread is + + // If there is an entry count and the current thread is // the owner, increment the count and continue. - if(_owner == &m) + if(_owner == &m) _count++; else { @@ -91,11 +91,11 @@ namespace ZThread { assert(_count == 0); - _owner = &m; + _owner = &m; _count++; } else { // Otherwise, wait() - + _waiters.push_back(&m); m.acquire(); @@ -108,7 +108,7 @@ namespace ZThread { } m.release(); - + // Remove from waiter list, regarless of weather release() is called or // not. The monitor is sticky, so its possible a state 'stuck' from a // previous operation and will leave the wait() w/o release() having @@ -117,39 +117,39 @@ namespace ZThread { if(i != _waiters.end()) _waiters.erase(i); - // If awoke due to a notify(), take ownership. + // If awoke due to a notify(), take ownership. switch(state) { case Monitor::SIGNALED: - + assert(_owner == 0); assert(_count == 0); _owner = &m; _count++; - + break; case Monitor::INTERRUPTED: throw Interrupted_Exception(); - + default: throw Synchronization_Exception(); - } - + } + } - + } } bool RecursiveMutexImpl::tryAcquire(unsigned long timeout) { - + // Get the monitor for the current thread Monitor& m = ThreadImpl::current()->getMonitor(); Guard<FastLock> g1(_lock); - - // If there is an entry count and the current thread is + + // If there is an entry count and the current thread is // the owner, increment the count and continue. if(_owner == &m) _count++; @@ -176,14 +176,14 @@ namespace ZThread { m.acquire(); { - + Guard<FastLock, UnlockedScope> g2(g1); state = m.wait(timeout); - + } m.release(); - + } // Remove from waiter list, regarless of weather release() is called or @@ -194,7 +194,7 @@ namespace ZThread { if(i != _waiters.end()) _waiters.erase(i); - // If awoke due to a notify(), take ownership. + // If awoke due to a notify(), take ownership. switch(state) { case Monitor::SIGNALED: @@ -203,21 +203,21 @@ namespace ZThread { _owner = &m; _count++; - + break; case Monitor::INTERRUPTED: throw Interrupted_Exception(); - + case Monitor::TIMEDOUT: return false; default: throw Synchronization_Exception(); - } - + } + } - + } return true; @@ -237,7 +237,7 @@ namespace ZThread { // Update the count, if it has reached 0, wake another waiter. if(--_count == 0) { - + _owner = 0; // Try to find a waiter with a backoff & retry scheme @@ -245,24 +245,24 @@ namespace ZThread { // Go through the list, attempt to notify() a waiter. for(List::iterator i = _waiters.begin(); i != _waiters.end();) { - + // Try the monitor lock, if it cant be locked skip to the next waiter Monitor* n = *i; if(n->tryAcquire()) { - - // If notify() is not sucessful, it is because the wait() has already + + // If notify() is not sucessful, it is because the wait() has already // been ended (killed/interrupted/notify'd) bool woke = n->notify(); n->release(); - + // Once notify() succeeds, return if(woke) return; - + } else ++i; - + } - + if(_waiters.empty()) return; @@ -276,7 +276,7 @@ namespace ZThread { } } - + } } // namespace ZThread |