00001 //====================================================================== 00002 // File: thread.h 00003 // Author: Matthias Toussaint 00004 // Created: Sat Nov 25 18:56:16 CET 2006 00005 // Project: QtDMM 00006 // Description: Simplest possible posix thread class 00007 //---------------------------------------------------------------------- 00008 // This file may be used under the terms of the GNU General Public 00009 // License version 2.0 as published by the Free Software Foundation 00010 // and appearing in the file LICENSE.GPL included in the packaging of 00011 // this file. 00012 // 00013 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING 00014 // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00015 // PURPOSE. 00016 //---------------------------------------------------------------------- 00017 // Copyright 2006 Matthias Toussaint 00018 //====================================================================== 00019 00020 #ifndef THREAD_HH 00021 #define THREAD_HH 00022 00023 #include <pthread.h> 00024 00036 class Thread 00037 { 00038 public: 00040 Thread(); 00042 virtual ~Thread(); 00043 00048 int start(); 00051 void wait(); 00054 void stop() { m_run = false; } 00059 void quit(); 00062 bool running() const { return m_run; } 00063 00064 protected: 00065 bool m_run; 00066 pthread_t m_pthread; 00067 00076 virtual void run()=0; 00077 00078 private: 00082 static void *start_thread( void * ); 00083 00084 }; 00085 00086 #endif // THREAD_HH