VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
G::Semaphore Class Reference

A semaphore class with a posix or sysv implementation chosen at build-time. More...

#include <gsemaphore.h>

Classes

struct  storage_type
 semaphore storage More...
 

Public Member Functions

 Semaphore (unsigned int initial_value=1U)
 Constructor for a new anonymous semaphore, typically located inside a shared memory segment using "placement new". More...
 
 ~Semaphore ()
 Destroys the semaphore. More...
 
void increment ()
 Increment operator. Used for mutex unlocking.
 
void decrement ()
 Decrement-but-block-if-zero operator. More...
 
bool decrement (int timeout_s)
 Overload with a timeout. Returns true if decremented.
 

Static Public Member Functions

static Semaphoreat (storage_type *)
 Syntactic sugar to return an object pointer corresponding to the given storage pointer. More...
 

Friends

class G::SemaphoreImp
 

Detailed Description

A semaphore class with a posix or sysv implementation chosen at build-time.

Eg.

struct Memory { Semaphore::storage_type sem_storage ; int value ; } ;
Memory * mem = static_cast<Memory*>( mem_p ) ;
Semaphore * s = new (&mem->sem_storage) Semaphore ; // creator - placement new
Semaphore * s = Semaphore::at(&mem->sem_storage) ; // user
s->decrement() ; // lock - may block
mem->value = 999 ;
s->increment() ; // unlock
s->~Semaphore() ; // creator - placement delete

Definition at line 47 of file gsemaphore.h.

Constructor & Destructor Documentation

G::Semaphore::Semaphore ( unsigned int  initial_value = 1U)
explicit

Constructor for a new anonymous semaphore, typically located inside a shared memory segment using "placement new".

The initial value should be one for a mutex.

Definition at line 43 of file gsemaphore_posix.cpp.

G::Semaphore::~Semaphore ( )

Destroys the semaphore.

Results are undefined if there are waiters.

Definition at line 54 of file gsemaphore_posix.cpp.

Member Function Documentation

G::Semaphore * G::Semaphore::at ( storage_type p)
static

Syntactic sugar to return an object pointer corresponding to the given storage pointer.

Definition at line 37 of file gsemaphore_posix.cpp.

void G::Semaphore::decrement ( )

Decrement-but-block-if-zero operator.

Used for mutex locking.

Definition at line 74 of file gsemaphore_posix.cpp.


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