]> git.sesse.net Git - cubemap/blob - thread.cpp
Factor serializing into its own function. Again, less stuff in main().
[cubemap] / thread.cpp
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <signal.h>
4
5 #include "thread.h"
6
7 void Thread::run()
8 {
9         should_stop = false;
10         pthread_create(&worker_thread, NULL, &Thread::do_work_thunk, this);
11 }
12
13 void Thread::stop()
14 {
15         should_stop = true;
16         pthread_kill(worker_thread, SIGHUP);
17         if (pthread_join(worker_thread, NULL) == -1) {
18                 perror("pthread_join");
19                 exit(1);
20         }
21 }
22
23 void *Thread::do_work_thunk(void *arg)
24 {
25         Thread *thread = reinterpret_cast<Thread *>(arg);
26         thread->do_work();
27         return NULL;
28 }
29