]> git.sesse.net Git - cubemap/blob - thread.cpp
Move Server:add_data() into Stream, where it more logically belongs.
[cubemap] / thread.cpp
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <signal.h>
4
5 #include "thread.h"
6         
7 Thread::~Thread() {}
8
9 void Thread::run()
10 {
11         should_stop = false;
12         pthread_create(&worker_thread, NULL, &Thread::do_work_thunk, this);
13 }
14
15 void Thread::stop()
16 {
17         should_stop = true;
18         pthread_kill(worker_thread, SIGHUP);
19         if (pthread_join(worker_thread, NULL) == -1) {
20                 perror("pthread_join");
21                 exit(1);
22         }
23 }
24
25 void *Thread::do_work_thunk(void *arg)
26 {
27         Thread *thread = reinterpret_cast<Thread *>(arg);
28         thread->do_work();
29         return NULL;
30 }
31