![]() |
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * Base type for thread objects * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 *********************************************************************************/ 00022 #ifndef FXRUNNABLE_H 00023 #define FXRUNNABLE_H 00024 00025 #ifndef FXTHREADEDOBJECT_H 00026 #include "FXThreadedObject.h" 00027 #endif 00028 namespace FXEX { 00029 class FXThreadManager; 00030 class FXInterlock; 00031 00032 /** 00033 * A Runnable object is a base type of a worker object/thread 00034 */ 00035 class FXAPI FXRunnable : public FXThreadedObject { 00036 FXDECLARE_ABSTRACT(FXRunnable) 00037 00038 private: 00039 FXInterlock *waitlock; 00040 00041 public: 00042 enum { 00043 ID_WAKE=FXThreadedObject::ID_LAST, 00044 ID_START, 00045 ID_LAST 00046 }; 00047 00048 public: 00049 long onWake(FXObject*,FXSelector,void*); 00050 long onStart(FXObject*,FXSelector,void*); 00051 00052 protected: 00053 /// A runnable just implements the basic stuff for threads 00054 FXRunnable(FXObject *tgt=NULL,FXSelector sel=0); 00055 00056 public: 00057 /// get a handle to the thread manager (ie the main thread) 00058 FXThreadManager* getThreadManager(); 00059 00060 /// start running the object 00061 virtual void start()=0; 00062 00063 /** 00064 * sleep for some delay 00065 * - a value of zero, results in a call to yield() 00066 * - a negative value, results in a call to wait() ie, to sleep indefinately, your main 00067 * thread will then need to call wake() to wake the worker thread up (or just delete 00068 * the thread object which make an implicit wake() call) 00069 */ 00070 virtual void sleep(FXint ms=0); 00071 00072 /// yield the thread (often we just sleep) 00073 virtual void yield(); 00074 00075 /// cause the thread to sleep indefinately, can get woken up by other threads 00076 void wait(); 00077 00078 /// wake a thread up; if its not wait()ing, this does nothing 00079 void wake(); 00080 00081 /// dtor 00082 virtual ~FXRunnable(); 00083 }; 00084 00085 } // namespace FXEX 00086 #endif // FXRUNNABLE_H