]> git.tdb.fi Git - libs/core.git/blob - source/thread.h
Use an extra bool variable to indicate thread validity
[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 #include <pthread.h>
10
11 namespace Msp {
12
13 class Thread
14 {
15 public:
16         void *join();
17         void kill(int s)   { pthread_kill(thread_, s); }
18         virtual ~Thread();
19 protected:
20         Thread(): valid_(false) { }
21         void launch()      { if(!valid_) pthread_create(&thread_, 0, &main_, this); }
22         virtual void *main()=0;
23         void exit(void *r) { pthread_exit(r); }
24 private:
25         pthread_t thread_;
26         bool      valid_;
27
28         Thread(const Thread &);
29         Thread &operator=(const Thread &);
30
31         static void *main_(void *t) { return ((Thread *)t)->main(); }
32 };
33
34 } // namespace Msp
35
36 #endif