Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPosixThread.cxx
Go to the documentation of this file.
1// @(#)root/thread:$Id$
2// Author: Fons Rademakers 02/07/97
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TPosixThread //
15// //
16// This class provides an interface to the posix thread routines. //
17// //
18//////////////////////////////////////////////////////////////////////////
19
20#include "TPosixThread.h"
21
22#include "TThread.h"
23
24
25
26////////////////////////////////////////////////////////////////////////////////
27/// Create a pthread. Returns 0 on success, otherwise an error number will
28/// be returned.
29
31{
32 int det;
33 pthread_t id;
35
37
38 if (affinity >= 0) {
39 #ifdef __GLIBC__
44 #else
45 Warning("Run", "Affinity setting not yet implemented on this platform");
46 #endif
47 }
48
49 // Set detach state
51
53
54 // See e.g. https://developer.apple.com/library/mac/#qa/qa1419/_index.html
55 // MacOS has only 512k of stack per thread; Linux has 2MB.
56 const size_t requiredStackSize = 1024*1024*2;
57 size_t stackSize = 0;
61 }
62 int ierr = pthread_create(&id, attr, &TThread::Function, th);
63 if (!ierr) th->fId = (Long_t) id;
64
66 delete attr;
67
68 return ierr;
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Join suspends the execution of the calling thread until the
73/// thread identified by th terminates, either by calling pthread_exit
74/// or by being cancelled. Returns 0 on success, otherwise an error number will
75/// be returned.
76
78{
79 return pthread_join((pthread_t) th->fId, ret);
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Terminates the execution of the calling thread. Return 0.
84
86{
88 return 0;
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Cancellation is the mechanism by which a thread can terminate the
93/// execution of another thread. Returns 0 on success, otherwise an error
94/// number will be returned.
95
97{
98 return pthread_cancel((pthread_t) th->fId);
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Turn off the cancellation state of the calling thread. Returns 0 on
103/// success, otherwise an error number will be returned.
104
109
110////////////////////////////////////////////////////////////////////////////////
111/// Turn on the cancellation state of the calling thread. Returns 0 on
112/// success, otherwise an error number will be returned.
113
118
119////////////////////////////////////////////////////////////////////////////////
120/// Set the cancellation response type of the calling thread to
121/// asynchronous, i.e. cancel as soon as the cancellation request
122/// is received.
123
128
129////////////////////////////////////////////////////////////////////////////////
130/// Set the cancellation response type of the calling thread to
131/// deferred, i.e. cancel only at next cancellation point.
132/// Returns 0 on success, otherwise an error number will be returned.
133
138
139////////////////////////////////////////////////////////////////////////////////
140/// Introduce an explicit cancellation point. Returns 0.
141
151
152////////////////////////////////////////////////////////////////////////////////
153/// Add thread cleanup function.
154
155Int_t TPosixThread::CleanUpPush(void **main, void *free, void *arg)
156{
157 // pthread_cleanup_push(free, arg);
158 if (!free) Error("CleanUpPush", "cleanup rountine = 0");
159 new TPosixThreadCleanUp(main, free, arg);
160 return 0;
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// Pop thread cleanup function from stack.
165
167{
168 // pthread_cleanup_pop(exe); // happy pthread future
169
170 if (!main || !*main) return 1;
172 if (!l->fRoutine) Error("CleanUpPop", "cleanup routine = 0");
173 if (exe && l->fRoutine) ((void (*)(void*))(l->fRoutine))(l->fArgument);
174 *main = l->fNext; delete l;
175 return 0;
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Default thread cleanup routine.
180
182{
183 if (gDebug > 0)
184 Info("Cleanup", "cleanup 0x%lx", (Long_t)*main);
185 while (!CleanUpPop(main, 1)) { }
186 return 0;
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Return the thread identifier for the calling thread.
191
193{
194 return (Long_t) pthread_self();
195}
196
197// Clean Up section. PTHREAD implementations of cleanup after cancel are
198// too different and often too bad. Temporary I invent my own bicycle.
199// V.Perev.
200
201////////////////////////////////////////////////////////////////////////////////
202///cleanup function
203
205{
207 fRoutine = routine; fArgument = arg;
208 *main = this;
209}
int main()
Definition Prototype.cxx:12
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
TPosixThreadCleanUp(void **main, void *routine, void *arg)
cleanup function
TPosixThreadCleanUp * fNext
Int_t SetCancelOn() override
Turn on the cancellation state of the calling thread.
Int_t SetCancelOff() override
Turn off the cancellation state of the calling thread.
Int_t SetCancelAsynchronous() override
Set the cancellation response type of the calling thread to asynchronous, i.e.
Int_t CleanUpPop(void **main, Int_t exe) override
Pop thread cleanup function from stack.
Int_t Kill(TThread *th) override
Cancellation is the mechanism by which a thread can terminate the execution of another thread.
Int_t CleanUpPush(void **main, void *free, void *arg) override
Add thread cleanup function.
Int_t CleanUp(void **main) override
Default thread cleanup routine.
Int_t Exit(void *ret) override
Terminates the execution of the calling thread. Return 0.
Int_t SetCancelDeferred() override
Set the cancellation response type of the calling thread to deferred, i.e.
Int_t Run(TThread *th, const int affinity=-1) override
Create a pthread.
Long_t SelfId() override
Return the thread identifier for the calling thread.
Int_t Join(TThread *th, void **ret) override
Join suspends the execution of the calling thread until the thread identified by th terminates,...
Int_t CancelPoint() override
Introduce an explicit cancellation point. Returns 0.
<div class="legacybox"><h2>Legacy Code</h2> TThread is a legacy interface: there will be no bug fixes...
Definition TThread.h:40
Bool_t fDetached
Definition TThread.h:82
Long_t fId
Definition TThread.h:80
static void * Function(void *ptr)
Static method which is called by the system thread function and which in turn calls the actual user f...
Definition TThread.cxx:800
TLine l
Definition textangle.C:4