-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thread.h
58 lines (46 loc) · 1017 Bytes
/
Thread.h
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
/*
* Thread.h
*
* Created on: Dec 27, 2012
* Author: jeff
*/
#ifndef THREAD_H_
#define THREAD_H_
#include <pthread.h>
class Thread {
public:
Thread();
virtual ~Thread();
/**
* Join on the underlying thread.
*/
void join();
/**
* Creates a pthread which targets Thread's run() method.
*/
virtual void start();
/**
* Sets a flag which means the thread should stop.
*
* Subclassers must implement the stopping behavior in run().
*/
virtual void stop();
/**
* Subclassers implement the run loop of the thread in this method.
*
* @return the return value when the Thread exits.
*/
virtual void* run() = 0;
protected:
// Flag which will be set when stop() is called.
bool killThread;
void setPriority(int prio);
private:
/**
* Static function which calls the Thread's run() method.
*/
static void* pthread_entry(void* args);
// pthread id for this thread.
pthread_t thread;
};
#endif /* THREAD_H_ */