diff options
| author | Alan Conway <aconway@apache.org> | 2007-10-29 21:14:44 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2007-10-29 21:14:44 +0000 |
| commit | da6e2b9f62966ef7d0cb69f58ffe1365af98d676 (patch) | |
| tree | a46b84d820f2c26f6094f092e18a0937deb46ecf /cpp/src/qpid/sys/Waitable.h | |
| parent | 505c43651b302ecf773bff1fcf3d45f5a1aef682 (diff) | |
| download | qpid-python-da6e2b9f62966ef7d0cb69f58ffe1365af98d676.tar.gz | |
client/BlockingQueue.h, sys/ConcurrentQueue.h: merged to sys/BlockingQueue.h
- updated all users
qpid/Exception.h: Removed unimplemented clone() function.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@589857 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/Waitable.h')
| -rw-r--r-- | cpp/src/qpid/sys/Waitable.h | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/cpp/src/qpid/sys/Waitable.h b/cpp/src/qpid/sys/Waitable.h index eb71a1d742..37392ed761 100644 --- a/cpp/src/qpid/sys/Waitable.h +++ b/cpp/src/qpid/sys/Waitable.h @@ -29,9 +29,9 @@ namespace qpid { namespace sys { /** - * A monitor that keeps track of waiting threads. - * Threads that use a WaitLock are counted as waiters, threads that - * use a normal ScopedLock are not considered waiters. + * A monitor that keeps track of waiting threads. Threads declare a + * ScopedWait around wait() inside a ScopedLock to be considered + * waiters. */ class Waitable : public Monitor { public: @@ -43,24 +43,22 @@ class Waitable : public Monitor { struct ScopedWait { Waitable& w; ScopedWait(Waitable& w_) : w(w_) { ++w.waiters; } - ~ScopedWait() { --w.waiters; w.notifyAll(); } + ~ScopedWait() { if (--w.waiters==0) w.notifyAll(); } }; - /** Block till all waiters have finished waiting. - * The calling thread does not count as a waiter. + /** Block till there are no more ScopedWaits. *@pre Must be called inside a ScopedLock but NOT a ScopedWait. */ - bool waitAll(Duration timeout=TIME_INFINITE) { - AbsTime deadline(now(), timeout); - while (waiters > 0) { - if (!wait(deadline)) { - assert(timeout != TIME_INFINITE); - return false; - } - } - return true; + void waitWaiters() { + while (waiters != 0) + wait(); } + /** Returns the number of outstanding ScopedWaits. + * Must be called with the lock held. + */ + size_t hasWaiters() { return waiters; } + private: friend struct ScopedWait; size_t waiters; |
