Honeycomb  0.1
Component-Model Framework
Public Types | Public Member Functions | List of all members
honey::ConditionLock Class Reference

Lock that is bound to a single condition. This is the common usage case of condition variables. More...

#include <Lock.h>

Inheritance diagram for honey::ConditionLock:
Inheritance graph
[legend]
Collaboration diagram for honey::ConditionLock:
Collaboration graph
[legend]

Public Types

typedef UniqueLock< ConditionLockScoped
 
- Public Types inherited from honey::Mutex
typedef Super::Handle Handle
 
typedef UniqueLock< MutexScoped
 

Public Member Functions

void wait (UniqueLock< Mutex > &lock)
 
template<class Rep , class Period >
bool wait (UniqueLock< Mutex > &lock, Duration< Rep, Period > time)
 
template<class Clock , class Dur >
bool wait (UniqueLock< Mutex > &lock, TimePoint< Clock, Dur > time)
 
void wait ()
 No lock arg required. More...
 
template<class Rep , class Period >
bool wait (Duration< Rep, Period > time)
 
template<class Clock , class Dur >
bool wait (TimePoint< Clock, Dur > time)
 
- Public Member Functions inherited from honey::Condition
void signal ()
 Signal one waiting thread to resume, resumed thread attempts to acquire the lock. More...
 
void broadcast ()
 Signal all waiting threads to resume, all resumed threads attempt to acquire the lock. More...
 
void wait (UniqueLock< Mutex > &lock)
 Release lock and wait until thread is signaled. More...
 
template<class Rep , class Period >
bool wait (UniqueLock< Mutex > &lock, Duration< Rep, Period > time)
 Release lock and wait until thread is signaled or until an amount of time has passed. Returns true if signaled, false if timed out. More...
 
template<class Clock , class Dur >
bool wait (UniqueLock< Mutex > &lock, TimePoint< Clock, Dur > time)
 Release lock and wait until thread is signaled or until a certain time. Returns true if signaled, false if timed out. More...
 
- Public Member Functions inherited from honey::Mutex
 Mutex ()=default
 
 Mutex (const Mutex &)
 Can't copy, silently inits to default. More...
 
Mutexoperator= (const Mutex &)
 Can't copy, silently does nothing. More...
 
void lock ()
 Acquire the lock. Thread suspends until lock becomes available. More...
 
void unlock ()
 Release the lock. More...
 
bool tryLock ()
 Attempt to acquire the lock, returns immediately. Returns true if the lock was acquired, false otherwise. More...
 
Handlehandle ()
 Get platform handle. More...
 

Detailed Description

Lock that is bound to a single condition. This is the common usage case of condition variables.

Example:

--Consumer Thread--
cond.lock(); //Lock to protect data access
while (data < 10) { cond.wait(); } //Read data, temporarily release lock while waiting for producer to signal that new data is available
cond.unlock(); //Condition no longer needed
--Producer Thread--
cond.lock(); //Lock to protect data access
data++; //Write data
cond.signal(); //Signal waiting consumer
cond.unlock(); //Allow consumer thread to resume

The condition must be locked before calling any methods on it.

Due to "spurious wakeups" (wakeups without a signal), conditions should always wait() in a while loop, and the predicate (ex. data < 10) should always be checked.

Member Typedef Documentation

Member Function Documentation

void honey::ConditionLock::wait ( UniqueLock< Mutex > &  lock)
template<class Rep , class Period >
bool honey::ConditionLock::wait ( UniqueLock< Mutex > &  lock,
Duration< Rep, Period >  time 
)
template<class Clock , class Dur >
bool honey::ConditionLock::wait ( UniqueLock< Mutex > &  lock,
TimePoint< Clock, Dur >  time 
)
void honey::ConditionLock::wait ( )
inline

No lock arg required.

template<class Rep , class Period >
bool honey::ConditionLock::wait ( Duration< Rep, Period >  time)
inline
template<class Clock , class Dur >
bool honey::ConditionLock::wait ( TimePoint< Clock, Dur >  time)
inline

The documentation for this class was generated from the following file: