aboutsummaryrefslogtreecommitdiff
path: root/dep/src/zthread/ConditionImpl.h
diff options
context:
space:
mode:
Diffstat (limited to 'dep/src/zthread/ConditionImpl.h')
-rw-r--r--dep/src/zthread/ConditionImpl.h116
1 files changed, 58 insertions, 58 deletions
diff --git a/dep/src/zthread/ConditionImpl.h b/dep/src/zthread/ConditionImpl.h
index eeeaba10bbc..ad1503ef197 100644
--- a/dep/src/zthread/ConditionImpl.h
+++ b/dep/src/zthread/ConditionImpl.h
@@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
-
+
#ifndef __ZTCONDITIONIMPL_H__
#define __ZTCONDITIONIMPL_H__
@@ -39,16 +39,16 @@ namespace ZThread {
*
* The ConditionImpl template allows how waiter lists are sorted
* to be parameteized
- */
-template <typename List>
+ */
+template <typename List>
class ConditionImpl {
-
+
//! Waiters currently blocked
List _waiters;
//! Serialize access to this object
FastLock _lock;
-
+
//! External lock
Lockable& _predicateLock;
@@ -80,7 +80,7 @@ class ConditionImpl {
};
-template <typename List>
+template <typename List>
ConditionImpl<List>::~ConditionImpl() {
#ifndef NDEBUG
@@ -89,7 +89,7 @@ ConditionImpl<List>::~ConditionImpl() {
if(!_waiters.empty()) {
ZTDEBUG("** You are destroying a condition variable which still has waiting threads. **\n");
- assert(0);
+ assert(0);
}
@@ -101,14 +101,14 @@ ConditionImpl<List>::~ConditionImpl() {
/**
* Signal the condition variable, waking one thread if any.
*/
-template <typename List>
+template <typename List>
void ConditionImpl<List>::signal() {
Guard<FastLock> g1(_lock);
// Try to find a waiter with a backoff & retry scheme
for(;;) {
-
+
// Go through the list, attempt to notify() a waiter.
for(typename List::iterator i = _waiters.begin(); i != _waiters.end();) {
@@ -117,28 +117,28 @@ void ConditionImpl<List>::signal() {
Monitor& m = impl->getMonitor();
if(m.tryAcquire()) {
-
+
// Notify the monitor & remove from the waiter list so time isn't
// wasted checking it again.
i = _waiters.erase(i);
-
- // 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 = m.notify();
-
+
m.release();
-
+
// Once notify() succeeds, return
- if(woke)
+ if(woke)
return;
-
+
} else ++i;
-
+
}
-
+
if(_waiters.empty())
return;
-
+
{ // Backoff and try again
Guard<FastLock, UnlockedScope> g2(g1);
@@ -154,14 +154,14 @@ void ConditionImpl<List>::signal() {
* Broadcast to the condition variable, waking all threads waiting at the time of
* the broadcast.
*/
-template <typename List>
+template <typename List>
void ConditionImpl<List>::broadcast() {
Guard<FastLock> g1(_lock);
// Try to find a waiter with a backoff & retry scheme
for(;;) {
-
+
// Go through the list, attempt to notify() a waiter.
for(typename List::iterator i = _waiters.begin(); i != _waiters.end();) {
@@ -170,21 +170,21 @@ void ConditionImpl<List>::broadcast() {
Monitor& m = impl->getMonitor();
if(m.tryAcquire()) {
-
+
// Notify the monitor & remove from the waiter list so time isn't
// wasted checking it again.
i = _waiters.erase(i);
-
+
// Try to wake the waiter, it doesn't matter if this is successful
- // or not (only fails when the monitor is already going to stop waiting).
+ // or not (only fails when the monitor is already going to stop waiting).
m.notify();
-
+
m.release();
-
+
} else ++i;
-
+
}
-
+
if(_waiters.empty())
return;
@@ -199,16 +199,16 @@ void ConditionImpl<List>::broadcast() {
}
-/**
+/**
* Cause the currently executing thread to block until this ConditionImpl has
* been signaled, the threads state changes.
*
- * @param predicate Lockable&
+ * @param predicate Lockable&
*
* @exception Interrupted_Exception thrown when the caller status is interrupted
* @exception Synchronization_Exception thrown if there is some other error.
*/
-template <typename List>
+template <typename List>
void ConditionImpl<List>::wait() {
// Get the monitor for the current thread
@@ -220,13 +220,13 @@ void ConditionImpl<List>::wait() {
{
Guard<FastLock> g1(_lock);
-
- // Release the _predicateLock
+
+ // Release the _predicateLock
_predicateLock.release();
-
+
// Stuff the waiter into the list
_waiters.insert(self);
-
+
// Move to the monitor's lock
m.acquire();
@@ -234,12 +234,12 @@ void ConditionImpl<List>::wait() {
Guard<FastLock, UnlockedScope> g2(g1);
state = m.wait();
-
+
}
// Move back to the Condition's lock
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
@@ -247,7 +247,7 @@ void ConditionImpl<List>::wait() {
typename List::iterator i = std::find(_waiters.begin(), _waiters.end(), self);
if(i != _waiters.end())
_waiters.erase(i);
-
+
}
// Defer interruption until the external lock is acquire()d
@@ -265,16 +265,16 @@ void ConditionImpl<List>::wait() {
}
switch(state) {
-
+
case Monitor::SIGNALED:
break;
-
+
case Monitor::INTERRUPTED:
throw Interrupted_Exception();
-
+
default:
throw Synchronization_Exception();
- }
+ }
}
@@ -283,7 +283,7 @@ void ConditionImpl<List>::wait() {
* Cause the currently executing thread to block until this ConditionImpl has
* been signaled, or the timeout expires or the threads state changes.
*
- * @param _predicateLock Lockable&
+ * @param _predicateLock Lockable&
* @param timeout maximum milliseconds to block.
*
* @return bool
@@ -291,9 +291,9 @@ void ConditionImpl<List>::wait() {
* @exception Interrupted_Exception thrown when the caller status is interrupted
* @exception Synchronization_Exception thrown if there is some other error.
*/
-template <typename List>
+template <typename List>
bool ConditionImpl<List>::wait(unsigned long timeout) {
-
+
// Get the monitor for the current thread
ThreadImpl* self = ThreadImpl::current();
Monitor& m = self->getMonitor();
@@ -303,18 +303,18 @@ bool ConditionImpl<List>::wait(unsigned long timeout) {
{
Guard<FastLock> g1(_lock);
-
- // Release the _predicateLock
+
+ // Release the _predicateLock
_predicateLock.release();
-
+
// Stuff the waiter into the list
_waiters.insert(self);
-
+
state = Monitor::TIMEDOUT;
-
+
// Don't bother waiting if the timeout is 0
if(timeout) {
-
+
m.acquire();
{
@@ -325,9 +325,9 @@ bool ConditionImpl<List>::wait(unsigned long timeout) {
}
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
@@ -335,7 +335,7 @@ bool ConditionImpl<List>::wait(unsigned long timeout) {
typename List::iterator i = std::find(_waiters.begin(), _waiters.end(), self);
if(i != _waiters.end())
_waiters.erase(i);
-
+
}
@@ -354,19 +354,19 @@ bool ConditionImpl<List>::wait(unsigned long timeout) {
}
switch(state) {
-
+
case Monitor::SIGNALED:
break;
-
+
case Monitor::INTERRUPTED:
throw Interrupted_Exception();
-
+
case Monitor::TIMEDOUT:
return false;
default:
throw Synchronization_Exception();
- }
+ }
return true;