Revert "[Tizen] Disable indicator"
[platform/core/uifw/dali-adaptor.git] / dali-windows-backend / ExInclude / pthread.h
1 /* This is an implementation of the threads API of POSIX 1003.1-2001.\r
2 *\r
3 * --------------------------------------------------------------------------\r
4 *\r
5 *      Pthreads-win32 - POSIX Threads Library for Win32\r
6 *      Copyright(C) 1998 John E. Bossom\r
7 *      Copyright(C) 1999,2005 Pthreads-win32 contributors\r
8 *\r
9 *      Contact Email: rpj@callisto.canberra.edu.au\r
10 *\r
11 *      The current list of contributors is contained\r
12 *      in the file CONTRIBUTORS included with the source\r
13 *      code distribution. The list can also be seen at the\r
14 *      following World Wide Web location:\r
15 *      http://sources.redhat.com/pthreads-win32/contributors.html\r
16 *\r
17 *      This library is free software; you can redistribute it and/or\r
18 *      modify it under the terms of the GNU Lesser General Public\r
19 *      License as published by the Free Software Foundation; either\r
20 *      version 2 of the License, or (at your option) any later version.\r
21 *\r
22 *      This library is distributed in the hope that it will be useful,\r
23 *      but WITHOUT ANY WARRANTY; without even the implied warranty of\r
24 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
25 *      Lesser General Public License for more details.\r
26 *\r
27 *      You should have received a copy of the GNU Lesser General Public\r
28 *      License along with this library in the file COPYING.LIB;\r
29 *      if not, write to the Free Software Foundation, Inc.,\r
30 *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\r
31 */\r
32 \r
33 #if !defined( PTHREAD_H )\r
34 #define PTHREAD_H\r
35 \r
36 /*\r
37 * See the README file for an explanation of the pthreads-win32 version\r
38 * numbering scheme and how the DLL is named etc.\r
39 */\r
40 #define PTW32_VERSION 2,8,0,0\r
41 #define PTW32_VERSION_STRING "2, 8, 0, 0\0"\r
42 \r
43 /* There are three implementations of cancel cleanup.\r
44 * Note that pthread.h is included in both application\r
45 * compilation units and also internally for the library.\r
46 * The code here and within the library aims to work\r
47 * for all reasonable combinations of environments.\r
48 *\r
49 * The three implementations are:\r
50 *\r
51 *   WIN32 SEH\r
52 *   C\r
53 *   C++\r
54 *\r
55 * Please note that exiting a push/pop block via\r
56 * "return", "exit", "break", or "continue" will\r
57 * lead to different behaviour amongst applications\r
58 * depending upon whether the library was built\r
59 * using SEH, C++, or C. For example, a library built\r
60 * with SEH will call the cleanup routine, while both\r
61 * C++ and C built versions will not.\r
62 */\r
63 \r
64 /*\r
65 * Define defaults for cleanup code.\r
66 * Note: Unless the build explicitly defines one of the following, then\r
67 * we default to standard C style cleanup. This style uses setjmp/longjmp\r
68 * in the cancelation and thread exit implementations and therefore won't\r
69 * do stack unwinding if linked to applications that have it (e.g.\r
70 * C++ apps). This is currently consistent with most/all commercial Unix\r
71 * POSIX threads implementations.\r
72 */\r
73 #if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C )\r
74 # define __CLEANUP_C\r
75 #endif\r
76 \r
77 #if defined( __CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined(PTW32_RC_MSC))\r
78 #error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler.\r
79 #endif\r
80 \r
81 /*\r
82 * Stop here if we are being included by the resource compiler.\r
83 */\r
84 #ifndef RC_INVOKED\r
85 \r
86 #undef PTW32_LEVEL\r
87 \r
88 #if defined(_POSIX_SOURCE)\r
89 #define PTW32_LEVEL 0\r
90 /* Early POSIX */\r
91 #endif\r
92 \r
93 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309\r
94 #undef PTW32_LEVEL\r
95 #define PTW32_LEVEL 1\r
96 /* Include 1b, 1c and 1d */\r
97 #endif\r
98 \r
99 #if defined(INCLUDE_NP)\r
100 #undef PTW32_LEVEL\r
101 #define PTW32_LEVEL 2\r
102 /* Include Non-Portable extensions */\r
103 #endif\r
104 \r
105 #define PTW32_LEVEL_MAX 3\r
106 \r
107 #if !defined(PTW32_LEVEL)\r
108 #define PTW32_LEVEL PTW32_LEVEL_MAX\r
109 /* Include everything */\r
110 #endif\r
111 \r
112 #ifdef _UWIN\r
113 #   define HAVE_STRUCT_TIMESPEC 1\r
114 #   define HAVE_SIGNAL_H        1\r
115 #   undef HAVE_CONFIG_H\r
116 #   pragma comment(lib, "pthread")\r
117 #endif\r
118 \r
119 /*\r
120 * -------------------------------------------------------------\r
121 *\r
122 *\r
123 * Module: pthread.h\r
124 *\r
125 * Purpose:\r
126 *      Provides an implementation of PThreads based upon the\r
127 *      standard:\r
128 *\r
129 *              POSIX 1003.1-2001\r
130 *  and\r
131 *    The Single Unix Specification version 3\r
132 *\r
133 *    (these two are equivalent)\r
134 *\r
135 *      in order to enhance code portability between Windows,\r
136 *  various commercial Unix implementations, and Linux.\r
137 *\r
138 *      See the ANNOUNCE file for a full list of conforming\r
139 *      routines and defined constants, and a list of missing\r
140 *      routines and constants not defined in this implementation.\r
141 *\r
142 * Authors:\r
143 *      There have been many contributors to this library.\r
144 *      The initial implementation was contributed by\r
145 *      John Bossom, and several others have provided major\r
146 *      sections or revisions of parts of the implementation.\r
147 *      Often significant effort has been contributed to\r
148 *      find and fix important bugs and other problems to\r
149 *      improve the reliability of the library, which sometimes\r
150 *      is not reflected in the amount of code which changed as\r
151 *      result.\r
152 *      As much as possible, the contributors are acknowledged\r
153 *      in the ChangeLog file in the source code distribution\r
154 *      where their changes are noted in detail.\r
155 *\r
156 *      Contributors are listed in the CONTRIBUTORS file.\r
157 *\r
158 *      As usual, all bouquets go to the contributors, and all\r
159 *      brickbats go to the project maintainer.\r
160 *\r
161 * Maintainer:\r
162 *      The code base for this project is coordinated and\r
163 *      eventually pre-tested, packaged, and made available by\r
164 *\r
165 *              Ross Johnson <rpj@callisto.canberra.edu.au>\r
166 *\r
167 * QA Testers:\r
168 *      Ultimately, the library is tested in the real world by\r
169 *      a host of competent and demanding scientists and\r
170 *      engineers who report bugs and/or provide solutions\r
171 *      which are then fixed or incorporated into subsequent\r
172 *      versions of the library. Each time a bug is fixed, a\r
173 *      test case is written to prove the fix and ensure\r
174 *      that later changes to the code don't reintroduce the\r
175 *      same error. The number of test cases is slowly growing\r
176 *      and therefore so is the code reliability.\r
177 *\r
178 * Compliance:\r
179 *      See the file ANNOUNCE for the list of implemented\r
180 *      and not-implemented routines and defined options.\r
181 *      Of course, these are all defined is this file as well.\r
182 *\r
183 * Web site:\r
184 *      The source code and other information about this library\r
185 *      are available from\r
186 *\r
187 *              http://sources.redhat.com/pthreads-win32/\r
188 *\r
189 * -------------------------------------------------------------\r
190 */\r
191 \r
192 /* Try to avoid including windows.h */\r
193 #if defined(__MINGW32__) && defined(__cplusplus)\r
194 #define PTW32_INCLUDE_WINDOWS_H\r
195 #endif\r
196 \r
197 #ifdef PTW32_INCLUDE_WINDOWS_H\r
198 #include <windows.h>\r
199 #endif\r
200 \r
201 #if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__)\r
202 /*\r
203 * VC++6.0 or early compiler's header has no DWORD_PTR type.\r
204 */\r
205 typedef unsigned long DWORD_PTR;\r
206 #endif\r
207 /*\r
208 * -----------------\r
209 * autoconf switches\r
210 * -----------------\r
211 */\r
212 \r
213 #if HAVE_CONFIG_H\r
214 #include "config.h"\r
215 #endif /* HAVE_CONFIG_H */\r
216 \r
217 #ifndef NEED_FTIME\r
218 #include <time.h>\r
219 #else /* NEED_FTIME */\r
220 /* use native WIN32 time API */\r
221 #endif /* NEED_FTIME */\r
222 \r
223 #if HAVE_SIGNAL_H\r
224 #include <signal.h>\r
225 #endif /* HAVE_SIGNAL_H */\r
226 \r
227 #include <setjmp.h>\r
228 #include <limits.h>\r
229 \r
230 /*\r
231 * Boolean values to make us independent of system includes.\r
232 */\r
233 enum {\r
234         PTW32_FALSE = 0,\r
235         PTW32_TRUE = (!PTW32_FALSE)\r
236 };\r
237 \r
238 /*\r
239 * This is a duplicate of what is in the autoconf config.h,\r
240 * which is only used when building the pthread-win32 libraries.\r
241 */\r
242 \r
243 #ifndef PTW32_CONFIG_H\r
244 #  if defined(WINCE)\r
245 #    define NEED_ERRNO\r
246 #    define NEED_SEM\r
247 #  endif\r
248 #  if defined(_UWIN) || defined(__MINGW32__)\r
249 #    define HAVE_MODE_T\r
250 #  endif\r
251 #endif\r
252 \r
253 /*\r
254 *\r
255 */\r
256 \r
257 #if PTW32_LEVEL >= PTW32_LEVEL_MAX\r
258 #ifdef NEED_ERRNO\r
259 #include "need_errno.h"\r
260 #else\r
261 #include <errno.h>\r
262 #endif\r
263 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */\r
264 \r
265 /*\r
266 * Several systems don't define some error numbers.\r
267 */\r
268 #ifndef ENOTSUP\r
269 #  define ENOTSUP 48   /* This is the value in Solaris. */\r
270 #endif\r
271 \r
272 #ifndef ETIMEDOUT\r
273 #  define ETIMEDOUT 10060     /* This is the value in winsock.h. */\r
274 #endif\r
275 \r
276 #ifndef ENOSYS\r
277 #  define ENOSYS 140     /* Semi-arbitrary value */\r
278 #endif\r
279 \r
280 #ifndef EDEADLK\r
281 #  ifdef EDEADLOCK\r
282 #    define EDEADLK EDEADLOCK\r
283 #  else\r
284 #    define EDEADLK 36     /* This is the value in MSVC. */\r
285 #  endif\r
286 #endif\r
287 \r
288 #include <sched.h>\r
289 \r
290 /*\r
291 * To avoid including windows.h we define only those things that we\r
292 * actually need from it.\r
293 */\r
294 #ifndef PTW32_INCLUDE_WINDOWS_H\r
295 #ifndef HANDLE\r
296 # define PTW32__HANDLE_DEF\r
297 # define HANDLE void *\r
298 #endif\r
299 #ifndef DWORD\r
300 # define PTW32__DWORD_DEF\r
301 # define DWORD unsigned long\r
302 #endif\r
303 #endif\r
304 \r
305 #ifndef _CRT_NO_TIME_T\r
306 #define HAVE_STRUCT_TIMESPEC 1\r
307 #endif\r
308 \r
309 #ifndef HAVE_STRUCT_TIMESPEC\r
310 #define HAVE_STRUCT_TIMESPEC 1\r
311 struct timespec {\r
312         long tv_sec;\r
313         long tv_nsec;\r
314 };\r
315 #endif /* HAVE_STRUCT_TIMESPEC */\r
316 \r
317 #ifndef SIG_BLOCK\r
318 #define SIG_BLOCK 0\r
319 #endif /* SIG_BLOCK */\r
320 \r
321 #ifndef SIG_UNBLOCK \r
322 #define SIG_UNBLOCK 1\r
323 #endif /* SIG_UNBLOCK */\r
324 \r
325 #ifndef SIG_SETMASK\r
326 #define SIG_SETMASK 2\r
327 #endif /* SIG_SETMASK */\r
328 \r
329 #ifdef __cplusplus\r
330 extern "C"\r
331 {\r
332 #endif                          /* __cplusplus */\r
333 \r
334         /*\r
335         * -------------------------------------------------------------\r
336         *\r
337         * POSIX 1003.1-2001 Options\r
338         * =========================\r
339         *\r
340         * Options are normally set in <unistd.h>, which is not provided\r
341         * with pthreads-win32.\r
342         *\r
343         * For conformance with the Single Unix Specification (version 3), all of the\r
344         * options below are defined, and have a value of either -1 (not supported)\r
345         * or 200112L (supported).\r
346         *\r
347         * These options can neither be left undefined nor have a value of 0, because\r
348         * either indicates that sysconf(), which is not implemented, may be used at\r
349         * runtime to check the status of the option.\r
350         *\r
351         * _POSIX_THREADS (== 200112L)\r
352         *                      If == 200112L, you can use threads\r
353         *\r
354         * _POSIX_THREAD_ATTR_STACKSIZE (== 200112L)\r
355         *                      If == 200112L, you can control the size of a thread's\r
356         *                      stack\r
357         *                              pthread_attr_getstacksize\r
358         *                              pthread_attr_setstacksize\r
359         *\r
360         * _POSIX_THREAD_ATTR_STACKADDR (== -1)\r
361         *                      If == 200112L, you can allocate and control a thread's\r
362         *                      stack. If not supported, the following functions\r
363         *                      will return ENOSYS, indicating they are not\r
364         *                      supported:\r
365         *                              pthread_attr_getstackaddr\r
366         *                              pthread_attr_setstackaddr\r
367         *\r
368         * _POSIX_THREAD_PRIORITY_SCHEDULING (== -1)\r
369         *                      If == 200112L, you can use realtime scheduling.\r
370         *                      This option indicates that the behaviour of some\r
371         *                      implemented functions conforms to the additional TPS\r
372         *                      requirements in the standard. E.g. rwlocks favour\r
373         *                      writers over readers when threads have equal priority.\r
374         *\r
375         * _POSIX_THREAD_PRIO_INHERIT (== -1)\r
376         *                      If == 200112L, you can create priority inheritance\r
377         *                      mutexes.\r
378         *                              pthread_mutexattr_getprotocol +\r
379         *                              pthread_mutexattr_setprotocol +\r
380         *\r
381         * _POSIX_THREAD_PRIO_PROTECT (== -1)\r
382         *                      If == 200112L, you can create priority ceiling mutexes\r
383         *                      Indicates the availability of:\r
384         *                              pthread_mutex_getprioceiling\r
385         *                              pthread_mutex_setprioceiling\r
386         *                              pthread_mutexattr_getprioceiling\r
387         *                              pthread_mutexattr_getprotocol     +\r
388         *                              pthread_mutexattr_setprioceiling\r
389         *                              pthread_mutexattr_setprotocol     +\r
390         *\r
391         * _POSIX_THREAD_PROCESS_SHARED (== -1)\r
392         *                      If set, you can create mutexes and condition\r
393         *                      variables that can be shared with another\r
394         *                      process.If set, indicates the availability\r
395         *                      of:\r
396         *                              pthread_mutexattr_getpshared\r
397         *                              pthread_mutexattr_setpshared\r
398         *                              pthread_condattr_getpshared\r
399         *                              pthread_condattr_setpshared\r
400         *\r
401         * _POSIX_THREAD_SAFE_FUNCTIONS (== 200112L)\r
402         *                      If == 200112L you can use the special *_r library\r
403         *                      functions that provide thread-safe behaviour\r
404         *\r
405         * _POSIX_READER_WRITER_LOCKS (== 200112L)\r
406         *                      If == 200112L, you can use read/write locks\r
407         *\r
408         * _POSIX_SPIN_LOCKS (== 200112L)\r
409         *                      If == 200112L, you can use spin locks\r
410         *\r
411         * _POSIX_BARRIERS (== 200112L)\r
412         *                      If == 200112L, you can use barriers\r
413         *\r
414         *      + These functions provide both 'inherit' and/or\r
415         *        'protect' protocol, based upon these macro\r
416         *        settings.\r
417         *\r
418         * -------------------------------------------------------------\r
419         */\r
420 \r
421         /*\r
422         * POSIX Options\r
423         */\r
424 #undef _POSIX_THREADS\r
425 #define _POSIX_THREADS 200112L\r
426 \r
427 #undef _POSIX_READER_WRITER_LOCKS\r
428 #define _POSIX_READER_WRITER_LOCKS 200112L\r
429 \r
430 #undef _POSIX_SPIN_LOCKS\r
431 #define _POSIX_SPIN_LOCKS 200112L\r
432 \r
433 #undef _POSIX_BARRIERS\r
434 #define _POSIX_BARRIERS 200112L\r
435 \r
436 #undef _POSIX_THREAD_SAFE_FUNCTIONS\r
437 #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L\r
438 \r
439 #undef _POSIX_THREAD_ATTR_STACKSIZE\r
440 #define _POSIX_THREAD_ATTR_STACKSIZE 200112L\r
441 \r
442         /*\r
443         * The following options are not supported\r
444         */\r
445 #undef _POSIX_THREAD_ATTR_STACKADDR\r
446 #define _POSIX_THREAD_ATTR_STACKADDR -1\r
447 \r
448 #undef _POSIX_THREAD_PRIO_INHERIT\r
449 #define _POSIX_THREAD_PRIO_INHERIT -1\r
450 \r
451 #undef _POSIX_THREAD_PRIO_PROTECT\r
452 #define _POSIX_THREAD_PRIO_PROTECT -1\r
453 \r
454         /* TPS is not fully supported.  */\r
455 #undef _POSIX_THREAD_PRIORITY_SCHEDULING\r
456 #define _POSIX_THREAD_PRIORITY_SCHEDULING -1\r
457 \r
458 #undef _POSIX_THREAD_PROCESS_SHARED\r
459 #define _POSIX_THREAD_PROCESS_SHARED -1\r
460 \r
461 \r
462         /*\r
463         * POSIX 1003.1-2001 Limits\r
464         * ===========================\r
465         *\r
466         * These limits are normally set in <limits.h>, which is not provided with\r
467         * pthreads-win32.\r
468         *\r
469         * PTHREAD_DESTRUCTOR_ITERATIONS\r
470         *                      Maximum number of attempts to destroy\r
471         *                      a thread's thread-specific data on\r
472         *                      termination (must be at least 4)\r
473         *\r
474         * PTHREAD_KEYS_MAX\r
475         *                      Maximum number of thread-specific data keys\r
476         *                      available per process (must be at least 128)\r
477         *\r
478         * PTHREAD_STACK_MIN\r
479         *                      Minimum supported stack size for a thread\r
480         *\r
481         * PTHREAD_THREADS_MAX\r
482         *                      Maximum number of threads supported per\r
483         *                      process (must be at least 64).\r
484         *\r
485         * SEM_NSEMS_MAX\r
486         *                      The maximum number of semaphores a process can have.\r
487         *                      (must be at least 256)\r
488         *\r
489         * SEM_VALUE_MAX\r
490         *                      The maximum value a semaphore can have.\r
491         *                      (must be at least 32767)\r
492         *\r
493         */\r
494 #undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS\r
495 #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS     4\r
496 \r
497 #undef PTHREAD_DESTRUCTOR_ITERATIONS\r
498 #define PTHREAD_DESTRUCTOR_ITERATIONS           _POSIX_THREAD_DESTRUCTOR_ITERATIONS\r
499 \r
500 #undef _POSIX_THREAD_KEYS_MAX\r
501 #define _POSIX_THREAD_KEYS_MAX                  128\r
502 \r
503 #undef PTHREAD_KEYS_MAX\r
504 #define PTHREAD_KEYS_MAX                        _POSIX_THREAD_KEYS_MAX\r
505 \r
506 #undef PTHREAD_STACK_MIN\r
507 #define PTHREAD_STACK_MIN                       0\r
508 \r
509 #undef _POSIX_THREAD_THREADS_MAX\r
510 #define _POSIX_THREAD_THREADS_MAX               64\r
511 \r
512         /* Arbitrary value */\r
513 #undef PTHREAD_THREADS_MAX\r
514 #define PTHREAD_THREADS_MAX                     2019\r
515 \r
516 #undef _POSIX_SEM_NSEMS_MAX\r
517 #define _POSIX_SEM_NSEMS_MAX                    256\r
518 \r
519         /* Arbitrary value */\r
520 #undef SEM_NSEMS_MAX\r
521 #define SEM_NSEMS_MAX                           1024\r
522 \r
523 #undef _POSIX_SEM_VALUE_MAX\r
524 #define _POSIX_SEM_VALUE_MAX                    32767\r
525 \r
526 #undef SEM_VALUE_MAX\r
527 #define SEM_VALUE_MAX                           INT_MAX\r
528 \r
529 \r
530 #if __GNUC__ && ! defined (__declspec)\r
531 # error Please upgrade your GNU compiler to one that supports __declspec.\r
532 #endif\r
533 \r
534         /*\r
535         * When building the DLL code, you should define PTW32_BUILD so that\r
536         * the variables/functions are exported correctly. When using the DLL,\r
537         * do NOT define PTW32_BUILD, and then the variables/functions will\r
538         * be imported correctly.\r
539         */\r
540 #ifndef PTW32_STATIC_LIB\r
541 #  ifdef PTW32_BUILD\r
542 #    define PTW32_DLLPORT __declspec (dllexport)\r
543 #  else\r
544 #    define PTW32_DLLPORT __declspec (dllimport)\r
545 #  endif\r
546 #else\r
547 #  define PTW32_DLLPORT\r
548 #endif\r
549 \r
550         /*\r
551         * The Open Watcom C/C++ compiler uses a non-standard calling convention\r
552         * that passes function args in registers unless __cdecl is explicitly specified\r
553         * in exposed function prototypes.\r
554         *\r
555         * We force all calls to cdecl even though this could slow Watcom code down\r
556         * slightly. If you know that the Watcom compiler will be used to build both\r
557         * the DLL and application, then you can probably define this as a null string.\r
558         * Remember that pthread.h (this file) is used for both the DLL and application builds.\r
559         */\r
560 #define PTW32_CDECL __cdecl\r
561 \r
562 #if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX\r
563 #   include     <sys/types.h>\r
564 #else\r
565         /*\r
566         * Generic handle type - intended to extend uniqueness beyond\r
567         * that available with a simple pointer. It should scale for either\r
568         * IA-32 or IA-64.\r
569         */\r
570         typedef struct {\r
571                 void * p;                   /* Pointer to actual object */\r
572                 unsigned int x;             /* Extra information - reuse count etc */\r
573         } ptw32_handle_t;\r
574 \r
575         typedef ptw32_handle_t pthread_t;\r
576         typedef struct pthread_attr_t_ * pthread_attr_t;\r
577         typedef struct pthread_once_t_ pthread_once_t;\r
578         typedef struct pthread_key_t_ * pthread_key_t;\r
579         typedef struct pthread_mutex_t_ * pthread_mutex_t;\r
580         typedef struct pthread_mutexattr_t_ * pthread_mutexattr_t;\r
581         typedef struct pthread_cond_t_ * pthread_cond_t;\r
582         typedef struct pthread_condattr_t_ * pthread_condattr_t;\r
583 #endif\r
584         typedef struct pthread_rwlock_t_ * pthread_rwlock_t;\r
585         typedef struct pthread_rwlockattr_t_ * pthread_rwlockattr_t;\r
586         typedef struct pthread_spinlock_t_ * pthread_spinlock_t;\r
587         typedef struct pthread_barrier_t_ * pthread_barrier_t;\r
588         typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t;\r
589 \r
590         /*\r
591         * ====================\r
592         * ====================\r
593         * POSIX Threads\r
594         * ====================\r
595         * ====================\r
596         */\r
597 \r
598         enum {\r
599                 /*\r
600                 * pthread_attr_{get,set}detachstate\r
601                 */\r
602                 PTHREAD_CREATE_JOINABLE = 0,  /* Default */\r
603                 PTHREAD_CREATE_DETACHED = 1,\r
604 \r
605                 /*\r
606                 * pthread_attr_{get,set}inheritsched\r
607                 */\r
608                 PTHREAD_INHERIT_SCHED = 0,\r
609                 PTHREAD_EXPLICIT_SCHED = 1,  /* Default */\r
610 \r
611                                                                          /*\r
612                                                                          * pthread_{get,set}scope\r
613                                                                          */\r
614                 PTHREAD_SCOPE_PROCESS = 0,\r
615                 PTHREAD_SCOPE_SYSTEM = 1,  /* Default */\r
616 \r
617                                                                    /*\r
618                                                                    * pthread_setcancelstate paramters\r
619                                                                    */\r
620                 PTHREAD_CANCEL_ENABLE = 0,  /* Default */\r
621                 PTHREAD_CANCEL_DISABLE = 1,\r
622 \r
623                 /*\r
624                 * pthread_setcanceltype parameters\r
625                 */\r
626                 PTHREAD_CANCEL_ASYNCHRONOUS = 0,\r
627                 PTHREAD_CANCEL_DEFERRED = 1,  /* Default */\r
628 \r
629                                                                           /*\r
630                                                                           * pthread_mutexattr_{get,set}pshared\r
631                                                                           * pthread_condattr_{get,set}pshared\r
632                                                                           */\r
633                 PTHREAD_PROCESS_PRIVATE = 0,\r
634                 PTHREAD_PROCESS_SHARED = 1,\r
635 \r
636                 /*\r
637                 * pthread_barrier_wait\r
638                 */\r
639                 PTHREAD_BARRIER_SERIAL_THREAD = -1\r
640         };\r
641 \r
642         /*\r
643         * ====================\r
644         * ====================\r
645         * Cancelation\r
646         * ====================\r
647         * ====================\r
648         */\r
649 #define PTHREAD_CANCELED       ((void *) -1)\r
650 \r
651 \r
652         /*\r
653         * ====================\r
654         * ====================\r
655         * Once Key\r
656         * ====================\r
657         * ====================\r
658         */\r
659 #define PTHREAD_ONCE_INIT       { PTW32_FALSE, 0, 0, 0}\r
660 \r
661         struct pthread_once_t_\r
662         {\r
663                 int          done;        /* indicates if user function has been executed */\r
664                 void *       lock;\r
665                 int          reserved1;\r
666                 int          reserved2;\r
667         };\r
668 \r
669 \r
670         /*\r
671         * ====================\r
672         * ====================\r
673         * Object initialisers\r
674         * ====================\r
675         * ====================\r
676         */\r
677 #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)\r
678 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2)\r
679 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3)\r
680 \r
681         /*\r
682         * Compatibility with LinuxThreads\r
683         */\r
684 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER\r
685 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER\r
686 \r
687 #define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)\r
688 \r
689 #define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) -1)\r
690 \r
691 #define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t) -1)\r
692 \r
693 \r
694         /*\r
695         * Mutex types.\r
696         */\r
697         enum\r
698         {\r
699                 /* Compatibility with LinuxThreads */\r
700                 PTHREAD_MUTEX_FAST_NP,\r
701                 PTHREAD_MUTEX_RECURSIVE_NP,\r
702                 PTHREAD_MUTEX_ERRORCHECK_NP,\r
703                 PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP,\r
704                 PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP,\r
705                 /* For compatibility with POSIX */\r
706                 PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP,\r
707                 PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,\r
708                 PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,\r
709                 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL\r
710         };\r
711 \r
712 \r
713         typedef struct ptw32_cleanup_t ptw32_cleanup_t;\r
714 \r
715 #if defined(_MSC_VER)\r
716         /* Disable MSVC 'anachronism used' warning */\r
717 #pragma warning( disable : 4229 )\r
718 #endif\r
719 \r
720         typedef void(*PTW32_CDECL ptw32_cleanup_callback_t)(void *);\r
721 \r
722 #if defined(_MSC_VER)\r
723 #pragma warning( default : 4229 )\r
724 #endif\r
725 \r
726         struct ptw32_cleanup_t\r
727         {\r
728                 ptw32_cleanup_callback_t routine;\r
729                 void *arg;\r
730                 struct ptw32_cleanup_t *prev;\r
731         };\r
732 \r
733 #ifdef __CLEANUP_SEH\r
734         /*\r
735         * WIN32 SEH version of cancel cleanup.\r
736         */\r
737 \r
738 #define pthread_cleanup_push( _rout, _arg ) \\r
739         { \\r
740             ptw32_cleanup_t     _cleanup; \\r
741             \\r
742         _cleanup.routine        = (ptw32_cleanup_callback_t)(_rout); \\r
743             _cleanup.arg        = (_arg); \\r
744             __try \\r
745               { \\r
746 \r
747 #define pthread_cleanup_pop( _execute ) \\r
748               } \\r
749             __finally \\r
750                 { \\r
751                     if( _execute || AbnormalTermination()) \\r
752                       { \\r
753                           (*(_cleanup.routine))( _cleanup.arg ); \\r
754                       } \\r
755                 } \\r
756         }\r
757 \r
758 #else /* __CLEANUP_SEH */\r
759 \r
760 #ifdef __CLEANUP_C\r
761 \r
762         /*\r
763         * C implementation of PThreads cancel cleanup\r
764         */\r
765 \r
766 #define pthread_cleanup_push( _rout, _arg ) \\r
767         { \\r
768             ptw32_cleanup_t     _cleanup; \\r
769             \\r
770             ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \\r
771 \r
772 #define pthread_cleanup_pop( _execute ) \\r
773             (void) ptw32_pop_cleanup( _execute ); \\r
774         }\r
775 \r
776 #else /* __CLEANUP_C */\r
777 \r
778 #ifdef __CLEANUP_CXX\r
779 \r
780         /*\r
781         * C++ version of cancel cleanup.\r
782         * - John E. Bossom.\r
783         */\r
784 \r
785         class PThreadCleanup {\r
786                 /*\r
787                 * PThreadCleanup\r
788                 *\r
789                 * Purpose\r
790                 *      This class is a C++ helper class that is\r
791                 *      used to implement pthread_cleanup_push/\r
792                 *      pthread_cleanup_pop.\r
793                 *      The destructor of this class automatically\r
794                 *      pops the pushed cleanup routine regardless\r
795                 *      of how the code exits the scope\r
796                 *      (i.e. such as by an exception)\r
797                 */\r
798                 ptw32_cleanup_callback_t cleanUpRout;\r
799                 void    *       obj;\r
800                 int             executeIt;\r
801 \r
802         public:\r
803                 PThreadCleanup() :\r
804                         cleanUpRout(0),\r
805                         obj(0),\r
806                         executeIt(0)\r
807                         /*\r
808                         * No cleanup performed\r
809                         */\r
810                 {\r
811                 }\r
812 \r
813                 PThreadCleanup(\r
814                         ptw32_cleanup_callback_t routine,\r
815                         void    *       arg) :\r
816                         cleanUpRout(routine),\r
817                         obj(arg),\r
818                         executeIt(1)\r
819                         /*\r
820                         * Registers a cleanup routine for 'arg'\r
821                         */\r
822                 {\r
823                 }\r
824 \r
825                 ~PThreadCleanup()\r
826                 {\r
827                         if (executeIt && ((void *)cleanUpRout != (void *)0))\r
828                         {\r
829                                 (void)(*cleanUpRout)(obj);\r
830                         }\r
831                 }\r
832 \r
833                 void execute(int exec)\r
834                 {\r
835                         executeIt = exec;\r
836                 }\r
837         };\r
838 \r
839         /*\r
840         * C++ implementation of PThreads cancel cleanup;\r
841         * This implementation takes advantage of a helper\r
842         * class who's destructor automatically calls the\r
843         * cleanup routine if we exit our scope weirdly\r
844         */\r
845 #define pthread_cleanup_push( _rout, _arg ) \\r
846         { \\r
847             PThreadCleanup  cleanup((ptw32_cleanup_callback_t)(_rout), \\r
848                                     (void *) (_arg) );\r
849 \r
850 #define pthread_cleanup_pop( _execute ) \\r
851             cleanup.execute( _execute ); \\r
852         }\r
853 \r
854 #else\r
855 \r
856 #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.\r
857 \r
858 #endif /* __CLEANUP_CXX */\r
859 \r
860 #endif /* __CLEANUP_C */\r
861 \r
862 #endif /* __CLEANUP_SEH */\r
863 \r
864         /*\r
865         * ===============\r
866         * ===============\r
867         * Methods\r
868         * ===============\r
869         * ===============\r
870         */\r
871 \r
872         /*\r
873         * PThread Attribute Functions\r
874         */\r
875         PTW32_DLLPORT int PTW32_CDECL pthread_attr_init(pthread_attr_t * attr);\r
876 \r
877         PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy(pthread_attr_t * attr);\r
878 \r
879         PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate(const pthread_attr_t * attr,\r
880                 int *detachstate);\r
881 \r
882         PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr(const pthread_attr_t * attr,\r
883                 void **stackaddr);\r
884 \r
885         PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize(const pthread_attr_t * attr,\r
886                 size_t * stacksize);\r
887 \r
888         PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate(pthread_attr_t * attr,\r
889                 int detachstate);\r
890 \r
891         PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr(pthread_attr_t * attr,\r
892                 void *stackaddr);\r
893 \r
894         PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize(pthread_attr_t * attr,\r
895                 size_t stacksize);\r
896 \r
897         PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam(const pthread_attr_t *attr,\r
898                 struct sched_param *param);\r
899 \r
900         PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam(pthread_attr_t *attr,\r
901                 const struct sched_param *param);\r
902 \r
903         PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy(pthread_attr_t *,\r
904                 int);\r
905 \r
906         PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy(pthread_attr_t *,\r
907                 int *);\r
908 \r
909         PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr,\r
910                 int inheritsched);\r
911 \r
912         PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(pthread_attr_t * attr,\r
913                 int * inheritsched);\r
914 \r
915         PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope(pthread_attr_t *,\r
916                 int);\r
917 \r
918         PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope(const pthread_attr_t *,\r
919                 int *);\r
920 \r
921         /*\r
922         * PThread Functions\r
923         */\r
924         PTW32_DLLPORT int PTW32_CDECL pthread_create(pthread_t * tid,\r
925                 const pthread_attr_t * attr,\r
926                 void *(*start) (void *),\r
927                 void *arg);\r
928 \r
929         PTW32_DLLPORT int PTW32_CDECL pthread_detach(pthread_t tid);\r
930 \r
931         PTW32_DLLPORT int PTW32_CDECL pthread_equal(pthread_t t1,\r
932                 pthread_t t2);\r
933 \r
934         PTW32_DLLPORT void PTW32_CDECL pthread_exit(void *value_ptr);\r
935 \r
936         PTW32_DLLPORT int PTW32_CDECL pthread_join(pthread_t thread,\r
937                 void **value_ptr);\r
938 \r
939         PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self(void);\r
940 \r
941         PTW32_DLLPORT int PTW32_CDECL pthread_cancel(pthread_t thread);\r
942 \r
943         PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate(int state,\r
944                 int *oldstate);\r
945 \r
946         PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype(int type,\r
947                 int *oldtype);\r
948 \r
949         PTW32_DLLPORT void PTW32_CDECL pthread_testcancel(void);\r
950 \r
951         PTW32_DLLPORT int PTW32_CDECL pthread_once(pthread_once_t * once_control,\r
952                 void(*init_routine) (void));\r
953 \r
954 #if PTW32_LEVEL >= PTW32_LEVEL_MAX\r
955         PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup(int execute);\r
956 \r
957         PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup(ptw32_cleanup_t * cleanup,\r
958                 void(*routine) (void *),\r
959                 void *arg);\r
960 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */\r
961 \r
962         /*\r
963         * Thread Specific Data Functions\r
964         */\r
965         PTW32_DLLPORT int PTW32_CDECL pthread_key_create(pthread_key_t * key,\r
966                 void(*destructor) (void *));\r
967 \r
968         PTW32_DLLPORT int PTW32_CDECL pthread_key_delete(pthread_key_t key);\r
969 \r
970         PTW32_DLLPORT int PTW32_CDECL pthread_setspecific(pthread_key_t key,\r
971                 const void *value);\r
972 \r
973         PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific(pthread_key_t key);\r
974 \r
975 \r
976         /*\r
977         * Mutex Attribute Functions\r
978         */\r
979         PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init(pthread_mutexattr_t * attr);\r
980 \r
981         PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy(pthread_mutexattr_t * attr);\r
982 \r
983         PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared(const pthread_mutexattr_t\r
984                 * attr,\r
985                 int *pshared);\r
986 \r
987         PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared(pthread_mutexattr_t * attr,\r
988                 int pshared);\r
989 \r
990         PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype(pthread_mutexattr_t * attr, int kind);\r
991         PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype(pthread_mutexattr_t * attr, int *kind);\r
992 \r
993         /*\r
994         * Barrier Attribute Functions\r
995         */\r
996         PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init(pthread_barrierattr_t * attr);\r
997 \r
998         PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy(pthread_barrierattr_t * attr);\r
999 \r
1000         PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared(const pthread_barrierattr_t\r
1001                 * attr,\r
1002                 int *pshared);\r
1003 \r
1004         PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared(pthread_barrierattr_t * attr,\r
1005                 int pshared);\r
1006 \r
1007         /*\r
1008         * Mutex Functions\r
1009         */\r
1010         PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init(pthread_mutex_t * mutex,\r
1011                 const pthread_mutexattr_t * attr);\r
1012 \r
1013         PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy(pthread_mutex_t * mutex);\r
1014 \r
1015         PTW32_DLLPORT int PTW32_CDECL pthread_mutex_lock(pthread_mutex_t * mutex);\r
1016 \r
1017         PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t *mutex,\r
1018                 const struct timespec *abstime);\r
1019 \r
1020         PTW32_DLLPORT int PTW32_CDECL pthread_mutex_trylock(pthread_mutex_t * mutex);\r
1021 \r
1022         PTW32_DLLPORT int PTW32_CDECL pthread_mutex_unlock(pthread_mutex_t * mutex);\r
1023 \r
1024         /*\r
1025         * Spinlock Functions\r
1026         */\r
1027         PTW32_DLLPORT int PTW32_CDECL pthread_spin_init(pthread_spinlock_t * lock, int pshared);\r
1028 \r
1029         PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy(pthread_spinlock_t * lock);\r
1030 \r
1031         PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock(pthread_spinlock_t * lock);\r
1032 \r
1033         PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock(pthread_spinlock_t * lock);\r
1034 \r
1035         PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock(pthread_spinlock_t * lock);\r
1036 \r
1037         /*\r
1038         * Barrier Functions\r
1039         */\r
1040         PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init(pthread_barrier_t * barrier,\r
1041                 const pthread_barrierattr_t * attr,\r
1042                 unsigned int count);\r
1043 \r
1044         PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy(pthread_barrier_t * barrier);\r
1045 \r
1046         PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait(pthread_barrier_t * barrier);\r
1047 \r
1048         /*\r
1049         * Condition Variable Attribute Functions\r
1050         */\r
1051         PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init(pthread_condattr_t * attr);\r
1052 \r
1053         PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy(pthread_condattr_t * attr);\r
1054 \r
1055         PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared(const pthread_condattr_t * attr,\r
1056                 int *pshared);\r
1057 \r
1058         PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared(pthread_condattr_t * attr,\r
1059                 int pshared);\r
1060 \r
1061         /*\r
1062         * Condition Variable Functions\r
1063         */\r
1064         PTW32_DLLPORT int PTW32_CDECL pthread_cond_init(pthread_cond_t * cond,\r
1065                 const pthread_condattr_t * attr);\r
1066 \r
1067         PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy(pthread_cond_t * cond);\r
1068 \r
1069         PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait(pthread_cond_t * cond,\r
1070                 pthread_mutex_t * mutex);\r
1071 \r
1072         PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait(pthread_cond_t * cond,\r
1073                 pthread_mutex_t * mutex,\r
1074                 const struct timespec *abstime);\r
1075 \r
1076         PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal(pthread_cond_t * cond);\r
1077 \r
1078         PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast(pthread_cond_t * cond);\r
1079 \r
1080         /*\r
1081         * Scheduling\r
1082         */\r
1083         PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam(pthread_t thread,\r
1084                 int policy,\r
1085                 const struct sched_param *param);\r
1086 \r
1087         PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam(pthread_t thread,\r
1088                 int *policy,\r
1089                 struct sched_param *param);\r
1090 \r
1091         PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency(int);\r
1092 \r
1093         PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency(void);\r
1094 \r
1095         /*\r
1096         * Read-Write Lock Functions\r
1097         */\r
1098         PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock,\r
1099                 const pthread_rwlockattr_t *attr);\r
1100 \r
1101         PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock);\r
1102 \r
1103         PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *);\r
1104 \r
1105         PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *);\r
1106 \r
1107         PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock);\r
1108 \r
1109         PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock,\r
1110                 const struct timespec *abstime);\r
1111 \r
1112         PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock);\r
1113 \r
1114         PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock,\r
1115                 const struct timespec *abstime);\r
1116 \r
1117         PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock);\r
1118 \r
1119         PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init(pthread_rwlockattr_t * attr);\r
1120 \r
1121         PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy(pthread_rwlockattr_t * attr);\r
1122 \r
1123         PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * attr,\r
1124                 int *pshared);\r
1125 \r
1126         PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared(pthread_rwlockattr_t * attr,\r
1127                 int pshared);\r
1128 \r
1129 #if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1\r
1130 \r
1131         /*\r
1132         * Signal Functions. Should be defined in <signal.h> but MSVC and MinGW32\r
1133         * already have signal.h that don't define these.\r
1134         */\r
1135         PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig);\r
1136 \r
1137         /*\r
1138         * Non-portable functions\r
1139         */\r
1140 \r
1141         /*\r
1142         * Compatibility with Linux.\r
1143         */\r
1144         PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr,\r
1145                 int kind);\r
1146         PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr,\r
1147                 int *kind);\r
1148 \r
1149         /*\r
1150         * Possibly supported by other POSIX threads implementations\r
1151         */\r
1152         PTW32_DLLPORT int PTW32_CDECL pthread_delay_np(struct timespec * interval);\r
1153         PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void);\r
1154 \r
1155         /*\r
1156         * Useful if an application wants to statically link\r
1157         * the lib rather than load the DLL at run-time.\r
1158         */\r
1159         PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void);\r
1160         PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void);\r
1161         PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void);\r
1162         PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void);\r
1163 \r
1164         /*\r
1165         * Features that are auto-detected at load/run time.\r
1166         */\r
1167         PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int);\r
1168         enum ptw32_features {\r
1169                 PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */\r
1170                 PTW32_ALERTABLE_ASYNC_CANCEL = 0x0002  /* Can cancel blocked threads. */\r
1171         };\r
1172 \r
1173         /*\r
1174         * Register a system time change with the library.\r
1175         * Causes the library to perform various functions\r
1176         * in response to the change. Should be called whenever\r
1177         * the application's top level window receives a\r
1178         * WM_TIMECHANGE message. It can be passed directly to\r
1179         * pthread_create() as a new thread if desired.\r
1180         */\r
1181         PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *);\r
1182 \r
1183 #endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */\r
1184 \r
1185 #if PTW32_LEVEL >= PTW32_LEVEL_MAX\r
1186 \r
1187         /*\r
1188         * Returns the Win32 HANDLE for the POSIX thread.\r
1189         */\r
1190         PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread);\r
1191 \r
1192 \r
1193         /*\r
1194         * Protected Methods\r
1195         *\r
1196         * This function blocks until the given WIN32 handle\r
1197         * is signaled or pthread_cancel had been called.\r
1198         * This function allows the caller to hook into the\r
1199         * PThreads cancel mechanism. It is implemented using\r
1200         *\r
1201         *              WaitForMultipleObjects\r
1202         *\r
1203         * on 'waitHandle' and a manually reset WIN32 Event\r
1204         * used to implement pthread_cancel. The 'timeout'\r
1205         * argument to TimedWait is simply passed to\r
1206         * WaitForMultipleObjects.\r
1207         */\r
1208         PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait(HANDLE waitHandle);\r
1209         PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait(HANDLE waitHandle,\r
1210                 DWORD timeout);\r
1211 \r
1212 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */\r
1213 \r
1214         /*\r
1215         * Thread-Safe C Runtime Library Mappings.\r
1216         */\r
1217 #ifndef _UWIN\r
1218 #  if defined(NEED_ERRNO)\r
1219         PTW32_DLLPORT int * PTW32_CDECL _errno(void);\r
1220 #  else\r
1221 #    ifndef errno\r
1222 #      if (defined(_MT) || defined(_DLL))\r
1223         __declspec(dllimport) extern int * __cdecl _errno(void);\r
1224 #        define errno   (*_errno())\r
1225 #      endif\r
1226 #    endif\r
1227 #  endif\r
1228 #endif\r
1229 \r
1230         /*\r
1231         * WIN32 C runtime library had been made thread-safe\r
1232         * without affecting the user interface. Provide\r
1233         * mappings from the UNIX thread-safe versions to\r
1234         * the standard C runtime library calls.\r
1235         * Only provide function mappings for functions that\r
1236         * actually exist on WIN32.\r
1237         */\r
1238 \r
1239 #if !defined(__MINGW32__)\r
1240 #define strtok_r( _s, _sep, _lasts ) \\r
1241         ( *(_lasts) = strtok( (_s), (_sep) ) )\r
1242 #endif /* !__MINGW32__ */\r
1243 \r
1244 #define asctime_r( _tm, _buf ) \\r
1245         ( strcpy( (_buf), asctime( (_tm) ) ), \\r
1246           (_buf) )\r
1247 \r
1248 #define ctime_r( _clock, _buf ) \\r
1249         ( strcpy( (_buf), ctime( (_clock) ) ),  \\r
1250           (_buf) )\r
1251 \r
1252 #define gmtime_r( _clock, _result ) \\r
1253         ( *(_result) = *gmtime( (_clock) ), \\r
1254           (_result) )\r
1255 \r
1256 #define localtime_r( _clock, _result ) \\r
1257         ( *(_result) = *localtime( (_clock) ), \\r
1258           (_result) )\r
1259 \r
1260 #define rand_r( _seed ) \\r
1261         ( _seed == _seed? rand() : rand() )\r
1262 \r
1263 \r
1264         /*\r
1265         * Some compiler environments don't define some things.\r
1266         */\r
1267 #if defined(__BORLANDC__)\r
1268 #  define _ftime ftime\r
1269 #  define _timeb timeb\r
1270 #endif\r
1271 \r
1272 #ifdef __cplusplus\r
1273 \r
1274         /*\r
1275         * Internal exceptions\r
1276         */\r
1277         class ptw32_exception {};\r
1278         class ptw32_exception_cancel : public ptw32_exception {};\r
1279         class ptw32_exception_exit : public ptw32_exception {};\r
1280 \r
1281 #endif\r
1282 \r
1283 #if PTW32_LEVEL >= PTW32_LEVEL_MAX\r
1284 \r
1285         /* FIXME: This is only required if the library was built using SEH */\r
1286         /*\r
1287         * Get internal SEH tag\r
1288         */\r
1289         PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void);\r
1290 \r
1291 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */\r
1292 \r
1293 #ifndef PTW32_BUILD\r
1294 \r
1295 #ifdef __CLEANUP_SEH\r
1296 \r
1297         /*\r
1298         * Redefine the SEH __except keyword to ensure that applications\r
1299         * propagate our internal exceptions up to the library's internal handlers.\r
1300         */\r
1301 #define __except( E ) \\r
1302         __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \\r
1303                  ? EXCEPTION_CONTINUE_SEARCH : ( E ) )\r
1304 \r
1305 #endif /* __CLEANUP_SEH */\r
1306 \r
1307 #ifdef __CLEANUP_CXX\r
1308 \r
1309         /*\r
1310         * Redefine the C++ catch keyword to ensure that applications\r
1311         * propagate our internal exceptions up to the library's internal handlers.\r
1312         */\r
1313 #ifdef _MSC_VER\r
1314         /*\r
1315         * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll'\r
1316         * if you want Pthread-Win32 cancelation and pthread_exit to work.\r
1317         */\r
1318 \r
1319 #ifndef PtW32NoCatchWarn\r
1320 \r
1321 #pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.")\r
1322 #pragma message("------------------------------------------------------------------")\r
1323 #pragma message("When compiling applications with MSVC++ and C++ exception handling:")\r
1324 #pragma message("  Replace any 'catch( ... )' in routines called from POSIX threads")\r
1325 #pragma message("  with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread")\r
1326 #pragma message("  cancelation and pthread_exit to work. For example:")\r
1327 #pragma message("")\r
1328 #pragma message("    #ifdef PtW32CatchAll")\r
1329 #pragma message("      PtW32CatchAll")\r
1330 #pragma message("    #else")\r
1331 #pragma message("      catch(...)")\r
1332 #pragma message("    #endif")\r
1333 #pragma message("        {")\r
1334 #pragma message("          /* Catchall block processing */")\r
1335 #pragma message("        }")\r
1336 #pragma message("------------------------------------------------------------------")\r
1337 \r
1338 #endif\r
1339 \r
1340 #define PtW32CatchAll \\r
1341         catch( ptw32_exception & ) { throw; } \\r
1342         catch( ... )\r
1343 \r
1344 #else /* _MSC_VER */\r
1345 \r
1346 #define catch( E ) \\r
1347         catch( ptw32_exception & ) { throw; } \\r
1348         catch( E )\r
1349 \r
1350 #endif /* _MSC_VER */\r
1351 \r
1352 #endif /* __CLEANUP_CXX */\r
1353 \r
1354 #endif /* ! PTW32_BUILD */\r
1355 \r
1356 #ifdef __cplusplus\r
1357 }                               /* End of extern "C" */\r
1358 #endif                          /* __cplusplus */\r
1359 \r
1360 #ifdef PTW32__HANDLE_DEF\r
1361 # undef HANDLE\r
1362 #endif\r
1363 #ifdef PTW32__DWORD_DEF\r
1364 # undef DWORD\r
1365 #endif\r
1366 \r
1367 #undef PTW32_LEVEL\r
1368 #undef PTW32_LEVEL_MAX\r
1369 \r
1370 #endif /* ! RC_INVOKED */\r
1371 \r
1372 #endif /* PTHREAD_H */\r