-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thread.cpp
executable file
·56 lines (46 loc) · 1.1 KB
/
Thread.cpp
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
/*
* Thread.cpp
*
* Base object class which provides the basic functionality and
* attributes for a pthread.
*
* Created on: Dec 27, 2012
* Author: jeff
*/
#include "Thread.h"
Thread::Thread(std::string n) :
killThread(false),
name(n),
thread(NULL) {}
Thread::~Thread() {}
void Thread::join() {
pthread_join(thread, NULL);
}
void Thread::start() {
pthread_create(&thread, NULL, pthread_entry, this);
pthread_setname_np(thread, name.c_str());
}
void Thread::stop() {
killThread = true;
}
void* Thread::pthread_entry(void* arg) {
Thread* threadedObject = (Thread*)arg;
return threadedObject->run();
}
int Thread::getPriority() {
int policy;
struct sched_param params;
pthread_getschedparam(thread, &policy, ¶ms);
return params.sched_priority;
}
void Thread::setPriority(int prio) {
//Get us on a higher priority...
int policy;
struct sched_param params;
pthread_getschedparam(thread, &policy, ¶ms);
params.sched_priority = prio;
pthread_setschedparam(thread, policy, ¶ms);
}
std::string Thread::getName() {
return name;
}