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