Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TWin32Thread.cxx
Go to the documentation of this file.
1// @(#)root/thread:$Id$
2// Author: Bertrand Bellenot 20/10/2004
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, 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// TWin32Thread //
15// //
16// This class provides an interface to the win32 thread routines. //
17// //
18//////////////////////////////////////////////////////////////////////////
19
20#include "TWin32Thread.h"
21
22#include "TThread.h"
23
24#include <process.h>
25#include <cerrno>
26
27
28////////////////////////////////////////////////////////////////////////////////
29/// Win32 threads -- spawn new thread (like pthread_create).
30/// Win32 has a thread handle in addition to the thread ID.
31
33{
34 DWORD dwThreadId;
35 HANDLE hHandle = CreateThread(0, 0,
37 th, 0, (DWORD*)&dwThreadId);
38 if (affinity >= 0)
39 Warning("Run", "Affinity setting not yet implemented on Win32");
40 if (th->fDetached) {
42 th->fHandle = 0L;
43 } else
45
46 th->fId = dwThreadId;
47
48 return hHandle ? 0 : EINVAL;
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Wait for specified thread execution (if any) to complete
53/// (like pthread_join).
54
56{
57 DWORD R = WaitForSingleObject((HANDLE)th->fHandle, INFINITE);
58
59 if ( (R == WAIT_OBJECT_0) || (R == WAIT_ABANDONED) ) {
60 //::CloseHandle((HANDLE)th->fHandle);
61 return 0;
62 }
63 if ( R == WAIT_TIMEOUT )
64 return EAGAIN;
65 return EINVAL;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Exit the thread.
70
72{
73 ExitThread(0);
74 return 0;
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// This is a somewhat dangerous function; it's not
79/// suggested to Stop() threads a lot.
80
82{
83 if (TerminateThread((HANDLE)th->fHandle,0)) {
85 return 0;
86 }
87 return EINVAL;
88}
89
90////////////////////////////////////////////////////////////////////////////////
91
92Int_t TWin32Thread::CleanUpPush(void **main, void *free,void *arg)
93{
94 if (!free) fprintf(stderr, "CleanUpPush ***ERROR*** Routine=0\n");
95 new TWin32ThreadCleanUp(main,free,arg);
96 return 0;
97}
98
99////////////////////////////////////////////////////////////////////////////////
100
102{
103 if (!*main) return 1;
105 if (!l->fRoutine) fprintf(stderr,"CleanUpPop ***ERROR*** Routine=0\n");
106 if (exe && l->fRoutine) ((void (*)(void*))(l->fRoutine))(l->fArgument);
107 *main = l->fNext; delete l;
108 return 0;
109}
110
111////////////////////////////////////////////////////////////////////////////////
112
114{
115 fprintf(stderr," CleanUp %zx\n",(size_t)*main);
116 while(!CleanUpPop(main,1)) { }
117 return 0;
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Return the current thread's ID.
122
127
128////////////////////////////////////////////////////////////////////////////////
129
131{
132 if (gDebug)
133 Warning("SetCancelOff", "Not implemented on Win32");
134 return 0;
135}
136
137////////////////////////////////////////////////////////////////////////////////
138
140{
141 if (gDebug)
142 Warning("SetCancelOn", "Not implemented on Win32");
143 return 0;
144}
145
146////////////////////////////////////////////////////////////////////////////////
147
149{
150 if (gDebug)
151 Warning("SetCancelAsynchronous", "Not implemented on Win32");
152 return 0;
153}
154
155////////////////////////////////////////////////////////////////////////////////
156
158{
159 if (gDebug)
160 Warning("SetCancelDeferred", "Not implemented on Win32");
161 return 0;
162}
163
164////////////////////////////////////////////////////////////////////////////////
165
167{
168 if (gDebug)
169 Warning("CancelPoint", "Not implemented on Win32");
170 return 0;
171}
172
173// Clean Up section. PTHREAD implementations of cleanup after cancel are
174// too different and often too bad. Temporary I invent my own bicycle.
175// V.Perev.
176
177////////////////////////////////////////////////////////////////////////////////
178
180{
182 fRoutine = routine; fArgument = arg;
183 *main = this;
184}
int main()
Definition Prototype.cxx:12
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
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.
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
<div class="legacybox"><h2>Legacy Code</h2> TThread is a legacy interface: there will be no bug fixes...
Definition TThread.h:40
EState fState
Definition TThread.h:78
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
@ kCanceledState
Definition TThread.h:69
Longptr_t fHandle
Definition TThread.h:81
TWin32ThreadCleanUp(void **main, void *routine, void *arg)
TWin32ThreadCleanUp * fNext
Int_t SetCancelOff() override
Int_t CleanUpPop(void **main, Int_t exe) override
Int_t Exit(void *ret) override
Exit the thread.
Int_t SetCancelOn() override
Int_t SetCancelDeferred() override
Int_t CleanUp(void **main) override
Long_t SelfId() override
Return the current thread's ID.
Int_t SetCancelAsynchronous() override
Int_t CancelPoint() override
Int_t CleanUpPush(void **main, void *free, void *arg) override
Int_t Kill(TThread *th) override
This is a somewhat dangerous function; it's not suggested to Stop() threads a lot.
Int_t Join(TThread *th, void **ret) override
Wait for specified thread execution (if any) to complete (like pthread_join).
Int_t Run(TThread *th, const int affinity=-1) override
Win32 threads – spawn new thread (like pthread_create).
TLine l
Definition textangle.C:4