]> git.sesse.net Git - cubemap/blob - thread.h
Split config parsing out of parse.h.
[cubemap] / thread.h
1 #ifndef _THREAD_H
2 #define _THREAD_H
3
4 #include <pthread.h>
5
6 // A rather generic thread class with start/stop functionality.
7 // NOTE: stop is somewhat racy (there's no guaranteed breakout from syscalls),
8 // since signals don't stick. We'll need to figure out something more
9 // intelligent later, probably based on sending a signal to an fd.
10
11 class Thread {
12 public:
13         void run();
14         void stop();
15
16 protected:
17         // Recovers the this pointer, and calls do_work().
18         static void *do_work_thunk(void *arg);
19
20         virtual void do_work() = 0;
21
22         volatile bool should_stop;
23
24 private:
25         pthread_t worker_thread;
26 };
27
28 #endif  // !defined(_THREAD_H)