23#include "RConfigure.h"
71class TThreadTearDownGuard {
74 ~TThreadTearDownGuard() {
103 static void* JoinFunc(
void *p);
106 TJoinHelper(
TThread *th,
void **ret);
115TJoinHelper::TJoinHelper(
TThread *th,
void **ret)
118 fH =
new TThread(
"JoinHelper", JoinFunc,
this);
124TJoinHelper::~TJoinHelper()
136void* TJoinHelper::JoinFunc(
void *p)
138 TJoinHelper *jp = (TJoinHelper*)p;
140 jp->fRc = jp->fT->Join(jp->fRet);
155Int_t TJoinHelper::Join()
163 int r = fC->TimedWaitRelative(100);
175 if (
r == 0 ||
r == 1) {
290 Info(
"TThread::TThread",
"TThread attached to running thread");
321#if !defined (_REENTRANT) && !defined (WIN32)
323 ::Fatal(
"Init",
"_REENTRANT must be #define-d for TThread to work properly.");
373 SetComment(
"Constructor: MainInternalMutex Locking");
375 SetComment(
"Constructor: MainInternalMutex Locked");
392 Info(
"TThread::~TThread",
"thread deleted");
396 SetComment(
"Destructor: MainInternalMutex Locking");
398 SetComment(
"Destructor: MainInternalMutex Locked");
424 th->
Info(
"TThread::Delete",
"deleting thread");
496 TTHREAD_TLS(
TThread*) self = 0;
512 Error(
"Join",
"thread not running");
517 Error(
"Join",
"cannot join detached thread");
527 return helper.Join();
538 ::Error(
"TThread::Join",
"cannot find thread 0x%lx", jid);
542 return myTh->
Join(ret);
575 Info(
"TThread::Run",
"thread run requested");
590 Warning(
"TThread::Kill",
"thread is not running");
609 ::Warning(
"TThread::Kill(Long_t)",
"thread 0x%lx not found",
id);
625 ::Warning(
"TThread::Kill(const char*)",
"thread %s not found",
name);
730 th->
Info(
"TThread::AfterCancel",
"thread is canceled");
732 ::Error(
"TThread::AfterCancel",
"zero thread pointer passed");
760 if (absSec) *absSec = t.
GetSec();
810 th->
Info(
"TThread::Function",
"thread is running");
829 th->
Info(
"TThread::Function",
"thread has finished");
845 ::Info(
"TThread::Ps",
"no threads have been created");
856 printf(
" Thread State\n");
858 memset(cbuf,
' ',
sizeof(cbuf));
859 snprintf(cbuf,
sizeof(cbuf),
"%3d %s:0x%lx", num--,
l->GetName(),
l->fId);
864 printf(
"%30s", cbuf);
874 default: printf(
"Invalid ");
876 if (
l->fComment[0]) printf(
" // %s",
l->fComment);
923 va_start(ap,
va_(fmt));
925 Int_t buf_size = 2048;
929 buf =
new char[buf_size];
931 int n = vsnprintf(buf, buf_size,
va_(fmt), ap);
934 if (
n == -1 ||
n >= buf_size) {
943 arr[1] = (
void*) buf;
944 if (
XARequest(
"PRTF", 2, arr, 0))
return;
959 Int_t buf_size = 2048;
963 buf =
new char[buf_size];
965 int n = vsnprintf(buf, buf_size, fmt, ap);
968 if (
n == -1 ||
n >= buf_size) {
982 arr[1] = (
void*)
Long_t(level);
983 arr[2] = (
void*) location;
985 if (
XARequest(
"ERRO", 4, arr, 0))
return;
1006 loc =
new char[strlen(location) + strlen(
GetName()) + 32];
1007 sprintf(loc,
"%s %s:0x%lx", location,
GetName(),
fId);
1009 loc =
new char[strlen(
GetName()) + 32];
1038 th->
SetComment(
"XARequest: XActMutex Locking");
1040 th->
SetComment(
"XARequest: XActMutex Locked");
1055 if (condimp) condimp->
Wait();
1058 if (iret) *iret =
fgXArt;
1077 char const acts[] =
"PRTF CUPD CANV CDEL PDCD METH ERRO";
1078 enum { kPRTF = 0, kCUPD = 5, kCANV = 10, kCDEL = 15,
1079 kPDCD = 20, kMETH = 25, kERRO = 30 };
1080 int iact = strstr(acts,
fgXAct) - acts;
1086 printf(
"%s\n", (
const char*)
fgXArr[1]);
1093 const char *location = (
const char*)
fgXArr[2];
1094 char *mess = (
char*)
fgXArr[3];
1105 union CastFromFuncToVoidPtr_t {
1106 void (*fFuncPtr)(
void*);
1108 } castFromFuncToVoidPtr;
1109 castFromFuncToVoidPtr.fVoidPtr =
fgXArr[2];
1110 (*castFromFuncToVoidPtr.fFuncPtr)(
fgXArr[1]);
1120 gROOT->ProcessLine(cmd);
1129 gROOT->ProcessLine(cmd);
1138 gROOT->ProcessLine(cmd);
1149 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]);
1150 gROOT->ProcessLine(cmd);
1159 gROOT->ProcessLine(cmd);
1174 ::Error(
"TThread::XAction",
"wrong case");
1178 if (condimp) condimp->
Signal();
static RooMathCoreReg dummy
R__EXTERN TApplication * gApplication
ErrorHandlerFunc_t GetErrorHandler()
Returns the current error handler function.
void Error(const char *location, const char *msgfmt,...)
R__EXTERN Int_t gErrorAbortLevel
R__EXTERN TVirtualMutex * gInterpreterMutex
R__EXTERN TInterpreter * gCling
R__EXTERN TVirtualMutex * gROOTMutex
char * Form(const char *fmt,...)
typedef void((*Func_t)())
R__EXTERN TSystem * gSystem
R__EXTERN TThreadFactory * gThreadFactory
R__EXTERN void **(* gThreadTsd)(void *, Int_t)
static TMutex * gMainInternalMutex
static void ThreadInternalUnLock()
static void CINT_alloc_lock()
static TThreadTearDownGuard gTearDownGuard
static Bool_t fgIsTearDown(kFALSE)
static void ThreadInternalLock()
void ROOT_TThread_Initialize()
static void CINT_alloc_unlock()
R__EXTERN TVirtualMutex * gGlobalMutex
#define R__LOCKGUARD(mutex)
R__EXTERN Int_t(* gThreadXAR)(const char *xact, Int_t nb, void **ar, Int_t *iret)
TConditionImp * fConditionImp
TMutex * GetMutex() const
Get internally created mutex.
virtual void SetAllocunlockfunc(void(*)()) const
virtual void SetAlloclockfunc(void(*)()) const
static TInterpreter * Instance()
returns gInterpreter global
Method or function calling interface.
Int_t UnLock()
Unlock the mutex.
Int_t CleanUp()
Clean up of mutex.
Int_t Lock()
Lock the mutex.
Int_t TryLock()
Try to lock mutex.
The TNamed class is the base class for all named ROOT classes.
virtual const char * GetName() const
Returns name of object.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
virtual const char * GetError()
Return system error string.
~TThreadCleaner()
Call user clean up routines.
virtual TThreadImp * CreateThreadImp()=0
virtual Int_t Join(TThread *th, void **ret)=0
virtual Int_t SetCancelOff()=0
virtual Int_t Exit(void *ret)=0
virtual Int_t CleanUpPush(void **main, void *free, void *arg)=0
virtual Long_t SelfId()=0
virtual Int_t CancelPoint()=0
virtual Int_t SetCancelDeferred()=0
virtual Int_t Kill(TThread *th)=0
virtual Int_t CleanUpPop(void **main, Int_t exe)=0
virtual Int_t SetCancelAsynchronous()=0
virtual Int_t SetCancelOn()=0
virtual Int_t Run(TThread *th)=0
virtual Int_t CleanUp(void **main)=0
TThreadTimer(Long_t ms=kItimerResolution+10)
Create thread timer.
Bool_t Notify()
Periodically execute the TThread::XAxtion() method in the main thread.
static TThread * GetThread(Long_t id)
Static method to find a thread by id.
static Int_t CleanUpPop(Int_t exe=0)
Static method which pops thread cleanup method off stack.
static char *volatile fgXAct
static Int_t CancelPoint()
Static method to set a cancellation point.
static Int_t Sleep(ULong_t secs, ULong_t nanos=0)
Static method to sleep the calling thread.
static void **volatile fgXArr
static Int_t TryLock()
Static method to try to lock the main thread mutex.
void SetPriority(EPriority pri)
Set thread priority.
static Int_t Exists()
Static method to check if threads exist.
static void Ps()
Static method listing the existing threads.
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 TThreadImp * fgThreadImp
static Int_t UnLock()
Static method to unlock the main thread mutex.
Int_t Kill()
Kill this thread.
static TMutex * fgMainMutex
static volatile Int_t fgXAnb
static void XAction()
Static method called via the thread timer to execute in the main thread certain commands.
virtual ~TThread()
Cleanup the thread.
static Int_t SetCancelAsynchronous()
Static method to set the cancellation response type of the calling thread to asynchronous,...
static Int_t CleanUp()
Static method to cleanup the calling thread.
void ErrorHandler(int level, const char *location, const char *fmt, va_list ap) const
Thread specific error handler function.
static Int_t GetTime(ULong_t *absSec, ULong_t *absNanoSec)
Static method to get the current time.
static Long_t SelfId()
Static method returning the id for the current thread.
void Constructor()
Common thread constructor.
static Int_t SetCancelOn()
Static method to turn on thread cancellation.
static void ** Tsd(void *dflt, Int_t k)
Static method returning a pointer to thread specific data container of the calling thread.
void DoError(Int_t level, const char *location, const char *fmt, va_list va) const
Interface to ErrorHandler.
static Int_t CleanUpPush(void *free, void *arg=0)
Static method which pushes thread cleanup method on stack.
static volatile Int_t fgXArt
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.
Long_t Join(void **ret=0)
Join this thread.
static void * Function(void *ptr)
Static method which is called by the system thread function and which in turn calls the actual user f...
static void Printf(const char *fmt,...)
Static method providing a thread safe printf. Appends a newline.
static Int_t Lock()
Static method to lock the main thread mutex.
friend class TThreadTimer
static Int_t SetCancelOff()
Static method to turn off thread cancellation.
static void Init()
Initialize global state and variables once.
static Int_t SetCancelDeferred()
Static method to set the cancellation response type of the calling thread to deferred,...
static void AfterCancel(TThread *th)
Static method which is called after the thread has been canceled.
static TMutex * fgXActMutex
static Bool_t IsInitialized()
Return true, if the TThread objects have been initialize.
static TThread * Self()
Static method returning pointer to current thread.
static void Initialize()
Initialize the Thread package.
void SetComment(const char *txt=0)
static TCondition * fgXActCondi
void Delete(Option_t *option="")
Delete this object.
static Int_t Exit(void *ret=0)
Static method which terminates the execution of the calling thread.
Int_t Run(void *arg=0)
Start the thread.
The TTimeStamp encapsulates seconds and ns since EPOCH.
Handles synchronous and a-synchronous timer events.
void Reset()
Reset the timer.
This class implements a mutex interface.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
R__EXTERN TVirtualRWMutex * gCoreMutex
static constexpr double ms