Class: TLocalCountingSemaphore

Declaration: CountingSemaphore.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

TCountingSemaphore

Inherited By:

None.

Purpose:

WARNING: Do not directly #include CountingSemaphore.h in any of your files. It is included in this version of the CommonPoint application system for internal implementation. It will be removed in future versions (and the public classes it contains will be moved to other public headers). Provides a concrete class with counting semaphore features, for use in a single address space.

Instantiation:

Allocate on the heap or the stack. This object should not be created in shared address space for sharing.

Deriving Classes:

None.

Concurrency:

Multithread safe.

Resource Use:

No special requirements.

Other Considerations:

This object is for use within single address space, and should not be created in shared address space.

Member Function: TLocalCountingSemaphore::TLocalCountingSemaphore

TLocalCountingSemaphore (long count =0)

Interface Category:

API.

Purpose:

Constructor constructs the semaphore.

Calling Context:

Called by the derived class constructors as well as client code.

Parameters:

Return Value:

None.

Exceptions:

Throws TGeneralKernelException(TGeneralKernelException::kBadArgument) if count is less than zero.

Concurrency:

Multithread safe.

Other Considerations:

After construction the count of the semaphore is set to value of 'count'.

Member Function: TLocalCountingSemaphore::~TLocalCountingSemaphore

virtual ~ TLocalCountingSemaphore ()

Interface Category:

API.

Purpose:

Destructor.

Calling Context:

Called to destroy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws TSemaphoreException(TSemaphoreException::kSemaphoreDeleted) if semaphore is being deleted.

Concurrency:

Multithread safe.

Other Considerations:

Wherenver the destructor of the TLocalCounting semaphore is called, all the waiting threads are woken up, the threads awakened get TSemaphoreException::kSemaphoreDeleted exception.

Member Function: TLocalCountingSemaphore::P

  1. virtual void P ()
  2. virtual void P (const TTime & aTimeOut)

Interface Category:

API.

Purpose:

  1. Tries to decrement the count on the semaphore, waits if count is zero.
  2. Tries to decrement the count on the semaphore, waits for specified time if count is zero. Upon timeout throws an exception TTimeOutException::kTimeExpired.

Calling Context:

  1. Called to receive a signal or decrement the count.
  2. Called to receive a signal or decrement the count within certain time bound.

Parameters:

Return Value:

None.

Exceptions:

Throws TSemaphoreException(TSemaphoreException::kSemaphoreDeleted) if semaphore is being deleted. Throws TTimeOutException(TTimeOutException::kTimeExpired) if operation times out.

Concurrency:

Multithread safe.

Other Considerations:


Member Function: TLocalCountingSemaphore::TryP

virtual bool TryP ()

Interface Category:

API.

Purpose:

Tries to receive a signal or decrement the count, but doesn't wait if the count is zero.

Calling Context:

Called to receive a signal or decrement the count, without having to wait.

Parameters:

Return Value:

Returns true if successfully decremented the count, false otherwise.

Exceptions:

Throws TSemaphoreException(TSemaphoreException::kSemaphoreDeleted) if semaphore is being deleted.

Concurrency:

Multithread safe.

Other Considerations:


Member Function: TLocalCountingSemaphore::V

virtual void V ()

Interface Category:

API.

Purpose:

Provides an operation to send a signal or to increment the count.

Calling Context:

Called to send a signal or to increment the count.

Parameters:

Return Value:

None.

Exceptions:

Throws TSemaphoreException(TSemaphoreException::kSemaphoreDeleted) if semaphore is being deleted.

Concurrency:

Multithread safe.

Other Considerations:

Any waiting threads are woken up in FIFO order.

Member Function: TLocalCountingSemaphore::GetCount

virtual long GetCount () const

Interface Category:

API.

Purpose:

Provides a means of finding out the current count.

Calling Context:

Called to get the value of the semaphore count.

Parameters:

Return Value:

Current count at the time of the call.

Exceptions:

Throws TSemaphoreException(TSemaphoreException::kSemaphoreDeleted) if semaphore is being deleted.

Concurrency:

The count value is not safe to use, because of the concurrent access to the semaphore by multiple threads.

Other Considerations:

The value returned from this operation may not safe to use.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.