XDispatch 0.7.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions
xdispatch::semaphore Class Reference

Wraps dispatch semaphores as provided by libDispatch. More...

#include <xdispatch/semaphore.h>

+ Inheritance diagram for xdispatch::semaphore:

List of all members.

Public Member Functions

 semaphore (int=1)
 Constructs a new semaphore with the given initial value.
 semaphore (dispatch_semaphore_t)
 Constructs a new semaphore using the given dispatch_semaphore_t object.
 semaphore (const semaphore &)
 ~semaphore ()
int release ()
 Release the semaphore.
void acquire ()
 Acquires the semaphore.
bool try_acquire (dispatch_time_t)
 Tries to acquire the semaphore.
bool try_acquire (struct tm *)
 Tries to acquire the semaphore.
const dispatch_semaphore_t native_semaphore () const
semaphoreoperator= (const semaphore &)
bool operator== (const semaphore &)
bool operator== (const dispatch_semaphore_t &)
bool operator!= (const semaphore &)
bool operator!= (const dispatch_semaphore_t &)

Detailed Description

Wraps dispatch semaphores as provided by libDispatch.

"A dispatch semaphore is an efficient implementation of a traditional counting semaphore. Dispatch semaphores call down to the kernel only when the calling thread needs to be blocked. If the calling semaphore does not need to block, no kernel call is made."

Definition at line 47 of file semaphore.h.


Constructor & Destructor Documentation

Constructs a new semaphore with the given initial value.

Passing zero for the value is useful for when two threads need to reconcile the completion of a particular event. Passing a value greather than zero is useful for managing a finite pool of resources, where the pool size is equal to the value.

Remarks:
Never pass a value less than zero here

Constructs a new semaphore using the given dispatch_semaphore_t object.


Member Function Documentation

Acquires the semaphore.

Decrements the counting semaphore. If the value is less than zero it will wait until another thread released the semaphore.

Returns:
The dispatch_semaphore_t object associated with this C++ object. Use this, if you need to use the plain C Interface of libdispatch.
bool xdispatch::semaphore::operator!= ( const semaphore )
bool xdispatch::semaphore::operator!= ( const dispatch_semaphore_t )
semaphore& xdispatch::semaphore::operator= ( const semaphore )
bool xdispatch::semaphore::operator== ( const semaphore )
bool xdispatch::semaphore::operator== ( const dispatch_semaphore_t )

Release the semaphore.

Increments the counting semaphore. If the previous value was less than zero, this function wakes a waiting thread before returning.

Returns:
non-zero if a thread was woken, zero otherwise.

Tries to acquire the semaphore.

Decrements the counting semaphore. If the value is less than zero it will wait until either another thread released the semaphore or the timeout passed.

Returns:
true if acquiring the semaphore succeeded.
bool xdispatch::semaphore::try_acquire ( struct tm *  )

Tries to acquire the semaphore.

Decrements the counting semaphore. If the value is less than zero it will wait until either another thread released the semaphore or the timeout passed.

Returns:
true if acquiring the semaphore succeeded.

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Sun Jan 27 2013 21:21:52 for XDispatch by Doxygen 1.7.6.1
© 2010-2013 MLBA (about | privacy) All Rights reserved.