Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

/home/jeroen/FOX/fox/fox-1.7.33/include/FXThread.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *                 M u l i t h r e a d i n g   S u p p o r t                     *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2004,2012 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (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                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXTHREAD_H
00022 #define FXTHREAD_H
00023 
00024 #ifndef FXRUNNABLE_H
00025 #include "FXRunnable.h"
00026 #endif
00027 
00028 namespace FX {
00029 
00030 
00058 class FXAPI FXThread : public FXRunnable {
00059 private:
00060   volatile FXThreadID tid;
00061   volatile FXbool     busy;
00062 private:
00063   static FXAutoThreadStorageKey selfKey;
00064 private:
00065   FXThread(const FXThread&);
00066   FXThread &operator=(const FXThread&);
00067 #if defined(WIN32)
00068   static unsigned int CALLBACK function(void*);
00069 #else
00070   static void* function(void*);
00071 #endif
00072 protected:
00073   static void self(FXThread* t);
00074 public:
00075 
00077   enum Priority {
00078     PriorityError=-1,   
00079     PriorityDefault,    
00080     PriorityMinimum,    
00081     PriorityLower,      
00082     PriorityMedium,     
00083     PriorityHigher,     
00084     PriorityMaximum     
00085     };
00086 
00088   enum Policy {
00089     PolicyError=-1,     
00090     PolicyDefault,      
00091     PolicyFifo,         
00092     PolicyRoundRobin  
00093     };
00094 
00095 public:
00096 
00098   FXThread();
00099 
00105   FXThreadID id() const;
00106 
00110   FXbool running() const;
00111 
00119   FXbool start(unsigned long stacksize=0);
00120 
00125   FXbool join();
00126 
00133   FXbool join(FXint& code);
00134 
00143   FXbool cancel();
00144 
00150   FXbool detach();
00151 
00157   static void exit(FXint code=0);
00158 
00162   static void yield();
00163 
00167   static FXTime time();
00168 
00172   static void sleep(FXTime nsec);
00173 
00177   static void wakeat(FXTime nsec);
00178 
00184   static FXThread* self();
00185 
00189   static FXThreadID current();
00190 
00194   static FXint processors();
00195 
00199   static FXThreadStorageKey createStorageKey();
00200 
00204   static void deleteStorageKey(FXThreadStorageKey key);
00205 
00209   static void* getStorage(FXThreadStorageKey key);
00210 
00214   static void setStorage(FXThreadStorageKey key,void* ptr);
00215 
00219   FXbool priority(Priority prio);
00220 
00224   Priority priority() const;
00225 
00229   FXbool policy(Policy plcy);
00230 
00234   Policy policy() const;
00235 
00240   FXbool affinity(FXulong mask);
00241 
00245   FXulong affinity() const;
00246 
00250   FXbool suspend();
00251 
00255   FXbool resume();
00256 
00262   virtual ~FXThread();
00263   };
00264 
00265 }
00266 
00267 #endif
00268 

Copyright © 1997-2011 Jeroen van der Zijp