23 #include "RConfigure.h" 69 class TThreadTearDownGuard {
72 ~TThreadTearDownGuard() {
83 TThread::fgThreadImp = 0;
101 static void* JoinFunc(
void *p);
104 TJoinHelper(
TThread *th,
void **ret);
113 TJoinHelper::TJoinHelper(
TThread *th,
void **ret)
116 fH =
new TThread(
"JoinHelper", JoinFunc,
this);
122 TJoinHelper::~TJoinHelper()
134 void* TJoinHelper::JoinFunc(
void *p)
136 TJoinHelper *jp = (TJoinHelper*)p;
138 jp->fRc = jp->fT->Join(jp->fRet);
153 Int_t TJoinHelper::Join()
161 int r = fC->TimedWaitRelative(100);
173 if (r == 0 || r == 1) {
188 TThread::fgThreadImp->
Join(fH, 0);
288 Info(
"TThread::TThread",
"TThread attached to running thread");
319 #if !defined (_REENTRANT) && !defined (WIN32) 321 ::Fatal(
"Init",
"_REENTRANT must be #define-d for TThread to work properly.");
363 SetComment(
"Constructor: MainInternalMutex Locking");
365 SetComment(
"Constructor: MainInternalMutex Locked");
382 Info(
"TThread::~TThread",
"thread deleted");
386 SetComment(
"Destructor: MainInternalMutex Locking");
388 SetComment(
"Destructor: MainInternalMutex Locked");
414 th->
Info(
"TThread::Delete",
"deleting thread");
486 TTHREAD_TLS(
TThread*)
self = 0;
502 Error(
"Join",
"thread not running");
507 Error(
"Join",
"cannot join detached thread");
517 return helper.Join();
528 ::Error(
"TThread::Join",
"cannot find thread 0x%lx", jid);
532 return myTh->
Join(ret);
565 Info(
"TThread::Run",
"thread run requested");
580 Warning(
"TThread::Kill",
"thread is not running");
599 ::Warning(
"TThread::Kill(Long_t)",
"thread 0x%lx not found",
id);
615 ::Warning(
"TThread::Kill(const char*)",
"thread %s not found", name);
720 th->
Info(
"TThread::AfterCancel",
"thread is canceled");
722 ::Error(
"TThread::AfterCancel",
"zero thread pointer passed");
750 if (absSec) *absSec = t.
GetSec();
800 th->
Info(
"TThread::Function",
"thread is running");
819 th->
Info(
"TThread::Function",
"thread has finished");
835 ::Info(
"TThread::Ps",
"no threads have been created");
846 printf(
" Thread State\n");
848 memset(cbuf,
' ',
sizeof(cbuf));
854 printf(
"%30s", cbuf);
864 default: printf(
"Invalid ");
913 va_start(ap,
va_(fmt));
915 Int_t buf_size = 2048;
919 buf =
new char[buf_size];
921 int n = vsnprintf(buf, buf_size,
va_(fmt), ap);
924 if (n == -1 || n >= buf_size) {
933 arr[1] = (
void*) buf;
934 if (
XARequest(
"PRTF", 2, arr, 0))
return;
949 Int_t buf_size = 2048;
953 buf =
new char[buf_size];
955 int n = vsnprintf(buf, buf_size, fmt, ap);
958 if (n == -1 || n >= buf_size) {
972 arr[1] = (
void*)
Long_t(level);
973 arr[2] = (
void*) location;
975 if (
XARequest(
"ERRO", 4, arr, 0))
return;
996 loc =
new char[strlen(location) + strlen(
GetName()) + 32];
997 sprintf(loc,
"%s %s:0x%lx", location,
GetName(),
fId);
999 loc =
new char[strlen(
GetName()) + 32];
1028 th->
SetComment(
"XARequest: XActMutex Locking");
1030 th->
SetComment(
"XARequest: XActMutex Locked");
1045 if (condimp) condimp->
Wait();
1048 if (iret) *iret =
fgXArt;
1067 char const acts[] =
"PRTF CUPD CANV CDEL PDCD METH ERRO";
1068 enum { kPRTF = 0, kCUPD = 5, kCANV = 10, kCDEL = 15,
1069 kPDCD = 20, kMETH = 25, kERRO = 30 };
1070 int iact = strstr(acts,
fgXAct) - acts;
1076 printf(
"%s\n", (
const char*)
fgXArr[1]);
1082 int level = (int)
Long_t(fgXArr[1]);
1083 const char *location = (
const char*)fgXArr[2];
1084 char *mess = (
char*)fgXArr[3];
1095 union CastFromFuncToVoidPtr_t {
1096 void (*fFuncPtr)(
void*);
1098 } castFromFuncToVoidPtr;
1099 castFromFuncToVoidPtr.fVoidPtr = fgXArr[2];
1100 (*castFromFuncToVoidPtr.fFuncPtr)(fgXArr[1]);
1109 cmd =
Form(
"((TCanvas *)0x%lx)->Constructor();",(
Long_t)fgXArr[1]);
1110 gROOT->ProcessLine(cmd);
1118 cmd =
Form(
"((TCanvas *)0x%lx)->Constructor((char*)0x%lx,(char*)0x%lx,*((Int_t*)(0x%lx)));",(
Long_t)fgXArr[1],(
Long_t)fgXArr[2],(
Long_t)fgXArr[3],(
Long_t)fgXArr[4]);
1119 gROOT->ProcessLine(cmd);
1127 cmd =
Form(
"((TCanvas *)0x%lx)->Constructor((char*)0x%lx,(char*)0x%lx,*((Int_t*)(0x%lx)),*((Int_t*)(0x%lx)));",(
Long_t)fgXArr[1],(
Long_t)fgXArr[2],(
Long_t)fgXArr[3],(
Long_t)fgXArr[4],(
Long_t)fgXArr[5]);
1128 gROOT->ProcessLine(cmd);
1139 cmd =
Form(
"((TCanvas *)0x%lx)->Constructor((char*)0x%lx,(char*)0x%lx,*((Int_t*)(0x%lx)),*((Int_t*)(0x%lx)),*((Int_t*)(0x%lx)),*((Int_t*)(0x%lx)));",(
Long_t)fgXArr[1],(
Long_t)fgXArr[2],(
Long_t)fgXArr[3],(
Long_t)fgXArr[4],(
Long_t)fgXArr[5],(
Long_t)fgXArr[6],(
Long_t)fgXArr[7]);
1140 gROOT->ProcessLine(cmd);
1148 cmd =
Form(
"((TCanvas *)0x%lx)->Destructor();",(
Long_t)fgXArr[1]);
1149 gROOT->ProcessLine(cmd);
1154 *((
Int_t*)(fgXArr[3])),
1157 *((
Int_t*)(fgXArr[6])));
1160 ((
TMethodCall *) fgXArr[1])->Execute((
void*)(fgXArr[2]),(
const char*)(fgXArr[3]));
1164 ::Error(
"TThread::XAction",
"wrong case");
1168 if (condimp) condimp->
Signal();
static void ** GetTls(Int_t k)
Static method that initializes the TLS array of a thread and returns the reference to a given positio...
static void AfterCancel(TThread *th)
Static method which is called after the thread has been canceled.
virtual const char * GetName() const
Returns name of object.
static Int_t SetCancelDeferred()
Static method to set the cancellation response type of the calling thread to deferred, i.e.
static void ThreadInternalUnLock()
void *(* VoidRtnFunc_t)(void *)
static Bool_t IsInitialized()
Return true, if the TThread objects have been initialize.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
virtual TVirtualMutex * Factory(Bool_t=kFALSE)=0
static void XAction()
Static method called via the thread timer to execute in the main thread certain commands.
virtual Int_t Join(TThread *th, void **ret)=0
static TCondition * fgXActCondi
void Reset()
Reset the timer.
friend class TThreadTimer
static void Initialize()
Initialize the Thread package.
RooArgList L(const RooAbsArg &v1)
R__EXTERN TVirtualMutex * gInterpreterMutex
void Constructor()
Common thread constructor.
static Int_t SetCancelOff()
Static method to turn off thread cancellation.
virtual Long_t SelfId()=0
This class implements a mutex interface.
static void Printf(const char *fmt,...)
Static method providing a thread safe printf. Appends a newline.
R__EXTERN Int_t gErrorAbortLevel
static Int_t SetCancelOn()
Static method to turn on thread cancellation.
static TThreadImp * fgThreadImp
R__EXTERN TVirtualMutex * gROOTMutex
R__EXTERN TThreadFactory * gThreadFactory
static Int_t TryLock()
Static method to try to lock the main thread mutex.
R__EXTERN TApplication * gApplication
virtual Int_t CleanUpPush(void **main, void *free, void *arg)=0
R__EXTERN void **(* gThreadTsd)(void *, Int_t)
Int_t UnLock()
Unlock the mutex.
virtual TThreadImp * CreateThreadImp()=0
static Int_t CleanUpPop(Int_t exe=0)
Static method which pops thread cleanup method off stack.
static volatile Int_t fgXArt
virtual Int_t CleanUp(void **main)=0
static Int_t SetCancelAsynchronous()
Static method to set the cancellation response type of the calling thread to asynchronous, i.e.
static void CINT_alloc_unlock()
void SetComment(const char *txt=0)
R__EXTERN Int_t(* gThreadXAR)(const char *xact, Int_t nb, void **ar, Int_t *iret)
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
The TNamed class is the base class for all named ROOT classes.
~TThreadCleaner()
Call user clean up routines.
static Int_t XARequest(const char *xact, Int_t nb, void **ar, Int_t *iret)
Static method used to allow commands to be executed by the main thread.
virtual Int_t SetCancelDeferred()=0
static Long_t SelfId()
Static method returning the id for the current thread.
Method or function calling interface.
Int_t Run(void *arg=0)
Start the thread.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
void Error(const char *location, const char *msgfmt,...)
R__EXTERN TVirtualMutex * gGlobalMutex
virtual ~TThread()
Cleanup the thread.
static TThread * GetThread(Long_t id)
Static method to find a thread by id.
virtual Int_t SetCancelOff()=0
static TMutex * fgMainMutex
static Int_t Exists()
Static method to check if threads exist.
R__EXTERN TSystem * gSystem
static void Init()
Initialize global state and variables once.
TConditionImp * fConditionImp
TMutex * GetMutex() const
Get internally created mutex.
static char *volatile fgXAct
void DoError(Int_t level, const char *location, const char *fmt, va_list va) const
Interface to ErrorHandler.
virtual Int_t Run(TThread *th)=0
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * Form(const char *fmt,...)
Handles synchronous and a-synchronous timer events.
static Int_t CleanUpPush(void *free, void *arg=0)
Static method which pushes thread cleanup method on stack.
static Int_t CancelPoint()
Static method to set a cancellation point.
Long_t Join(void **ret=0)
Join this thread.
virtual Int_t SetCancelAsynchronous()=0
Int_t Kill()
Kill this thread.
Int_t CleanUp()
Clean up of mutex.
static Int_t Lock()
Static method to lock the main thread mutex.
static TInterpreter * Instance()
returns gInterpreter global
Int_t TryLock()
Try to lock mutex.
static void Ps()
Static method listing the existing threads.
static TMutex * fgXActMutex
Bool_t Notify()
Periodically execute the TThread::XAxtion() method in the main thread.
static void **volatile fgXArr
static Bool_t fgIsTearDown(kFALSE)
static Int_t CleanUp()
Static method to cleanup the calling thread.
virtual Int_t SetCancelOn()=0
static void ** Tsd(void *dflt, Int_t k)
Static method returning a pointer to thread specific data container of the calling thread...
static Int_t UnLock()
Static method to unlock the main thread mutex.
virtual void SetAlloclockfunc(void(*)()) const
static TThread * Self()
Static method returning pointer to current thread.
TThreadTimer(Long_t ms=kItimerResolution+10)
Create thread timer.
The TTimeStamp encapsulates seconds and ns since EPOCH.
void SetPriority(EPriority pri)
Set thread priority.
static void CINT_alloc_lock()
static RooMathCoreReg dummy
virtual Int_t Exit(void *ret)=0
Int_t Lock()
Lock the mutex.
#define R__LOCKGUARD(mutex)
virtual Int_t CancelPoint()=0
static Int_t GetTime(ULong_t *absSec, ULong_t *absNanoSec)
Static method to get the current time.
virtual Int_t Kill(TThread *th)=0
void ROOT_TThread_Initialize()
typedef void((*Func_t)())
static Int_t Exit(void *ret=0)
Static method which terminates the execution of the calling thread.
ErrorHandlerFunc_t GetErrorHandler()
Returns the current error handler function.
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
static TThreadTearDownGuard gTearDownGuard
virtual void SetAllocunlockfunc(void(*)()) const
void(* VoidFunc_t)(void *)
static TMutex * gMainInternalMutex
virtual Int_t CleanUpPop(void **main, Int_t exe)=0
static Int_t Sleep(ULong_t secs, ULong_t nanos=0)
Static method to sleep the calling thread.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
R__EXTERN TInterpreter * gCling
static void ThreadInternalLock()
virtual const char * GetError()
Return system error string.
void ErrorHandler(int level, const char *location, const char *fmt, va_list ap) const
Thread specific error handler function.
static void * Function(void *ptr)
Static method which is called by the system thread function and which in turn calls the actual user f...
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
static volatile Int_t fgXAnb
void Delete(Option_t *option="")
Delete this object.