Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::port::Semaphore Class Reference

A Semaphore enables threads and process synchronization. More...

#include "semaphore.h"

Public Member Functions

 Semaphore ()
 Initializes a semaphore with an internal value of zero. More...
 
 Semaphore (uint32 initial_value)
 Initializes a semaphore with an explicit initial value. More...
 
 ~Semaphore ()
 
bool Post ()
 Wakes a single thread that is Wait()ing, or the next thread to call Wait(). More...
 
bool Wait ()
 Blocks the calling thread until another thread calls Post(). More...
 
bool TryWait ()
 Does not block. More...
 
bool TimedWaitMs (int64 timeout_in_ms)
 Blocks for a maximum of the passed number of milliseconds before returning. More...
 

Detailed Description

A Semaphore enables threads and process synchronization.

Semaphores block via a call to Wait(), and are woken when another thread calls Post() on the same Semaphore. If multiple threads are Wait()ing, then a call to Post() will wake only one thread.

Definition at line 40 of file semaphore.h.

Constructor & Destructor Documentation

ion::port::Semaphore::Semaphore ( )

Initializes a semaphore with an internal value of zero.

Definition at line 36 of file semaphore.cc.

ion::port::Semaphore::Semaphore ( uint32  initial_value)
explicit

Initializes a semaphore with an explicit initial value.

Definition at line 50 of file semaphore.cc.

References Post().

ion::port::Semaphore::~Semaphore ( )

Definition at line 73 of file semaphore.cc.

Member Function Documentation

bool ion::port::Semaphore::Post ( )

Wakes a single thread that is Wait()ing, or the next thread to call Wait().

Returns false if there was an error while trying to post.

Definition at line 85 of file semaphore.cc.

Referenced by ion::gfxutils::ResourceCallback< T >::Callback(), ion::gfxutils::ResourceCallback< T >::ResourceCallback(), Semaphore(), ion::base::ReadWriteLock::UnlockForRead(), and ion::base::ReadWriteLock::UnlockForWrite().

bool ion::port::Semaphore::TimedWaitMs ( int64  timeout_in_ms)

Blocks for a maximum of the passed number of milliseconds before returning.

Returns whether the semaphore was Post()ed within the timeout. Passing a negative value for the timeout is equivalent to calling Wait();

Definition at line 143 of file semaphore.cc.

References TryWait(), Wait(), and ion::port::YieldThread().

bool ion::port::Semaphore::TryWait ( )

Does not block.

Returns whether the semaphore has been Post()ed. A return value of true means that a call to Wait() would not have blocked, while a return value of false means that a call to Wait() would have blocked.

Definition at line 107 of file semaphore.cc.

Referenced by TimedWaitMs(), and Wait().

bool ion::port::Semaphore::Wait ( )

Blocks the calling thread until another thread calls Post().

Returns false if there was an error while trying to wait.

Definition at line 205 of file semaphore.cc.

References TryWait().

Referenced by ion::base::ReadWriteLock::LockForRead(), ion::base::ReadWriteLock::LockForWrite(), TimedWaitMs(), and ion::gfxutils::ResourceCallback< T >::WaitForCompletion().


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