GlobalSearch::SlottedWaitCondition Class Reference

A wrapper for QWaitCondition that has slots for wakeOne and wakeAll. See warning in expanded documentation. More...

#include <globalsearch/slottedwaitcondition.h>

List of all members.

Public Slots

void wakeOneSlot ()
void wakeAllSlot ()
void prewaitLock ()
void postwaitUnlock ()

Public Member Functions

 SlottedWaitCondition (QObject *parent)
virtual ~SlottedWaitCondition ()
QMutex * mutex ()
void wait (unsigned long timeout)

Detailed Description

A wrapper for QWaitCondition that has slots for wakeOne and wakeAll. See warning in expanded documentation.

Warning:
Misuse of this class can easily lead to a deadlock. If all calls to the wake* slots are made before wait() is called, the code may hang indefinitely. Ensure that wait() is not called without setting a timeout to prevent this. For similar reasons, it is recommended that this construct is only used for trivial applications, such as GUI updates.

This class adds a few new functions to QWaitCondition:

SlottedWaitCondition also includes an internal mutex that can be used for create critical sections before and after calls to wait(). Normally an external mutex is used for this, but calls to wait(), prewaitLock(), and postwaitUnlock() use the internal mutex. Calling mutex() will return a pointer to this mutex. Typical usage of this wait condition is:

SlottedWaitCondition slottedWC;
...
connect(sender, SIGNAL(somethingThatFreesSlottedWCsResources()),
        &slottedWC, SLOT(wakeAllSlot()));

slottedWC->prewaitLock();
// Do any work that needs to be peformed in a critical section before waiting
...

// Check every 250 milliseconds that we still need to be waiting
while (someConditionIsTrue) {
  slottedWC->wait(250);
}

// Do any work that needs to be done in a critical section after waking
...

slottedWC->postwaitUnlock();
Author:
David C. Lonie

Definition at line 74 of file slottedwaitcondition.h.


Constructor & Destructor Documentation

GlobalSearch::SlottedWaitCondition::SlottedWaitCondition ( QObject *  parent  ) 

Constructor.

Parameters:
parent Parent for QObject.

Definition at line 20 of file slottedwaitcondition.cpp.

GlobalSearch::SlottedWaitCondition::~SlottedWaitCondition (  )  [virtual]

Destructor.

Definition at line 27 of file slottedwaitcondition.cpp.


Member Function Documentation

QMutex* GlobalSearch::SlottedWaitCondition::mutex (  )  [inline]
Returns:
A pointer to the internal mutex, m_mutex.
See also:
prewaitLock
postwaitUnlock
wait

Definition at line 108 of file slottedwaitcondition.h.

void GlobalSearch::SlottedWaitCondition::postwaitUnlock (  )  [inline, slot]

Unlock the internal mutex, m_mutex, to end the critical section after calling wait().

Definition at line 159 of file slottedwaitcondition.h.

void GlobalSearch::SlottedWaitCondition::prewaitLock (  )  [inline, slot]

Lock the internal mutex, m_mutex, to create a critical section before calling wait().

Definition at line 153 of file slottedwaitcondition.h.

void GlobalSearch::SlottedWaitCondition::wait ( unsigned long  timeout  )  [inline]

Wait until woken up by one of:

Warning:
Misuse of this function can easily lead to a deadlock. If all calls to the wake* slots are made before wait() is called, the code may hang indefinitely. Ensure that wait() is only called using a reasonable timeout to prevent this. For similar reasons, it is recommended that this construct is only used for trivial applications, such as GUI updates.
Parameters:
timeout Timeout in milliseconds. After this time, the wait condition will wake itself and continue.

This function expects the internal mutex, m_mutex, to be locked before prior to using being called. This can be accomplished by calling lock() on mutex() or prewaitLock(). The internal mutex will be locked before returning from this function. The mutex can be unlocked by calling the convenience function postwaitUnlock(). See class description for example usage.

Definition at line 135 of file slottedwaitcondition.h.

void GlobalSearch::SlottedWaitCondition::wakeAllSlot (  )  [inline, slot]

Slot that calls QWaitCondition::wakeAll()

Definition at line 147 of file slottedwaitcondition.h.

void GlobalSearch::SlottedWaitCondition::wakeOneSlot (  )  [inline, slot]

Slot that calls QWaitCondition::wakeOne()

Definition at line 142 of file slottedwaitcondition.h.


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations Enumerator
Generated on Mon Jul 16 14:40:04 2012 for GlobalSearch by  doxygen 1.6.3