The Pedigree Project
0.1
|
#include <ConditionVariable.h>
Public Types | |
enum | Error { NoError, TimedOut, ThreadTerminating, MutexNotLocked, MutexNotAcquired } |
typedef Result< bool, Error > | WaitResult |
Public Member Functions | |
WaitResult | wait (Mutex &mutex, Time::Timestamp &timeout) |
WaitResult | wait (Mutex &mutex) |
void | signal () |
void | broadcast () |
Private Attributes | |
Spinlock | m_Lock |
Lock around m_Waiters. | |
List< Thread * > | m_Waiters |
Threads waiting for a signal. | |
ConditionVariable provides an abstraction over condition variables.
Definition at line 36 of file ConditionVariable.h.
void ConditionVariable::broadcast | ( | ) |
Wake up all threads currently waiting.
Definition at line 174 of file ConditionVariable.cc.
Referenced by RequestQueue::halt().
void ConditionVariable::signal | ( | ) |
Wake up at least one thread that is currently waiting.
Definition at line 158 of file ConditionVariable.cc.
References Spinlock::acquire(), Thread::getLock(), Spinlock::release(), and Thread::setStatus().
Referenced by RequestQueue::addRequest().
ConditionVariable::WaitResult ConditionVariable::wait | ( | Mutex & | mutex, |
Time::Timestamp & | timeout | ||
) |
Wait for a signal on the condition variable with a specific timeout.
If the given timeout is non-zero, it specifies a timeout for the wait operation. If the operation times out, the value will be set to zero. If the operation succeeds before the timeout expires, the value will be the amount of time remaining in the timeout.
[in] | mutex | an acquired mutex protecting the resource. |
[in,out] | timeout | a timeout in nanoseconds to wait (or zero for none). |
Definition at line 49 of file ConditionVariable.cc.
References Semaphore::acquire(), Thread::Continue, Thread::getUnwindState(), Semaphore::getValue(), Processor::information(), Semaphore::release(), Thread::setDebugState(), Thread::setInterrupted(), WARNING, and Thread::wasInterrupted().
Referenced by ProducerConsumer::consumerThread(), PerProcessorScheduler::processorAddThread(), and RequestQueue::work().
ConditionVariable::WaitResult ConditionVariable::wait | ( | Mutex & | mutex | ) |
Wait for a signal on the condition variable with no timeout.
Definition at line 42 of file ConditionVariable.cc.