#ifndef ROOT_TThread
#define ROOT_TThread
#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TMutex
#include "TMutex.h"
#endif
#ifndef ROOT_TCondition
#include "TCondition.h"
#endif
#ifndef ROOT_TSystem
#include "TSystem.h"
#endif
#ifndef ROOT_TTimer
#include "TTimer.h"
#endif
#ifndef ROOT_Varargs
#include "Varargs.h"
#endif
#ifndef ROOT_TThreadSlots
#include "TThreadSlots.h"
#endif
class TThreadImp;
class TThread : public TNamed {
friend class TThreadImp;
friend class TPosixThread;
friend class TThreadTimer;
friend class TThreadCleaner;
friend class TWin32Thread;
public:
typedef void *(*VoidRtnFunc_t)(void *);
typedef void (*VoidFunc_t)(void *);
enum EPriority {
kLowPriority,
kNormalPriority,
kHighPriority
};
enum EState {
kInvalidState,
kNewState,
kRunningState,
kTerminatedState,
kFinishedState,
kCancelingState,
kCanceledState,
kDeletingState
};
private:
TThread *fNext;
TThread *fPrev;
TThread **fHolder;
EPriority fPriority;
EState fState;
EState fStateComing;
Long_t fId;
Long_t fHandle;
Bool_t fDetached;
Bool_t fNamed;
VoidRtnFunc_t fFcnRetn;
VoidFunc_t fFcnVoid;
void *fThreadArg;
void *fClean;
void *fTsd[ROOT::kMaxThreadSlot];
char fComment[100];
static TThreadImp *fgThreadImp;
static char * volatile fgXAct;
static void ** volatile fgXArr;
static volatile Int_t fgXAnb;
static volatile Int_t fgXArt;
static Long_t fgMainId;
static TThread *fgMain;
static TMutex *fgMainMutex;
static TMutex *fgXActMutex;
static TCondition *fgXActCondi;
void Constructor();
void SetComment(const char *txt = 0)
{ fComment[0] = 0; if (txt) { strncpy(fComment, txt, 99); fComment[99] = 0; } }
void DoError(Int_t level, const char *location, const char *fmt, va_list va) const;
void ErrorHandler(int level, const char *location, const char *fmt, va_list ap) const;
static void Init();
static void *Function(void *ptr);
static Int_t XARequest(const char *xact, Int_t nb, void **ar, Int_t *iret);
static void AfterCancel(TThread *th);
TThread(const TThread&);
TThread& operator=(const TThread&);
public:
TThread(VoidRtnFunc_t fn, void *arg = 0, EPriority pri = kNormalPriority);
TThread(VoidFunc_t fn, void *arg = 0, EPriority pri = kNormalPriority);
TThread(const char *thname, VoidRtnFunc_t fn, void *arg = 0, EPriority pri = kNormalPriority);
TThread(const char *thname, VoidFunc_t fn, void *arg = 0, EPriority pri = kNormalPriority);
TThread(Long_t id = 0);
virtual ~TThread();
Int_t Kill();
Int_t Run(void *arg = 0);
void SetPriority(EPriority pri);
void Delete(Option_t *option="") { TObject::Delete(option); }
EPriority GetPriority() const { return fPriority; }
EState GetState() const { return fState; }
Long_t GetId() const { return fId; }
static void Ps();
static void ps() { Ps(); }
static void Initialize();
static Bool_t IsInitialized();
Long_t Join(void **ret = 0);
static Long_t Join(Long_t id, void **ret = 0);
static Int_t Exit(void *ret = 0);
static Int_t Exists();
static TThread *GetThread(Long_t id);
static TThread *GetThread(const char *name);
static Int_t Lock();
static Int_t TryLock();
static Int_t UnLock();
static TThread *Self();
static Long_t SelfId();
static Int_t Sleep(ULong_t secs, ULong_t nanos = 0);
static Int_t GetTime(ULong_t *absSec, ULong_t *absNanoSec);
static Int_t Delete(TThread *&th);
static void **Tsd(void *dflt, Int_t k);
static Int_t SetCancelOn();
static Int_t SetCancelOff();
static Int_t SetCancelAsynchronous();
static Int_t SetCancelDeferred();
static Int_t CancelPoint();
static Int_t Kill(Long_t id);
static Int_t Kill(const char *name);
static Int_t CleanUpPush(void *free, void *arg = 0);
static Int_t CleanUpPop(Int_t exe = 0);
static Int_t CleanUp();
static void Printf(const char *fmt, ...)
#if defined(__GNUC__) && !defined(__CINT__)
__attribute__((format(printf, 1, 2)))
#endif
;
static void XAction();
ClassDef(TThread,0)
};
class TThreadCleaner {
public:
TThreadCleaner() { }
~TThreadCleaner();
};
class TThreadTimer : public TTimer {
public:
TThreadTimer(Long_t ms = 10);
Bool_t Notify();
};
#endif