semaphore Class Reference
[Synchronisation Library]

#include <winstl/synch/semaphore.hpp>

Inheritance diagram for semaphore:

critical_section< STLSOFT_CRITICAL_SECTION_ISNOT_RECURSIVE, STLSOFT_CRITICAL_SECTION_IS_TRYABLE > synchronisable_object_tag critical_section_tag

List of all members.


Detailed Description

This class acts as an semaphore based on the Win32 kernel semaphore object.

Public Types

enum  { maxCountValue = 0x7fffffff }
typedef semaphore class_type
 This type.
typedef HANDLE synch_handle_type
 The synchronisation handle type.
typedef bool bool_type
 The Boolean type.
typedef size_t count_type
 The count type.
typedef HANDLE resource_type
 The resource type.

Public Member Functions

Construction
 semaphore (synch_handle_type sem, bool_type bTakeOwnership)
 Conversion constructor.
 semaphore (count_type initialCount, count_type maxCount=maxCountValue)
 Creates an instance of the semaphore.
 semaphore (char const *name, count_type initialCount, count_type maxCount=maxCountValue)
 Creates an instance of the semaphore.
 semaphore (wchar_t const *name, count_type initialCount, count_type maxCount=maxCountValue)
 Creates an instance of the semaphore.
 semaphore (char const *name, LPSECURITY_ATTRIBUTES psa, count_type initialCount, count_type maxCount=maxCountValue)
 Creates an instance of the semaphore.
 semaphore (wchar_t const *name, LPSECURITY_ATTRIBUTES psa, count_type initialCount, count_type maxCount=maxCountValue)
 Creates an instance of the semaphore.
 ~semaphore () throw ()
 Destroys an instance of the semaphore.
Operations
void lock ()
 Acquires a lock on the semaphore, pending the thread until the lock is aquired.
bool_type lock (ws_dword_t wait)
 Acquires a lock on the semaphore, pending the thread until the lock is aquired.
bool_type try_lock ()
 Attempts to lock the semaphore.
void unlock ()
 Releases an aquired lock on the semaphore, increasing the semaphore's counter by one.
ws_long_t unlock (count_type numLocksToRelease)
 Releases a number of aquired "locks" on the semaphore, increasing the semaphore's counter by the given value.
Accessors
synch_handle_type handle ()
 The underlying kernel object handle.
synch_handle_type get ()
 The underlying kernel object handle.

Member Typedef Documentation

This type.

typedef HANDLE synch_handle_type

The synchronisation handle type.

typedef bool bool_type

The Boolean type.

typedef size_t count_type

The count type.

typedef HANDLE resource_type

The resource type.


Constructor & Destructor Documentation

semaphore ( synch_handle_type  sem,
bool_type  bTakeOwnership 
) [inline]

Conversion constructor.

References WINSTL_ASSERT.

semaphore ( count_type  initialCount,
count_type  maxCount = maxCountValue 
) [inline, explicit]

Creates an instance of the semaphore.

semaphore ( char const *  name,
count_type  initialCount,
count_type  maxCount = maxCountValue 
) [inline, explicit]

Creates an instance of the semaphore.

semaphore ( wchar_t const *  name,
count_type  initialCount,
count_type  maxCount = maxCountValue 
) [inline, explicit]

Creates an instance of the semaphore.

semaphore ( char const *  name,
LPSECURITY_ATTRIBUTES  psa,
count_type  initialCount,
count_type  maxCount = maxCountValue 
) [inline, explicit]

Creates an instance of the semaphore.

semaphore ( wchar_t const *  name,
LPSECURITY_ATTRIBUTES  psa,
count_type  initialCount,
count_type  maxCount = maxCountValue 
) [inline, explicit]

Creates an instance of the semaphore.

~semaphore (  )  throw () [inline]

Destroys an instance of the semaphore.


Member Function Documentation

void lock (  )  [inline]

Acquires a lock on the semaphore, pending the thread until the lock is aquired.

References WINSTL_ASSERT.

bool_type lock ( ws_dword_t  wait  )  [inline]

Acquires a lock on the semaphore, pending the thread until the lock is aquired.

References WINSTL_ASSERT.

bool_type try_lock (  )  [inline]

Attempts to lock the semaphore.

Returns:
true if the semaphore was aquired, or false if not

void unlock (  )  [inline]

Releases an aquired lock on the semaphore, increasing the semaphore's counter by one.

Note:
Equivalent to unlock().

References WINSTL_ASSERT.

ws_long_t unlock ( count_type  numLocksToRelease  )  [inline]

Releases a number of aquired "locks" on the semaphore, increasing the semaphore's counter by the given value.

Parameters:
numLocksToRelease The number by which to increment the semaphore's counter. If this is greater than the available value, the function fails. (It will throw an exception, if exception handling is enabled, or return -1 otherwise.)
Returns:
Returns the value of the semaphore's counter prior to the change effected by the call.
Return values:
-1 Indicates call failure (only if exception handling is not enabled).

References WINSTL_ASSERT.

synch_handle_type handle (  )  [inline]

The underlying kernel object handle.

synch_handle_type get (  )  [inline]

The underlying kernel object handle.

Referenced by winstl::get_kernel_handle(), and winstl::get_synch_handle().


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

Generated on Thu Jun 10 08:59:36 2010 for STLSoft by  doxygen 1.5.6