Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
thread.h
Go to the documentation of this file.
1
2
24#if defined (_WIN32)
25
26// definitions of Win32 POSIX compatibility layer functions
27
28#include <windows.h>
29
30extern "C" {
31
32struct pthread_attr_t;
33
34struct pthread_t
35{
36 long id;
37 void* handle;
38};
39
40int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
41 void *(*start_routine)(void*), void *arg)
42{
43 int result = 0;
44
45 pthread_t tmpid;
46
47 if (0 == thread)
48 thread = &tmpid;
49
50 DWORD nid;
51
52 const HANDLE hthread = CreateThread (0, 0,
53 (LPTHREAD_START_ROUTINE)start_routine,
54 arg, 0, &nid);
55
56 if (INVALID_HANDLE_VALUE == hthread) {
57 thread->id = -1;
58 thread->handle = 0;
59 result = -1;
60 }
61 else {
62 thread->id = nid;
63 thread->handle = hthread;
64 }
65
66 return result;
67}
68
69int pthread_join(pthread_t thread, void **value_ptr)
70{
71 int result = 0;
72
73 const DWORD retcode = WaitForSingleObject (thread.handle, INFINITE);
74
75 if (WAIT_OBJECT_0 == retcode) {
76 if (value_ptr) {
77 DWORD exit_code;
78
79 if (GetExitCodeThread (thread.handle, &exit_code))
80 *value_ptr = (void*)exit_code;
81 else
82 result = -1;
83 }
84 }
85 else
86 result = -1;
87
88 return result;
89}
90
91} // extern "C"
92
93# define set_concurrency(ignore) 0
94#else // if !defined (_WIN32)
95# include <pthread.h>
96
97# if defined (__sun) && defined (__SVR4)
98 // use the Solaris threads API in case this is Solaris 2.6
99 // where the POSIX pthread_setconcurrency() API is missing
100# include <thread.h>
101# define set_concurrency(n) thr_setconcurrency (n)
102# else
103# define set_concurrency(n) pthread_setconcurrency (n)
104# endif // __sun && __SVR4
105#endif // _WIN32
volatile int result
int arg
Definition locale.cpp:2806