00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "TWin32Thread.h"
00021 #include <process.h>
00022 #include <errno.h>
00023
00024 ClassImp(TWin32Thread)
00025
00026
00027 Int_t TWin32Thread::Run(TThread *th)
00028 {
00029
00030
00031
00032 DWORD dwThreadId;
00033 HANDLE hHandle = CreateThread(0, 0,
00034 (LPTHREAD_START_ROUTINE)&TThread::Function,
00035 th, 0, (DWORD*)&dwThreadId);
00036 if (th->fDetached) {
00037 ::CloseHandle(hHandle);
00038 th->fHandle = 0L;
00039 } else
00040 th->fHandle = (Long_t)hHandle;
00041
00042 th->fId = dwThreadId;
00043
00044 return hHandle ? 0 : EINVAL;
00045 }
00046
00047
00048 Int_t TWin32Thread::Join(TThread *th, void **ret)
00049 {
00050
00051
00052
00053 DWORD R = WaitForSingleObject((HANDLE)th->fHandle, INFINITE);
00054
00055 if ( (R == WAIT_OBJECT_0) || (R == WAIT_ABANDONED) ) {
00056
00057 return 0;
00058 }
00059 if ( R == WAIT_TIMEOUT )
00060 return EAGAIN;
00061 return EINVAL;
00062 }
00063
00064
00065 Int_t TWin32Thread::Exit(void *ret)
00066 {
00067
00068
00069 ExitThread(0);
00070 return 0;
00071 }
00072
00073
00074 Int_t TWin32Thread::Kill(TThread *th)
00075 {
00076
00077
00078
00079 if (TerminateThread((HANDLE)th->fHandle,0)) {
00080 th->fState = TThread::kCanceledState;
00081 return 0;
00082 }
00083 return EINVAL;
00084 }
00085
00086
00087 Int_t TWin32Thread::CleanUpPush(void **main, void *free,void *arg)
00088 {
00089 if (!free) fprintf(stderr, "CleanUpPush ***ERROR*** Routine=0\n");
00090 new TWin32ThreadCleanUp(main,free,arg);
00091 return 0;
00092 }
00093
00094
00095 Int_t TWin32Thread::CleanUpPop(void **main,Int_t exe)
00096 {
00097 if (!*main) return 1;
00098 TWin32ThreadCleanUp *l = (TWin32ThreadCleanUp*)(*main);
00099 if (!l->fRoutine) fprintf(stderr,"CleanUpPop ***ERROR*** Routine=0\n");
00100 if (exe && l->fRoutine) ((void (*)(void*))(l->fRoutine))(l->fArgument);
00101 *main = l->fNext; delete l;
00102 return 0;
00103 }
00104
00105
00106 Int_t TWin32Thread::CleanUp(void **main)
00107 {
00108 fprintf(stderr," CleanUp %lx\n",(ULong_t)*main);
00109 while(!CleanUpPop(main,1)) { }
00110 return 0;
00111 }
00112
00113
00114 Long_t TWin32Thread::SelfId()
00115 {
00116
00117
00118 return (Long_t)::GetCurrentThreadId();
00119 }
00120
00121
00122 Int_t TWin32Thread::SetCancelOff()
00123 {
00124 if (gDebug)
00125 Warning("SetCancelOff", "Not implemented on Win32");
00126 return 0;
00127 }
00128
00129
00130 Int_t TWin32Thread::SetCancelOn()
00131 {
00132 if (gDebug)
00133 Warning("SetCancelOn", "Not implemented on Win32");
00134 return 0;
00135 }
00136
00137
00138 Int_t TWin32Thread::SetCancelAsynchronous()
00139 {
00140 if (gDebug)
00141 Warning("SetCancelAsynchronous", "Not implemented on Win32");
00142 return 0;
00143 }
00144
00145
00146 Int_t TWin32Thread::SetCancelDeferred()
00147 {
00148 if (gDebug)
00149 Warning("SetCancelDeferred", "Not implemented on Win32");
00150 return 0;
00151 }
00152
00153
00154 Int_t TWin32Thread::CancelPoint()
00155 {
00156 if (gDebug)
00157 Warning("CancelPoint", "Not implemented on Win32");
00158 return 0;
00159 }
00160
00161
00162
00163
00164
00165
00166 TWin32ThreadCleanUp::TWin32ThreadCleanUp(void **main, void *routine, void *arg)
00167 {
00168 fNext = (TWin32ThreadCleanUp*)*main;
00169 fRoutine = routine; fArgument = arg;
00170 *main = this;
00171 }