File: StopSignalThread.cpp

package info (click to toggle)
primrose 6%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,304 kB
  • sloc: cpp: 27,318; php: 765; ansic: 636; objc: 272; sh: 136; makefile: 92; perl: 67
file content (65 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (30)
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();
    }