00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TThread
00013 #define ROOT_TThread
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef ROOT_TObject
00028 #include "TObject.h"
00029 #endif
00030 #ifndef ROOT_TMutex
00031 #include "TMutex.h"
00032 #endif
00033 #ifndef ROOT_TCondition
00034 #include "TCondition.h"
00035 #endif
00036 #ifndef ROOT_TSystem
00037 #include "TSystem.h"
00038 #endif
00039 #ifndef ROOT_TTimer
00040 #include "TTimer.h"
00041 #endif
00042 #ifndef ROOT_Varargs
00043 #include "Varargs.h"
00044 #endif
00045
00046 class TThreadImp;
00047
00048
00049 class TThread : public TNamed {
00050
00051 friend class TThreadImp;
00052 friend class TPosixThread;
00053 friend class TThreadTimer;
00054 friend class TThreadCleaner;
00055 friend class TWin32Thread;
00056
00057 public:
00058
00059 typedef void *(*VoidRtnFunc_t)(void *);
00060 typedef void (*VoidFunc_t)(void *);
00061
00062 enum EPriority {
00063 kLowPriority,
00064 kNormalPriority,
00065 kHighPriority
00066 };
00067
00068 enum EState {
00069 kInvalidState,
00070 kNewState,
00071 kRunningState,
00072 kTerminatedState,
00073
00074 kFinishedState,
00075 kCancelingState,
00076 kCanceledState,
00077 kDeletingState
00078 };
00079
00080 private:
00081 TThread *fNext;
00082 TThread *fPrev;
00083 TThread **fHolder;
00084 EPriority fPriority;
00085 EState fState;
00086 EState fStateComing;
00087 Long_t fId;
00088 Long_t fHandle;
00089 Bool_t fDetached;
00090 Bool_t fNamed;
00091 VoidRtnFunc_t fFcnRetn;
00092 VoidFunc_t fFcnVoid;
00093 void *fThreadArg;
00094 void *fClean;
00095 void *fTsd[20];
00096 char fComment[100];
00097
00098 static TThreadImp *fgThreadImp;
00099 static char * volatile fgXAct;
00100 static void ** volatile fgXArr;
00101 static volatile Int_t fgXAnb;
00102 static volatile Int_t fgXArt;
00103 static Long_t fgMainId;
00104 static TThread *fgMain;
00105 static TMutex *fgMainMutex;
00106 static TMutex *fgXActMutex;
00107 static TCondition *fgXActCondi;
00108
00109
00110 void Constructor();
00111 void SetComment(const char *txt = 0)
00112 { fComment[0] = 0; if (txt) { strncpy(fComment, txt, 99); fComment[99] = 0; } }
00113 void DoError(Int_t level, const char *location, const char *fmt, va_list va) const;
00114 void ErrorHandler(int level, const char *location, const char *fmt, va_list ap) const;
00115 static void Init();
00116 static void *Function(void *ptr);
00117 static Int_t XARequest(const char *xact, Int_t nb, void **ar, Int_t *iret);
00118 static void AfterCancel(TThread *th);
00119
00120 TThread(const TThread&);
00121 TThread& operator=(const TThread&);
00122
00123 public:
00124 TThread(VoidRtnFunc_t fn, void *arg = 0, EPriority pri = kNormalPriority);
00125 TThread(VoidFunc_t fn, void *arg = 0, EPriority pri = kNormalPriority);
00126 TThread(const char *thname, VoidRtnFunc_t fn, void *arg = 0, EPriority pri = kNormalPriority);
00127 TThread(const char *thname, VoidFunc_t fn, void *arg = 0, EPriority pri = kNormalPriority);
00128 TThread(Long_t id = 0);
00129 virtual ~TThread();
00130
00131 Int_t Kill();
00132 Int_t Run(void *arg = 0);
00133 void SetPriority(EPriority pri);
00134 void Delete(Option_t *option="") { TObject::Delete(option); }
00135 EPriority GetPriority() const { return fPriority; }
00136 EState GetState() const { return fState; }
00137 Long_t GetId() const { return fId; }
00138 static void Ps();
00139 static void ps() { Ps(); }
00140
00141 static Bool_t IsInitialized();
00142
00143 Long_t Join(void **ret = 0);
00144 static Long_t Join(Long_t id, void **ret = 0);
00145
00146 static Int_t Exit(void *ret = 0);
00147 static Int_t Exists();
00148 static TThread *GetThread(Long_t id);
00149 static TThread *GetThread(const char *name);
00150
00151 static Int_t Lock();
00152 static Int_t TryLock();
00153 static Int_t UnLock();
00154 static TThread *Self();
00155 static Long_t SelfId();
00156 static Int_t Sleep(ULong_t secs, ULong_t nanos = 0);
00157 static Int_t GetTime(ULong_t *absSec, ULong_t *absNanoSec);
00158
00159 static Int_t Delete(TThread *&th);
00160 static void **Tsd(void *dflt, Int_t k);
00161
00162
00163
00164
00165
00166
00167 static Int_t SetCancelOn();
00168 static Int_t SetCancelOff();
00169 static Int_t SetCancelAsynchronous();
00170 static Int_t SetCancelDeferred();
00171 static Int_t CancelPoint();
00172 static Int_t Kill(Long_t id);
00173 static Int_t Kill(const char *name);
00174 static Int_t CleanUpPush(void *free, void *arg = 0);
00175 static Int_t CleanUpPop(Int_t exe = 0);
00176 static Int_t CleanUp();
00177
00178
00179 static void Printf(const char *fmt, ...);
00180 static void XAction();
00181
00182 ClassDef(TThread,0)
00183 };
00184
00185
00186
00187
00188
00189
00190
00191
00192 class TThreadCleaner {
00193 public:
00194 TThreadCleaner() { }
00195 ~TThreadCleaner();
00196 };
00197
00198
00199
00200
00201
00202
00203
00204
00205 class TThreadTimer : public TTimer {
00206 public:
00207 TThreadTimer(Long_t ms = 10);
00208 Bool_t Notify();
00209 };
00210
00211 #endif