]> git.tdb.fi Git - libs/core.git/blob - source/thread.h
51ca0ef3395c2abe80d182a6cef056429d655e75
[libs/core.git] / source / thread.h
1 /*
2 This file is part of libmspframework
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
5 */
6 #ifndef MSP_FRAMEWORK_THREAD_H_
7 #define MSP_FRAMEWORK_THREAD_H_
8
9 #ifdef WIN32
10 #include "win32signum.h"
11 #endif
12
13 #include <pthread.h>
14
15 namespace Msp {
16
17 class Thread
18 {
19 public:
20         void *join();
21         void kill(int s)   { pthread_kill(thread_, s); }
22         virtual ~Thread();
23 protected:
24         Thread(): valid_(false) { }
25         void launch()      { if(!valid_) pthread_create(&thread_, 0, &main_, this); }
26         virtual void *main()=0;
27         void exit(void *r) { pthread_exit(r); }
28 private:
29         pthread_t thread_;
30         bool      valid_;
31
32         Thread(const Thread &);
33         Thread &operator=(const Thread &);
34
35         static void *main_(void *t) { return ((Thread *)t)->main(); }
36 };
37
38 } // namespace Msp
39
40 #endif