GroupLock Class Reference

GroupLock is a synchronization object for enforcing mutual exclusion among an indefinite number of groups with indefinite cardinalities. More...

#include <GroupLock.h>

Inheritance diagram for GroupLock:

SynchMonitoredObject List of all members.

Public Member Functions

 GroupLock ()
 ~GroupLock ()
bool waitFor (uint iGroup, uint iTimeout=ETERNITY)
void release ()
 // TODO: pass the group key to release as well, and assert that it matches iHeldGroup

Protected Attributes

StrictMutex mutex
LocalCondition condition

Private Attributes

uint nHolders
uint iHeldGroup

Detailed Description

GroupLock is a synchronization object for enforcing mutual exclusion among an indefinite number of groups with indefinite cardinalities.

As an example, suppose you only had a single bathroom, and you wanted to prevent members of the opposite sex from occupying it simultaneously. You could do this by slapping a GroupLock on the door; men would enter with group key "1" and women would enter with group key "2"; the GroupLock would allow any number of men to enter together, or any number of women, but would never allow them to mix. In this case, there are only two groups, but any number of groups is supported, as long as they have unique integer identifiers. Note that there are no provisions for preventing starvation, or whatever the equally unpleasant equivalent is in this example.

Definition at line 44 of file GroupLock.h.


Constructor & Destructor Documentation

GroupLock::GroupLock (  )  [explicit]

Definition at line 29 of file GroupLock.cpp.

References iHeldGroup, and nHolders.

00030 {
00031     nHolders = 0;
00032     iHeldGroup = 0;
00033 }

GroupLock::~GroupLock (  ) 

Definition at line 35 of file GroupLock.cpp.

References nHolders.

00036 {
00037     assert(!nHolders);
00038 }


Member Function Documentation

bool GroupLock::waitFor ( uint  iGroup,
uint  iTimeout = ETERNITY 
)

Definition at line 40 of file GroupLock.cpp.

References SynchMonitoredObject::condition, convertTimeout(), iHeldGroup, SynchMonitoredObject::mutex, and nHolders.

00041 {
00042     boost::xtime atv;
00043     convertTimeout(iTimeout,atv);
00044     StrictMutexGuard mutexGuard(mutex);
00045     while (nHolders && iHeldGroup != iGroup) {
00046         if (!condition.timed_wait(mutexGuard,atv)) {
00047             return false;
00048         }
00049     }
00050     nHolders++;
00051     iHeldGroup = iGroup;
00052     return true;
00053 }

void GroupLock::release (  ) 

// TODO: pass the group key to release as well, and assert that it matches iHeldGroup

Definition at line 55 of file GroupLock.cpp.

References SynchMonitoredObject::condition, iHeldGroup, SynchMonitoredObject::mutex, and nHolders.

00056 {
00057     StrictMutexGuard mutexGuard(mutex);
00058     assert(nHolders);
00059     if (!--nHolders) {
00060         iHeldGroup = 0;
00061         condition.notify_all();
00062     }
00063 }


Member Data Documentation

uint GroupLock::nHolders [private]

Definition at line 46 of file GroupLock.h.

Referenced by GroupLock(), release(), waitFor(), and ~GroupLock().

uint GroupLock::iHeldGroup [private]

Definition at line 47 of file GroupLock.h.

Referenced by GroupLock(), release(), and waitFor().

StrictMutex SynchMonitoredObject::mutex [protected, inherited]

Definition at line 38 of file SynchMonitoredObject.h.

Referenced by ParallelExecStreamScheduler::abort(), LogicalTxnLog::checkpoint(), Database::checkpointImpl(), CheckpointThread::closeImpl(), LogicalTxnLog::commitTxn(), ParallelExecStreamScheduler::executeManager(), ParallelExecStreamScheduler::executeTask(), LogicalTxnLog::getOldestActiveTxnId(), LogicalTxnLog::newLogicalTxn(), ParallelExecStreamScheduler::readStream(), SXMutex::release(), release(), Database::requestCheckpoint(), CheckpointThread::requestCheckpoint(), LogicalTxnLog::rollbackTxn(), TimerThread::run(), CheckpointThread::run(), ThreadPoolBase::runPooledThread(), SXMutex::setSchedulingPolicy(), TimerThread::signalImmediate(), ParallelExecStreamScheduler::signalSentinel(), ThreadPoolBase::start(), TimerThread::stop(), ThreadPoolBase::stop(), ParallelExecStreamScheduler::stop(), ThreadPool< RandomAccessRequest >::submitTask(), ParallelExecStreamScheduler::tryExecuteManager(), ParallelExecStreamScheduler::tryExecuteTask(), SXMutex::tryUpgrade(), SXMutex::waitFor(), waitFor(), and Database::writeStats().

LocalCondition SynchMonitoredObject::condition [protected, inherited]

Definition at line 39 of file SynchMonitoredObject.h.

Referenced by ParallelExecStreamScheduler::abort(), Database::checkpointImpl(), CheckpointThread::closeImpl(), LogicalTxnLog::commitTxnWithGroup(), ParallelExecStreamScheduler::executeTask(), ParallelExecStreamScheduler::readStream(), SXMutex::release(), release(), Database::requestCheckpoint(), CheckpointThread::requestCheckpoint(), TimerThread::run(), CheckpointThread::run(), ThreadPoolBase::runPooledThread(), TimerThread::signalImmediate(), TimerThread::stop(), ThreadPoolBase::stop(), ParallelExecStreamScheduler::stop(), ThreadPool< RandomAccessRequest >::submitTask(), ParallelExecStreamScheduler::tryExecuteManager(), ParallelExecStreamScheduler::tryExecuteTask(), SXMutex::waitFor(), and waitFor().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:32 2009 for Fennel by  doxygen 1.5.1