12 #ifndef _U_Thread_Posix_
13 #define _U_Thread_Posix_
27 req.tv_sec = ms / 1000;
28 req.tv_nsec = (ms - req.tv_sec * 1000) * 1000 * 1000;
29 nanosleep (&req, &rem);
39 req.tv_sec = us / 1000000;
40 req.tv_nsec = (us - req.tv_sec * 1000000) * 1000;
41 nanosleep (&req, &rem);
51 req.tv_sec = ns / 1000000000;
52 req.tv_nsec = (ns - req.tv_sec * 1000000000);
53 nanosleep (&req, &rem);
57 #define InvalidHandle 0
58 #define THREAD_HANDLE pthread_t
60 typedef void *( * pthread_fn )(
void * );
89 { pthread_testcancel(); }
93 {
return (
Handle)pthread_self(); }
101 const bool & CreateDetached =
false,
102 const unsigned int & StackSize = 0,
103 const bool & CancelEnable =
false,
104 const bool & CancelAsync =
false
109 pthread_attr_init(&attr);
111 if ( CreateDetached )
112 pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
115 pthread_attr_setstacksize(&attr,StackSize);
117 Instance I(Param,0,Function,CancelEnable,CancelAsync);
122 pthread_attr_destroy(&attr);
134 const bool & CreateDetached =
false,
135 const unsigned int & StackSize = 0,
136 const bool & CancelEnable =
false,
137 const bool & CancelAsync =
false
142 pthread_attr_init(&attr);
144 if ( CreateDetached )
145 pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
148 pthread_attr_setstacksize(&attr,StackSize);
155 pthread_attr_destroy(&attr);
165 {
return pthread_join(
H,0); }
169 {
return pthread_cancel(
H); }
173 {
return pthread_detach(
H); }
183 Thread_T Data(
I.Data);
189 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,
NULL);
192 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,
NULL);
194 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,
NULL);
198 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,
NULL);
203 I.Owner->ThreadMain(Data);
247 { pthread_testcancel(); }
251 {
return (
Handle)pthread_self(); }
258 const bool & CreateDetached =
false,
259 const unsigned int & StackSize = 0,
260 const bool & CancelEnable =
false,
261 const bool & CancelAsync =
false
266 pthread_attr_init(&attr);
268 if ( CreateDetached )
269 pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
272 pthread_attr_setstacksize(&attr,StackSize);
274 Instance
I(0,Function,CancelEnable,CancelAsync);
279 pthread_attr_destroy(&attr);
290 const bool & CreateDetached =
false,
291 const unsigned int & StackSize = 0,
292 const bool & CancelEnable =
false,
293 const bool & CancelAsync =
false
298 pthread_attr_init(&attr);
300 if ( CreateDetached )
301 pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
304 pthread_attr_setstacksize(&attr,StackSize);
306 Instance
I(
const_cast<UThreadC *
>(
this),0,CancelEnable,CancelAsync);
311 pthread_attr_destroy(&attr);
321 unsigned long & ThreadId,
323 const bool & CreateDetached =
false,
324 const unsigned int & StackSize = 0,
325 const bool & CancelEnable =
false,
326 const bool & CancelAsync =
false
331 pthread_attr_init(&attr);
333 if ( CreateDetached )
334 pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
337 pthread_attr_setstacksize(&attr,StackSize);
339 Instance
I(
const_cast<UThreadC *
>(
this),0,CancelEnable,CancelAsync);
344 ThreadId = (
unsigned long)*
H;
346 pthread_attr_destroy(&attr);
355 {
return pthread_join(
H,0); }
359 {
return pthread_cancel(
H); }
363 {
return pthread_detach(
H); }
378 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,
NULL);
381 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,
NULL);
383 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,
NULL);
387 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,
NULL);
392 I.Owner->ThreadMain();
411 #endif // !_U_Thread_Posix_