-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thread.h
86 lines (71 loc) · 1.49 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Thread.h
*
* Base object class which provides the basic functionality and
* attributes for a pthread.
*
* Created on: Dec 27, 2012
* Author: jeff
*/
#ifndef THREAD_H_
#define THREAD_H_
#include <pthread.h>
#include <string>
class Thread {
public:
Thread(std::string name);
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;
/**
* Returns the priority of the thread.
*
* @return an int representing the priority of the thread
*/
int getPriority();
/**
* Sets the priority of the thread.
*
* @param prio - the new priority to be set
*/
void setPriority(int prio);
/**
* @return the name used by the underlying pthread
*/
std::string getName();
protected:
// Flag which will be set when stop() is called.
bool killThread;
/**
* The name of the task; reflected as the name of the underlying thread.
*/
std::string name;
/**
* pthread id for this thread.
*/
pthread_t thread;
private:
/**
* Static function which calls the Thread's run() method.
*/
static void* pthread_entry(void* args);
};
#endif /* THREAD_H_ */