[Home] [Prev] [Next] [Up]


XGCritical class

Provides a stack-based object to provide stack-safe access to the semaphore EnterCritical/LeaveCritical routines.

Usage:

#include <XThread.h>

class XGCritical;

Description

This stack-based object provides a stack-safe mechanism for handling semaphore access.

Notes

This object should be created as an automatic on the stack.

For example, suppose the routine DoThing() needs to be serialized: that is, the access to this function should be done by only one thread at a time. Use this routine to protect the routine even in the face of exception processing:

void DoThing(void)
{
    XGCritical csection(&GMySemaphore);

    ... do processing ...
}

On return this will automatically release the semaphore.

Constructor/Destructors

XGCritical::XGCritical(XGSemaphore *ptr)

This calls the semaphore's EnterCritical method, and stores the pointer for the destructor.

XGCritical::~XGCritical()

This calls the semaphore's LeaveCritical method.


[Home] [Prev] [Next] [Up]