C12Adapter Opensource C++ Interface
MSynchronizer Class Referenceabstract

Abstract synchronizer object. More...

Inheritance diagram for MSynchronizer:

Classes

class  Locker
 Scope based locker that acquires the lock at construction, and releases it at destruction. More...
 

Public Member Functions

void Lock ()
 Lock without timeout. More...
 
virtual void Unlock ()=0
 Unlock the synchronizer by a count of one. More...
 
bool LockWithTimeout (long timeout)
 

Static Public Member Functions

static void WaitForAll (MSynchronizer *p0, MSynchronizer *p1, MSynchronizer *p2=0, MSynchronizer *p3=NULL, MSynchronizer *p4=NULL)
 Wait until all the objects in the list are set to nonsignaled state. More...
 
static bool WaitWithTimeoutForAll (long timeout, MSynchronizer *p0, MSynchronizer *p1, MSynchronizer *p2=0, MSynchronizer *p3=NULL, MSynchronizer *p4=NULL)
 Wait until all the objects in the list are set to nonsignaled state, or timeout expires. More...
 
static unsigned WaitForAny (MSynchronizer *p0, MSynchronizer *p1, MSynchronizer *p2=NULL, MSynchronizer *p3=NULL, MSynchronizer *p4=NULL)
 Wait until any of the objects in the list are set to nonsignaled state. More...
 
static bool WaitWithTimeoutForAny (long timeout, unsigned *which, MSynchronizer *p0, MSynchronizer *p1, MSynchronizer *p2=0, MSynchronizer *p3=NULL, MSynchronizer *p4=NULL)
 Wait until any of the objects in the list are set to nonsignaled state, or timeout expires. More...
 

Protected Member Functions

 MSynchronizer ()
 Constructor that creates synchronizer. More...
 
virtual ~MSynchronizer ()
 Destructor.
 

Detailed Description

Abstract synchronizer object.

Synchronizers are event and semaphore. Critical section would also be a synchronizer, but due to internal details it is not derived from this class.

The implementation of the class is system dependent.

Use Locker subclass to handle the synchronizer in a way that guarantees the boundaries of the lock within the C++ scope whether or not an exception thrown.

Constructor & Destructor Documentation

MSynchronizer::MSynchronizer ( )
inlineprotected

Constructor that creates synchronizer.

As the class is abstract, the constructor is protected. Child classes have to initialize this class field m_handle in their constructors.

Member Function Documentation

void MSynchronizer::Lock ( )
inline

Lock without timeout.

Interpretation of this operation may vary depending on the child class.

bool MSynchronizer::LockWithTimeout ( long  timeout)

Lock the synchronizer or timeout if the object is being locked for a specified number of milliseconds.

Interpretation of this operation may vary depending on the child class.

Parameters
timeoutTimeout in milliseconds. Negative value means infinite timeout. Zero timeout can be used to know if the object is currently locked. Care should be taken when specifying very long timeouts, since the parameter is of type long, which is 32-bits long, about 25 days of milliseconds.
Returns
True if the lock is acquired, false if timeout took place.
virtual void MSynchronizer::Unlock ( )
pure virtual

Unlock the synchronizer by a count of one.

Interpretation of this operation may vary depending on the child class.

Implemented in MEvent, and MSemaphore.

static void MSynchronizer::WaitForAll ( MSynchronizer p0,
MSynchronizer p1,
MSynchronizer p2 = 0,
MSynchronizer p3 = NULL,
MSynchronizer p4 = NULL 
)
inlinestatic

Wait until all the objects in the list are set to nonsignaled state.

Windows-only method.

Currently only up to five objects are supported. Only two synchronizers are mandatory. Once NULL is specified as object, no subsequent objects shall be supplied. There are assertions in the debug version. No timeout is provided, waiting is done infinitely.

Parameters
p0First object, required.
p1Second object, required.
p2Third object, optional.
p3Fourth object, optional.
p4Fifth object, optional.
static unsigned MSynchronizer::WaitForAny ( MSynchronizer p0,
MSynchronizer p1,
MSynchronizer p2 = NULL,
MSynchronizer p3 = NULL,
MSynchronizer p4 = NULL 
)
inlinestatic

Wait until any of the objects in the list are set to nonsignaled state.

Windows-only method.

Currently only up to five objects are supported. Only two synchronizers are mandatory. Once NULL is specified as object, no subsequent objects shall be supplied. There are assertions in the debug version. No timeout is provided, waiting is done infinitely.

Parameters
p0First object, required.
p1Second object, required.
p2Third object, optional.
p3Fourth object, optional.
p4Fifth object, optional.
Returns
Zero based index of the object that is in nonsignaled state.
static bool MSynchronizer::WaitWithTimeoutForAll ( long  timeout,
MSynchronizer p0,
MSynchronizer p1,
MSynchronizer p2 = 0,
MSynchronizer p3 = NULL,
MSynchronizer p4 = NULL 
)
inlinestatic

Wait until all the objects in the list are set to nonsignaled state, or timeout expires.

Windows-only method.

Currently only up to five objects are supported. Only two synchronizers are mandatory. Once NULL is specified as object, no subsequent objects shall be supplied. There are assertions in the debug version.

Parameters
timeoutTimeout in milliseconds. Negative value means infinite timeout. Zero timeout can be used to know if all objects are currently locked. Care should be taken when specifying very long timeouts, since the parameter is of type long, which is 32-bits, about 25 days of milliseconds.
p0First object, required.
p1Second object, required.
p2Third object, optional.
p3Fourth object, optional.
p4Fifth object, optional.
Returns
True if the lock on all objects is acquired, false if there is a timeout.
static bool MSynchronizer::WaitWithTimeoutForAny ( long  timeout,
unsigned *  which,
MSynchronizer p0,
MSynchronizer p1,
MSynchronizer p2 = 0,
MSynchronizer p3 = NULL,
MSynchronizer p4 = NULL 
)
inlinestatic

Wait until any of the objects in the list are set to nonsignaled state, or timeout expires.

Windows-only method.

Currently only up to five objects are supported. Only two synchronizers are mandatory. Once NULL is specified as object, no subsequent objects shall be supplied. There are assertions in the debug version.

Parameters
timeoutTimeout in milliseconds. Negative value means infinite timeout. Zero timeout can be used to know if all objects are currently locked. Care should be taken when specifying very long timeouts, since the parameter is of type long, which is 32-bits, about 25 days of milliseconds.
whichReturn value through pointer, zero based index of the object that is in nonsignaled state.
p0First object, required.
p1Second object, required.
p2Third object, optional.
p3Fourth object, optional.
p4Fifth object, optional.
Returns
True if the lock on an object is acquired, false if there is a timeout.