]> git.tdb.fi Git - libs/core.git/blobdiff - source/thread.h
Add files
[libs/core.git] / source / thread.h
diff --git a/source/thread.h b/source/thread.h
new file mode 100644 (file)
index 0000000..a115853
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+This file is part of libmspframework
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+#ifndef MSP_FRAMEWORK_THREAD_H_
+#define MSP_FRAMEWORK_THREAD_H_
+
+#include <pthread.h>
+
+namespace Msp {
+
+class Thread
+{
+public:
+       void *join();
+       void kill(int s)   { pthread_kill(thread_, s); }
+       virtual ~Thread();
+protected:
+       Thread()           { }
+       void launch()      { pthread_create(&thread_, 0, &main_, this); }
+       virtual void *main()=0;
+       void exit(void *r) { pthread_exit(r); }
+private:
+       pthread_t thread_;
+
+       Thread(const Thread &);
+       Thread &operator=(const Thread &);
+
+       static void *main_(void *t) { return ((Thread *)t)->main(); }
+};
+
+} // namespace Msp
+
+#endif