[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

 

LSemaphore



Overview:

LSemaphore is a PowerPlant class that is used for implementing semaphores. Most of the methods and members are internal to PowerPlant.

Methods :

The methods in this class are:

 

LSemaphore()  
~LSemaphore()  
BlockThread()  
InitSemaphore()  
Signal()  
UnblockAll()  
UnblockThread()  
Wait()  
operator =()  
 

Data Members:

The data members in this class are:

 

mExcessSignals0  
mThreads  

Operation:

The only two methods you will typically concern yourself with are Wait() and Signal().

Source files:

(Threads Classes)

LSemaphore.h

LSemaphore.cp

See also:

LEventSemaphore

LMutexSemaphore

LThread

LSemaphore()

Purpose:

The constructor creates the object.

Access :

Public

Prototype:

LSemaphore();

LSemaphore(SInt32 initialCount);

Copy Constructor

LSemaphore(const LSemaphore&); 
Parameters:

SInt32 containing the initial count to set the semaphore at, or a semaphore to make a copy of.

~LSemaphore()

Purpose:

The destructor destroys the LSemaphore object.

Access :

Virtual, Public

Prototype:

~LSemaphore();

BlockThread()

Purpose:

Block the current thread for the given number of milliseconds, refer to Wait().

NOTE: The current thread must be in a 1-level-deep critical section upon entering this function!

Access :

Protected

Prototype:

ExceptionCode BlockThread(SInt32 milliSeconds);
Parameters:

SInt32 containing the number of msec to block for.

Return:

An exception code

InitSemaphore()

Purpose:

Initializes the fields of a semaphore.

Access :

Private

Prototype:

void InitSemaphore(SInt32 initialCount);
Parameters:

The initial count to set the semaphore to.

Return:

None

Signal()

Purpose:

Release a semaphore. If any threads are waiting on the semaphore, one of them is unblocked.

Access :

Virtual, Public

Prototype:

virtual void Signal();
Parameters:

None

Return:

None

UnblockAll()

Purpose:

Unblock all of the threads waiting on this semaphore, passing them the given error code.

Access :

Protected

Prototype:

void UnblockAll(ExceptionCode error);
Parameters:

The exception code

Return:

None

UnblockThread()

Purpose:

Unblock the thread pointed to by qEl, passing it the given error code.

NOTE: The current thread must be in a critical section upon entering this method!

Access :

Protected

Prototype:

LThread* UnblockThread(QElemPtr qEl, 
  ExceptionCode error);
Parameters:

The parameters for this method are:

 

QElemPtr  
qEl  
The queue element.  
ExceptionCode  
error  
The exception code.  

Return:

A pointer to the thread

Wait()

Purpose:

Wait for a semaphore to become available. An optional argument specifies how long the caller is willing to wait for the semaphore to become available. Possible values are:

If the time interval expires before the semaphore becomes available, this function returns errSemaphoreTimedOut.

Access :

Virtual, Public

Prototype:

ExceptionCode Wait(SInt32 milliSeconds);
Parameters:

The time to wait in msec.

Return:

An exception code.

operator =()

Purpose:

The assignment operator

Access :

Private

Prototype:

LSemaphore&		operator = (const LSemaphore&);
Parameters:

A reference to a semaphore

Return:

A reference to a semaphore

mExcessSignals0

Purpose:

Excess signal / thread count

Access :

Protected

Prototype:

SInt32 mExcessSignals;

mThreads

Purpose:

List of waiting threads

Access :

Protected

Prototype:

QHdr mThreads;

 


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: July 21, 2000