forked from larsjuhljensen/tagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread.h
54 lines (43 loc) · 846 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
#ifndef __REFLECT_THREAD_HEADER__
#define __REFLECT_THREAD_HEADER__
#include <cassert>
#include <pthread.h>
class IThread
{
public:
virtual void start() = 0;
virtual void join() = 0;
virtual void run() = 0;
};
class Thread : public IThread
{
private:
pthread_t posix_thread;
private:
static void* wrap_run(void* object);
public:
void start();
void join();
virtual void run();
};
////////////////////////////////////////////////////////////////////////////////
void* Thread::wrap_run(void* object)
{
((IThread*)object)->run();
return NULL;
}
void Thread::start()
{
int rc = pthread_create(&(this->posix_thread), NULL, Thread::wrap_run, (void*)this);
assert(rc == 0);
}
void Thread::join()
{
void* status;
int rc = pthread_join(this->posix_thread, &status);
assert(rc == 0);
}
void Thread::run()
{
}
#endif