WindowsUtils::Semaphore Class Reference
[Semaphore]

#include <wsemaphore.h>

List of all members.


Detailed Description

Class Sempahore is obtained from [WIN32SEMAPHORE] at [BBDSOFT] with this license.


Public Member Functions

 Semaphore (const char *const inName=0, const unsigned long inInitialCount=0, const unsigned long inMaximumCount=0)
 constructor.

 ~Semaphore ()
 destructor.

Semaphorepost (const unsigned long inPostCount=1)
 release semaphore.

Semaphorewait (const unsigned long inTimeout=0)
 acquire semaphore.

unsigned long maxCount () const
 return theMaxCount.


Private Member Functions

 Semaphore (const Semaphore &)
 disable copy constructor and assignment operator.

Semaphoreoperator= (const Semaphore &)

Private Attributes

unsigned theSemaphoreHandle
 semaphore handle.

unsigned long theMaxCount
 maximum count.


Constructor & Destructor Documentation

WindowsUtils::Semaphore::Semaphore const char *const   inName = 0,
const unsigned long  inInitialCount = 0,
const unsigned long  inMaximumCount = 0
 

Create the semaphore named inName with initial count inInitialCount and maximum count inMaximumCount. If the named semaphore already exists, that semaphore is used. If the semaphore could not be created or opened the following runtime error is generated: "Semaphore: failed to create.".

Exceptions:
Semaphore: failed to create. if the semaphore could not be created or opened this runtime error message is generated.
Parameters:
inName a null-terminated string specifying the name of the semaphore object. The name is limited to MAX_PATH characters, and can contain any character except the backslash path-separator character (\). Name comparison is case sensitive. If lpName matches the name of an existing named semaphore object, this function requests SEMAPHORE_ALL_ACCESS access to the existing object. In this case, the lInitialCount and lMaximumCount parameters are ignored because they have already been set by the creating process. If the lpSemaphoreAttributes parameter is not NULL, it determines whether the handle can be inherited, but its security-descriptor member is ignored.
If lpName is NULL, the semaphore object is created without a name. If lpName matches the name of an existing event, mutex, or file- mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because event, mutex, semaphore, and file-mapping objects share the same name space.
inInitialCount specifies an initial count for the semaphore object. This value must be greater than or equal to zero and less than or equal to lMaximumCount. The state of a semaphore is signaled when its count is greater than zero and nonsignaled when it is zero. The count is decreased by one whenever a wait function releases a thread that was waiting for the semaphore. The count is increased by a specified amount by calling the ReleaseSemaphore function.
inMaximumCount specifies the maximum count for the semaphore object. This value must be greater than zero.

WindowsUtils::Semaphore::~Semaphore  ) 
 

The destructor closes the semaphore.

Exceptions:
Semaphore: failed to close. if the semaphore could not be closed this runtime error message is generated.


Member Function Documentation

Semaphore & WindowsUtils::Semaphore::post const unsigned long  inPostCount = 1  ) 
 

post() increments semaphore counter by inPostCount. inPostCount must not be 0.

Parameters:
inPostCount [1]
Returns:

Semaphore & WindowsUtils::Semaphore::wait const unsigned long  inTimeout = 0  ) 
 

wait() waits while semaphore counter is greater than 0 and decrements semaphore counter by 1.

Parameters:
inTimeout [0]
Returns:


The documentation for this class was generated from the following files:
Generated on Tue Sep 30 11:48:51 2003 for Windows Utilities by doxygen 1.3.4