S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_semaphore Class Reference

A semaphore that is implemented as a wrapper around POSIX 1003.1b sem_t (implemented in LinuxThreads). More...

#include <s3_semaphore.h>

List of all members.

Public Methods

 s3_semaphore (int n_value=0)
 Default and initialising constructor: instantiate a new semaphore, initialising it with the supplied value. More...

 ~s3_semaphore ()
 Destructor: destroy the semaphore primitive. More...

void wait () const
 Suspend the caller until the semaphore has a non-zero value. More...

bool try_wait () const
 A non-blocking version of wait(). More...

void post () const
 Increment the value of the semaphore by one. More...

int get_value () const
 Return the current value of the semaphore. More...

void flush () const
 Ensure that the current value is zero. More...


Protected Attributes

sem_t sem
 LinuxThreads semaphore primitive. More...


Private Methods

 s3_semaphore (const s3_semaphore &src)
 Copy constructor: private for your convenience (thou shalt not copy construct an s3_semaphore - deal with it). More...

s3_semaphore & operator= (const s3_semaphore &src)
 Neither shalt thou copy assign an s3_semaphore. More...


Detailed Description

A semaphore that is implemented as a wrapper around POSIX 1003.1b sem_t (implemented in LinuxThreads).

A semaphore has a positive integer value associated with it and supports the following operations:

All the above operations are atomic and therefore require no additional locks.

All the member functions are declared const and a semaphore can therefore always be used in a const context.

Definition at line 68 of file s3_semaphore.h.


Constructor & Destructor Documentation

s3_semaphore::s3_semaphore int    n_value = 0
 

Default and initialising constructor: instantiate a new semaphore, initialising it with the supplied value.

Initialise with a value of zero (0) when used as a default constructor.

Note: The semaphore is initialised as local (i.e. not shared) as this is the only implementation currently supported by LinuxThreads.

Parameters:
n_val  Initial value (optional - default: 0).

Definition at line 42 of file s3_semaphore.cc.

References sem.

s3_semaphore::~s3_semaphore  
 

Destructor: destroy the semaphore primitive.

Definition at line 52 of file s3_semaphore.cc.

References sem.

s3_semaphore::s3_semaphore const s3_semaphore &    src [private]
 

Copy constructor: private for your convenience (thou shalt not copy construct an s3_semaphore - deal with it).

Definition at line 63 of file s3_semaphore.cc.


Member Function Documentation

void s3_semaphore::flush   const
 

Ensure that the current value is zero.

This is done by calling try_wait until the value is zero.

Definition at line 139 of file s3_semaphore.cc.

References try_wait.

int s3_semaphore::get_value   const
 

Return the current value of the semaphore.

Returns:
The semaphore value.

Definition at line 101 of file s3_semaphore.cc.

References CONST_OVERRIDE_SEM_T, and sem.

s3_semaphore & s3_semaphore::operator= const s3_semaphore &    src [private]
 

Neither shalt thou copy assign an s3_semaphore.

Definition at line 70 of file s3_semaphore.cc.

void s3_semaphore::post   const
 

Increment the value of the semaphore by one.

If the increment operation would cause the semaphore value to exceed SEM_VALUE_MAX, this function fails by throwing an exception and leaving the semaphore value unchanged.

Definition at line 90 of file s3_semaphore.cc.

References CONST_OVERRIDE_SEM_T, and sem.

Referenced by s3_rpc_server::main_loop, s3_post_office_switch::main_loop, s3_post_office::main_loop, s3_txport_tcp_rx_task::set_terminate, s3_txport_tcp_tx_task< s3_message, s3_socket_tcp >::set_terminate, s3_txport_tcp< s3_message >::set_terminate, s3_thread_base::signal_state_changed, and s3_txport_local::~s3_txport_local.

bool s3_semaphore::try_wait   const
 

A non-blocking version of wait().

If the value of the semaphore is zero, return a false, else proceed as a normal wait() call would on a non-zero value (i.e. decrement and return) and return a true.

Return values:
c  true Semaphore value decremented (proceeded like wait).
c  false Semaphore has value of zero (skirted the suspend).

Definition at line 83 of file s3_semaphore.cc.

References CONST_OVERRIDE_SEM_T, and sem.

Referenced by flush, s3_txport_tcp::main_loop, s3_txport_tcp_rx_task::main_loop, s3_txport_tcp_tx_task::main_loop, s3_txport_local::main_loop, s3_socket_tcp_ssl::read, s3_socket_tcp::read, s3_socket_tcp_ssl::write, and s3_socket_tcp::write.

void s3_semaphore::wait   const
 

Suspend the caller until the semaphore has a non-zero value.

If the semaphore obtains a non-zero value (either at the start of the call or while waiting on it), it is decremented and the call returns.

Definition at line 77 of file s3_semaphore.cc.

References CONST_OVERRIDE_SEM_T, and sem.

Referenced by s3_post_office::connect, s3_txport_tcp_rx_task::main_loop, s3_txport_tcp_tx_task::main_loop, s3_txport_local::main_loop, s3_post_office_switch::main_loop, s3_post_office::main_loop, s3_post_office_switch::s3_post_office_switch, s3_rpc_server::s3_rpc_server, and s3_thread_base::wait_on_state_changed.


Member Data Documentation

sem_t s3_semaphore::sem [protected]
 

LinuxThreads semaphore primitive.

Definition at line 74 of file s3_semaphore.h.

Referenced by get_value, post, s3_semaphore, try_wait, wait, and ~s3_semaphore.


The documentation for this class was generated from the following files:
Send comments to: s3fc@stonethree.com SourceForge Logo