1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
/*
* Modification History
*
* 2002-April-4 Jason Rohrer
* Created.
* Changed to reflect the fact that the base class
* destructor is called *after* the derived class destructor.
*
* 2002-August-5 Jason Rohrer
* Fixed member initialization order to match declaration order.
*
* 2003-September-5 Jason Rohrer
* Moved into minorGems.
*
* 2005-January-9 Jason Rohrer
* Changed to sleep on a semaphore to make sleep interruptable by stop.
*/
#include "StopSignalThread.h"
StopSignalThread::StopSignalThread()
: mStopLock( new MutexLock() ), mStopped( false ),
mSleepSemaphore( new BinarySemaphore() ) {
}
StopSignalThread::~StopSignalThread() {
delete mStopLock;
delete mSleepSemaphore;
}
void StopSignalThread::sleep( unsigned long inTimeInMilliseconds ) {
mSleepSemaphore->wait( inTimeInMilliseconds );
}
char StopSignalThread::isStopped() {
mStopLock->lock();
char stoped = mStopped;
mStopLock->unlock();
return stoped;
}
void StopSignalThread::stop() {
mStopLock->lock();
mStopped = true;
mStopLock->unlock();
// signal the semaphore to wake up the thread, if it is sleeping
mSleepSemaphore->signal();
}
|