RAUL  0.5.1
Public Member Functions | List of all members
Raul::Semaphore Class Reference

Trivial wrapper around POSIX semaphores (zero memory overhead). More...

#include <Semaphore.hpp>

Public Member Functions

 Semaphore (unsigned int initial)
 
void reset (unsigned int initial)
 
bool has_waiter ()
 
void post ()
 Increment (and signal any waiters). More...
 
void wait ()
 Wait until count is > 0, then decrement. More...
 
bool try_wait ()
 Non-blocking version of wait(). More...
 

Detailed Description

Trivial wrapper around POSIX semaphores (zero memory overhead).

This was created to provide an alternative debuggable implementation of semaphores based on a cond/mutex pair because semaphore's appeared not to work in GDB. Turns out sem_wait can fail when run in GDB, and Debian really needs to update it's man pages.

This class remains as a trivial (yet pretty) wrapper/abstraction, because Glib (idiotically) doesn't have a Semaphore class.

Member Function Documentation

void Raul::Semaphore::post ( )
inline

Increment (and signal any waiters).

Realtime safe.

Referenced by Raul::Slave::whip().

void Raul::Semaphore::wait ( )
inline

Wait until count is > 0, then decrement.

Note that sem_wait always returns 0 in practise. It returns nonzero when run in GDB, so the while is necessary to allow debugging.

Obviously not realtime safe.

Referenced by Raul::Command::operator()().

bool Raul::Semaphore::try_wait ( )
inline

Non-blocking version of wait().

Returns
true if decrement was successful (lock was acquired).

Realtime safe?


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