VThread.hpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: VThread.hpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #ifndef VTHREAD_HPP 00045 #define VTHREAD_HPP 00046 00047 #ifdef WINCE 00048 #include <windef.h> 00049 #endif 00050 00051 #include "global.hpp" 00052 #include <assert.h> 00053 #ifndef WINCE 00054 #include <pthread.h> 00055 #endif //wince 00056 00057 #ifdef QT_THREAD_SUPPORT 00058 #include <qthread.h> 00059 #define VThread QThread 00060 #else //enable pthread threads 00061 00073 class VThread { 00074 00075 public: 00076 VThread(); 00077 virtual ~VThread() ; 00078 00079 /* @PARAM time defines waittime 00080 */ 00081 bool wait( unsigned long time = ULONG_MAX ); 00082 00083 /* starts the overwritten run() method 00084 */ 00085 void start(); 00086 00087 /* @returns if this thread's execution is done */ 00088 bool finished() const; 00089 /* @returns if this thread's execution is still proceeding */ 00090 bool running() const; 00091 00092 /* exits the currently running thread and informs all other waiting threads */ 00093 void exit(); 00094 00095 /* set the scheduling strategy to round-robin */ 00096 int setRoundRobinScheduling(int val); 00097 00098 protected: 00099 /* overwrite this with the real work method! 00100 * it is VERY important to finish this function with a call to this->exit() !!!! 00101 * if this->exit() is omitted, the wait() functionality may not work correctly! */ 00102 virtual void run() = 0; 00103 00104 00105 /* internally needed, just ignore it! */ 00106 #ifndef WINCE 00107 static void * HelperFunction (void *args); 00108 pthread_t my_thread; 00109 #else 00110 static DWORD WINAPI HelperFunction (void *args); 00111 LPDWORD my_thread; 00112 #endif //wince 00113 00114 void setRunning(bool running) {this->is_running = running;}; 00115 void setFinished(bool finished) {this->is_finished = finished;}; 00116 00117 00118 bool is_running; 00119 bool is_finished; 00120 }; 00121 #endif //enable qt_thread 00122 00123 #endif //vthread_hpp 00124