00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #if !defined( PTHREAD_H )
00034 #define PTHREAD_H
00035
00036 #undef PTW32_LEVEL
00037
00038 #if defined(_POSIX_SOURCE)
00039 #define PTW32_LEVEL 0
00040
00041 #endif
00042
00043 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
00044 #undef PTW32_LEVEL
00045 #define PTW32_LEVEL 1
00046
00047 #endif
00048
00049 #if defined(INCLUDE_NP)
00050 #undef PTW32_LEVEL
00051 #define PTW32_LEVEL 2
00052
00053 #endif
00054
00055 #define PTW32_LEVEL_MAX 3
00056
00057 #if !defined(PTW32_LEVEL)
00058 #define PTW32_LEVEL PTW32_LEVEL_MAX
00059
00060 #endif
00061
00062 #ifdef _UWIN
00063 # define HAVE_STRUCT_TIMESPEC 1
00064 # define HAVE_SIGNAL_H 1
00065 # undef HAVE_CONFIG_H
00066 # pragma comment(lib, "pthread")
00067 #endif
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 #if defined(__MINGW32__) && defined(__cplusplus)
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 #define PTW32_INCLUDE_WINDOWS_H
00154 #endif
00155
00156 #ifdef PTW32_INCLUDE_WINDOWS_H
00157 #include <windows.h>
00158 #endif
00159
00160
00161
00162
00163
00164
00165
00166 #if HAVE_CONFIG_H
00167 #include "config.h"
00168 #endif
00169
00170 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
00171
00172
00173 #if defined(__MINGW32__) && defined(__cplusplus)
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 #define PTW32_INCLUDE_WINDOWS_H
00184 #endif
00185
00186 #ifdef PTW32_INCLUDE_WINDOWS_H
00187 #include <windows.h>
00188 #endif
00189
00190 #ifndef NEED_FTIME
00191 #include <time.h>
00192 #else
00193
00194 #endif
00195
00196 #if HAVE_SIGNAL_H
00197 #include <signal.h>
00198 #endif
00199
00200 #include <setjmp.h>
00201 #include <limits.h>
00202
00203
00204
00205
00206 enum {
00207 PTW32_FALSE = 0,
00208 PTW32_TRUE = (! PTW32_FALSE)
00209 };
00210
00211
00212
00213
00214
00215
00216 #ifndef PTW32_CONFIG_H
00217 # if defined(WINCE)
00218 # define NEED_ERRNO
00219 # define NEED_SEM
00220 # endif
00221 # if defined(_UWIN) || defined(__MINGW32__)
00222 # define HAVE_MODE_T
00223 # endif
00224 #endif
00225
00226
00227
00228
00229
00230 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
00231 #ifdef NEED_ERRNO
00232 #include "need_errno.h"
00233 #else
00234 #include <errno.h>
00235 #endif
00236 #endif
00237
00238
00239
00240
00241
00242 #ifndef ENOTSUP
00243 # define ENOTSUP 48
00244 #endif
00245
00246 #ifndef ETIMEDOUT
00247 # define ETIMEDOUT 10060
00248 #endif
00249
00250 #include <sched.h>
00251
00252
00253
00254
00255
00256
00257 #ifndef PTW32_INCLUDE_WINDOWS_H
00258 #ifndef HANDLE
00259 # define PTW32__HANDLE_DEF
00260 # define HANDLE void *
00261 #endif
00262 #ifndef DWORD
00263 # define PTW32__DWORD_DEF
00264 # define DWORD unsigned long
00265 #endif
00266 #endif
00267
00268 #endif
00269
00270 #ifndef HAVE_STRUCT_TIMESPEC
00271 struct timespec {
00272 long tv_sec;
00273 long tv_nsec;
00274 };
00275 #endif
00276
00277 #ifndef SIG_BLOCK
00278 #define SIG_BLOCK 0
00279 #endif
00280
00281 #ifndef SIG_UNBLOCK
00282 #define SIG_UNBLOCK 1
00283 #endif
00284
00285 #ifndef SIG_SETMASK
00286 #define SIG_SETMASK 2
00287 #endif
00288
00289 #ifdef __cplusplus
00290 extern "C"
00291 {
00292 #endif
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 #ifndef _POSIX_THREADS
00411 #define _POSIX_THREADS
00412 #endif
00413
00414 #ifndef _POSIX_READER_WRITER_LOCKS
00415 #define _POSIX_READER_WRITER_LOCKS
00416 #endif
00417
00418 #ifndef _POSIX_SPIN_LOCKS
00419 #define _POSIX_SPIN_LOCKS
00420 #endif
00421
00422 #ifndef _POSIX_BARRIERS
00423 #define _POSIX_BARRIERS
00424 #endif
00425
00426 #define _POSIX_THREAD_SAFE_FUNCTIONS
00427 #define _POSIX_THREAD_ATTR_STACKSIZE
00428 #define _POSIX_THREAD_PRIORITY_SCHEDULING
00429
00430 #if defined( KLUDGE )
00431
00432
00433
00434 #define _POSIX_THREAD_ATTR_STACKADDR
00435 #define _POSIX_THREAD_PRIO_INHERIT
00436 #define _POSIX_THREAD_PRIO_PROTECT
00437 #define _POSIX_THREAD_PROCESS_SHARED
00438
00439 #endif
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 #define PTHREAD_DESTRUCTOR_ITERATIONS 4
00471 #define PTHREAD_KEYS_MAX 64
00472 #define PTHREAD_STACK_MIN 0
00473 #define PTHREAD_THREADS_MAX 2019
00474 #ifndef _POSIX_SEM_NSEMS_MAX
00475
00476 # define _POSIX_SEM_NSEMS_MAX 1024
00477 #endif
00478 #ifndef _POSIX_SEM_VALUE_MAX
00479 # define _POSIX_SEM_VALUE_MAX (INT_MAX/2)
00480 #endif
00481
00482 #if __GNUC__ && ! defined (__declspec)
00483 # error Please upgrade your GNU compiler to one that supports __declspec.
00484 #endif
00485
00486
00487
00488
00489
00490
00491
00492 #ifdef _DLL
00493 # ifdef PTW32_BUILD
00494 # define PTW32_DLLPORT __declspec (dllexport)
00495 # else
00496 # define PTW32_DLLPORT __declspec (dllimport)
00497 # endif
00498 #endif
00499
00500 #if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX
00501 # include <sys/types.h>
00502 #else
00503 typedef struct pthread_t_ *pthread_t;
00504 typedef struct pthread_attr_t_ *pthread_attr_t;
00505 typedef struct pthread_once_t_ pthread_once_t;
00506 typedef struct pthread_key_t_ *pthread_key_t;
00507 typedef struct pthread_mutex_t_ *pthread_mutex_t;
00508 typedef struct pthread_mutexattr_t_ *pthread_mutexattr_t;
00509 typedef struct pthread_cond_t_ *pthread_cond_t;
00510 typedef struct pthread_condattr_t_ *pthread_condattr_t;
00511 #endif
00512 typedef struct pthread_rwlock_t_ *pthread_rwlock_t;
00513 typedef struct pthread_rwlockattr_t_ *pthread_rwlockattr_t;
00514 typedef struct pthread_spinlock_t_ *pthread_spinlock_t;
00515 typedef struct pthread_barrier_t_ *pthread_barrier_t;
00516 typedef struct pthread_barrierattr_t_ *pthread_barrierattr_t;
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526 enum {
00527
00528
00529
00530 PTHREAD_CREATE_JOINABLE = 0,
00531 PTHREAD_CREATE_DETACHED = 1,
00532
00533
00534
00535
00536 PTHREAD_INHERIT_SCHED = 0,
00537 PTHREAD_EXPLICIT_SCHED = 1,
00538
00539
00540
00541
00542 PTHREAD_SCOPE_PROCESS = 0,
00543 PTHREAD_SCOPE_SYSTEM = 1,
00544
00545
00546
00547
00548 PTHREAD_CANCEL_ENABLE = 0,
00549 PTHREAD_CANCEL_DISABLE = 1,
00550
00551
00552
00553
00554 PTHREAD_CANCEL_ASYNCHRONOUS = 0,
00555 PTHREAD_CANCEL_DEFERRED = 1,
00556
00557
00558
00559
00560
00561 PTHREAD_PROCESS_PRIVATE = 0,
00562 PTHREAD_PROCESS_SHARED = 1,
00563
00564
00565
00566
00567 PTHREAD_BARRIER_SERIAL_THREAD = -1
00568 };
00569
00570
00571
00572
00573
00574
00575
00576
00577 #define PTHREAD_CANCELED ((void *) -1)
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587 #define PTHREAD_ONCE_INIT { PTW32_FALSE, -1 }
00588
00589 struct pthread_once_t_
00590 {
00591 int done;
00592 long started;
00593
00594 };
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604 #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
00605
00606 #define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)
00607
00608 #define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) -1)
00609
00610 #define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t) -1)
00611
00612
00613
00614
00615
00616 enum
00617 {
00618
00619 PTHREAD_MUTEX_FAST_NP,
00620 PTHREAD_MUTEX_RECURSIVE_NP,
00621 PTHREAD_MUTEX_ERRORCHECK_NP,
00622 PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP,
00623 PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP,
00624
00625 PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP,
00626 PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
00627 PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
00628 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
00629 };
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662 #if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C )
00663 # define __CLEANUP_C
00664 #endif
00665
00666 #if defined( __CLEANUP_SEH ) && defined(__GNUC__)
00667 #error ERROR [__FILE__, line __LINE__]: GNUC does not support SEH.
00668 #endif
00669
00670 typedef struct ptw32_cleanup_t ptw32_cleanup_t;
00671 typedef void (__cdecl *ptw32_cleanup_callback_t)(void *);
00672
00673 struct ptw32_cleanup_t
00674 {
00675 ptw32_cleanup_callback_t routine;
00676 void *arg;
00677 struct ptw32_cleanup_t *prev;
00678 };
00679
00680 #ifdef __CLEANUP_SEH
00681
00682
00683
00684
00685 #define pthread_cleanup_push( _rout, _arg ) \
00686 { \
00687 ptw32_cleanup_t _cleanup; \
00688 \
00689 _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); \
00690 _cleanup.arg = (_arg); \
00691 __try \
00692 { \
00693
00694 #define pthread_cleanup_pop( _execute ) \
00695 } \
00696 __finally \
00697 { \
00698 if( _execute || AbnormalTermination()) \
00699 { \
00700 (*(_cleanup.routine))( _cleanup.arg ); \
00701 } \
00702 } \
00703 }
00704
00705 #else
00706
00707 #ifdef __CLEANUP_C
00708
00709
00710
00711
00712
00713 #define pthread_cleanup_push( _rout, _arg ) \
00714 { \
00715 ptw32_cleanup_t _cleanup; \
00716 \
00717 ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \
00718
00719 #define pthread_cleanup_pop( _execute ) \
00720 (void) ptw32_pop_cleanup( _execute ); \
00721 }
00722
00723 #else
00724
00725 #ifdef __CLEANUP_CXX
00726
00727
00728
00729
00730
00731
00732 class PThreadCleanup {
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745 ptw32_cleanup_callback_t cleanUpRout;
00746 void * obj;
00747 int executeIt;
00748
00749 public:
00750 PThreadCleanup() :
00751 cleanUpRout( 0 ),
00752 obj( 0 ),
00753 executeIt( 0 )
00754
00755
00756
00757 {
00758 }
00759
00760 PThreadCleanup(
00761 ptw32_cleanup_callback_t routine,
00762 void * arg ) :
00763 cleanUpRout( routine ),
00764 obj( arg ),
00765 executeIt( 1 )
00766
00767
00768
00769 {
00770 }
00771
00772 ~PThreadCleanup()
00773 {
00774 if ( executeIt && ((void *) cleanUpRout != (void *) 0) )
00775 {
00776 (void) (*cleanUpRout)( obj );
00777 }
00778 }
00779
00780 void execute( int exec )
00781 {
00782 executeIt = exec;
00783 }
00784 };
00785
00786
00787
00788
00789
00790
00791
00792 #define pthread_cleanup_push( _rout, _arg ) \
00793 { \
00794 PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), \
00795 (void *) (_arg) );
00796
00797 #define pthread_cleanup_pop( _execute ) \
00798 cleanup.execute( _execute ); \
00799 }
00800
00801 #else
00802
00803 #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.
00804
00805 #endif
00806
00807 #endif
00808
00809 #endif
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822 PTW32_DLLPORT int pthread_attr_init (pthread_attr_t * attr);
00823
00824 PTW32_DLLPORT int pthread_attr_destroy (pthread_attr_t * attr);
00825
00826 PTW32_DLLPORT int pthread_attr_getdetachstate (const pthread_attr_t * attr,
00827 int *detachstate);
00828
00829 PTW32_DLLPORT int pthread_attr_getstackaddr (const pthread_attr_t * attr,
00830 void **stackaddr);
00831
00832 PTW32_DLLPORT int pthread_attr_getstacksize (const pthread_attr_t * attr,
00833 size_t * stacksize);
00834
00835 PTW32_DLLPORT int pthread_attr_setdetachstate (pthread_attr_t * attr,
00836 int detachstate);
00837
00838 PTW32_DLLPORT int pthread_attr_setstackaddr (pthread_attr_t * attr,
00839 void *stackaddr);
00840
00841 PTW32_DLLPORT int pthread_attr_setstacksize (pthread_attr_t * attr,
00842 size_t stacksize);
00843
00844 PTW32_DLLPORT int pthread_attr_getschedparam (const pthread_attr_t *attr,
00845 struct sched_param *param);
00846
00847 PTW32_DLLPORT int pthread_attr_setschedparam (pthread_attr_t *attr,
00848 const struct sched_param *param);
00849
00850 PTW32_DLLPORT int pthread_attr_setschedpolicy (pthread_attr_t *,
00851 int);
00852
00853 PTW32_DLLPORT int pthread_attr_getschedpolicy (pthread_attr_t *,
00854 int *);
00855
00856 PTW32_DLLPORT int pthread_attr_setinheritsched(pthread_attr_t * attr,
00857 int inheritsched);
00858
00859 PTW32_DLLPORT int pthread_attr_getinheritsched(pthread_attr_t * attr,
00860 int * inheritsched);
00861
00862 PTW32_DLLPORT int pthread_attr_setscope (pthread_attr_t *,
00863 int);
00864
00865 PTW32_DLLPORT int pthread_attr_getscope (const pthread_attr_t *,
00866 int *);
00867
00868
00869
00870
00871 PTW32_DLLPORT int pthread_create (pthread_t * tid,
00872 const pthread_attr_t * attr,
00873 void *(*start) (void *),
00874 void *arg);
00875
00876 PTW32_DLLPORT int pthread_detach (pthread_t tid);
00877
00878 PTW32_DLLPORT int pthread_equal (pthread_t t1,
00879 pthread_t t2);
00880
00881 PTW32_DLLPORT void pthread_exit (void *value_ptr);
00882
00883 PTW32_DLLPORT int pthread_join (pthread_t thread,
00884 void **value_ptr);
00885
00886 PTW32_DLLPORT pthread_t pthread_self (void);
00887
00888 PTW32_DLLPORT int pthread_cancel (pthread_t thread);
00889
00890 PTW32_DLLPORT int pthread_setcancelstate (int state,
00891 int *oldstate);
00892
00893 PTW32_DLLPORT int pthread_setcanceltype (int type,
00894 int *oldtype);
00895
00896 PTW32_DLLPORT void pthread_testcancel (void);
00897
00898 PTW32_DLLPORT int pthread_once (pthread_once_t * once_control,
00899 void (*init_routine) (void));
00900
00901 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
00902 PTW32_DLLPORT ptw32_cleanup_t *ptw32_pop_cleanup (int execute);
00903
00904 PTW32_DLLPORT void ptw32_push_cleanup (ptw32_cleanup_t * cleanup,
00905 void (*routine) (void *),
00906 void *arg);
00907 #endif
00908
00909
00910
00911
00912 PTW32_DLLPORT int pthread_key_create (pthread_key_t * key,
00913 void (*destructor) (void *));
00914
00915 PTW32_DLLPORT int pthread_key_delete (pthread_key_t key);
00916
00917 PTW32_DLLPORT int pthread_setspecific (pthread_key_t key,
00918 const void *value);
00919
00920 PTW32_DLLPORT void *pthread_getspecific (pthread_key_t key);
00921
00922
00923
00924
00925
00926 PTW32_DLLPORT int pthread_mutexattr_init (pthread_mutexattr_t * attr);
00927
00928 PTW32_DLLPORT int pthread_mutexattr_destroy (pthread_mutexattr_t * attr);
00929
00930 PTW32_DLLPORT int pthread_mutexattr_getpshared (const pthread_mutexattr_t
00931 * attr,
00932 int *pshared);
00933
00934 PTW32_DLLPORT int pthread_mutexattr_setpshared (pthread_mutexattr_t * attr,
00935 int pshared);
00936
00937 PTW32_DLLPORT int pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind);
00938 PTW32_DLLPORT int pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *kind);
00939
00940
00941
00942
00943 PTW32_DLLPORT int pthread_barrierattr_init (pthread_barrierattr_t * attr);
00944
00945 PTW32_DLLPORT int pthread_barrierattr_destroy (pthread_barrierattr_t * attr);
00946
00947 PTW32_DLLPORT int pthread_barrierattr_getpshared (const pthread_barrierattr_t
00948 * attr,
00949 int *pshared);
00950
00951 PTW32_DLLPORT int pthread_barrierattr_setpshared (pthread_barrierattr_t * attr,
00952 int pshared);
00953
00954
00955
00956
00957 PTW32_DLLPORT int pthread_mutex_init (pthread_mutex_t * mutex,
00958 const pthread_mutexattr_t * attr);
00959
00960 PTW32_DLLPORT int pthread_mutex_destroy (pthread_mutex_t * mutex);
00961
00962 PTW32_DLLPORT int pthread_mutex_lock (pthread_mutex_t * mutex);
00963
00964 PTW32_DLLPORT int pthread_mutex_timedlock(pthread_mutex_t *mutex,
00965 const struct timespec *abstime);
00966
00967 PTW32_DLLPORT int pthread_mutex_trylock (pthread_mutex_t * mutex);
00968
00969 PTW32_DLLPORT int pthread_mutex_unlock (pthread_mutex_t * mutex);
00970
00971
00972
00973
00974 PTW32_DLLPORT int pthread_spin_init (pthread_spinlock_t * lock, int pshared);
00975
00976 PTW32_DLLPORT int pthread_spin_destroy (pthread_spinlock_t * lock);
00977
00978 PTW32_DLLPORT int pthread_spin_lock (pthread_spinlock_t * lock);
00979
00980 PTW32_DLLPORT int pthread_spin_trylock (pthread_spinlock_t * lock);
00981
00982 PTW32_DLLPORT int pthread_spin_unlock (pthread_spinlock_t * lock);
00983
00984
00985
00986
00987 PTW32_DLLPORT int pthread_barrier_init (pthread_barrier_t * barrier,
00988 const pthread_barrierattr_t * attr,
00989 unsigned int count);
00990
00991 PTW32_DLLPORT int pthread_barrier_destroy (pthread_barrier_t * barrier);
00992
00993 PTW32_DLLPORT int pthread_barrier_wait (pthread_barrier_t * barrier);
00994
00995
00996
00997
00998 PTW32_DLLPORT int pthread_condattr_init (pthread_condattr_t * attr);
00999
01000 PTW32_DLLPORT int pthread_condattr_destroy (pthread_condattr_t * attr);
01001
01002 PTW32_DLLPORT int pthread_condattr_getpshared (const pthread_condattr_t * attr,
01003 int *pshared);
01004
01005 PTW32_DLLPORT int pthread_condattr_setpshared (pthread_condattr_t * attr,
01006 int pshared);
01007
01008
01009
01010
01011 PTW32_DLLPORT int pthread_cond_init (pthread_cond_t * cond,
01012 const pthread_condattr_t * attr);
01013
01014 PTW32_DLLPORT int pthread_cond_destroy (pthread_cond_t * cond);
01015
01016 PTW32_DLLPORT int pthread_cond_wait (pthread_cond_t * cond,
01017 pthread_mutex_t * mutex);
01018
01019 PTW32_DLLPORT int pthread_cond_timedwait (pthread_cond_t * cond,
01020 pthread_mutex_t * mutex,
01021 const struct timespec *abstime);
01022
01023 PTW32_DLLPORT int pthread_cond_signal (pthread_cond_t * cond);
01024
01025 PTW32_DLLPORT int pthread_cond_broadcast (pthread_cond_t * cond);
01026
01027
01028
01029
01030 PTW32_DLLPORT int pthread_setschedparam (pthread_t thread,
01031 int policy,
01032 const struct sched_param *param);
01033
01034 PTW32_DLLPORT int pthread_getschedparam (pthread_t thread,
01035 int *policy,
01036 struct sched_param *param);
01037
01038 PTW32_DLLPORT int pthread_setconcurrency (int);
01039
01040 PTW32_DLLPORT int pthread_getconcurrency (void);
01041
01042
01043
01044
01045 PTW32_DLLPORT int pthread_rwlock_init(pthread_rwlock_t *lock,
01046 const pthread_rwlockattr_t *attr);
01047
01048 PTW32_DLLPORT int pthread_rwlock_destroy(pthread_rwlock_t *lock);
01049
01050 PTW32_DLLPORT int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
01051
01052 PTW32_DLLPORT int pthread_rwlock_trywrlock(pthread_rwlock_t *);
01053
01054 PTW32_DLLPORT int pthread_rwlock_rdlock(pthread_rwlock_t *lock);
01055
01056 PTW32_DLLPORT int pthread_rwlock_timedrdlock(pthread_rwlock_t *lock,
01057 const struct timespec *abstime);
01058
01059 PTW32_DLLPORT int pthread_rwlock_wrlock(pthread_rwlock_t *lock);
01060
01061 PTW32_DLLPORT int pthread_rwlock_timedwrlock(pthread_rwlock_t *lock,
01062 const struct timespec *abstime);
01063
01064 PTW32_DLLPORT int pthread_rwlock_unlock(pthread_rwlock_t *lock);
01065
01066 PTW32_DLLPORT int pthread_rwlockattr_init (pthread_rwlockattr_t * attr);
01067
01068 PTW32_DLLPORT int pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr);
01069
01070 PTW32_DLLPORT int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr,
01071 int *pshared);
01072
01073 PTW32_DLLPORT int pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
01074 int pshared);
01075
01076 #if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1
01077
01078
01079
01080
01081
01082 PTW32_DLLPORT int pthread_kill(pthread_t thread, int sig);
01083
01084
01085
01086
01087
01088
01089
01090
01091 PTW32_DLLPORT int pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr,
01092 int kind);
01093 PTW32_DLLPORT int pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr,
01094 int *kind);
01095
01096
01097
01098
01099 PTW32_DLLPORT int pthread_delay_np (struct timespec * interval);
01100 PTW32_DLLPORT int pthread_num_processors_np(void);
01101
01102
01103
01104
01105
01106 PTW32_DLLPORT int pthread_win32_process_attach_np(void);
01107 PTW32_DLLPORT int pthread_win32_process_detach_np(void);
01108 PTW32_DLLPORT int pthread_win32_thread_attach_np(void);
01109 PTW32_DLLPORT int pthread_win32_thread_detach_np(void);
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119 PTW32_DLLPORT void * pthread_timechange_handler_np(void *);
01120
01121 #endif
01122
01123 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
01124
01125
01126
01127
01128 PTW32_DLLPORT HANDLE pthread_getw32threadhandle_np(pthread_t thread);
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146 PTW32_DLLPORT int pthreadCancelableWait (HANDLE waitHandle);
01147 PTW32_DLLPORT int pthreadCancelableTimedWait (HANDLE waitHandle,
01148 DWORD timeout);
01149
01150 #endif
01151
01152
01153
01154
01155 #ifndef _UWIN
01156 # if defined(NEED_ERRNO)
01157 PTW32_DLLPORT int * _errno( void );
01158 # else
01159 # ifndef errno
01160 # if (defined(_MT) || defined(_DLL))
01161 __declspec(dllimport) extern int * __cdecl _errno(void);
01162 # define errno (*_errno())
01163 # endif
01164 # endif
01165 # endif
01166 #endif
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177 #if !defined(__MINGW32__)
01178 #define strtok_r( _s, _sep, _lasts ) \
01179 ( *(_lasts) = strtok( (_s), (_sep) ) )
01180 #endif
01181
01182 #define asctime_r( _tm, _buf ) \
01183 ( strcpy( (_buf), asctime( (_tm) ) ), \
01184 (_buf) )
01185
01186 #define ctime_r( _clock, _buf ) \
01187 ( strcpy( (_buf), ctime( (_clock) ) ), \
01188 (_buf) )
01189
01190 #define gmtime_r( _clock, _result ) \
01191 ( *(_result) = *gmtime( (_clock) ), \
01192 (_result) )
01193
01194 #define localtime_r( _clock, _result ) \
01195 ( *(_result) = *localtime( (_clock) ), \
01196 (_result) )
01197
01198 #define rand_r( _seed ) \
01199 ( _seed == _seed? rand() : rand() )
01200
01201
01202 #ifdef __cplusplus
01203
01204
01205
01206
01207 class ptw32_exception {};
01208 class ptw32_exception_cancel : public ptw32_exception {};
01209 class ptw32_exception_exit : public ptw32_exception {};
01210
01211 #endif
01212
01213 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
01214
01215
01216
01217
01218
01219 PTW32_DLLPORT DWORD ptw32_get_exception_services_code(void);
01220
01221 #endif
01222
01223 #ifndef PTW32_BUILD
01224
01225 #ifdef __CLEANUP_SEH
01226
01227
01228
01229
01230
01231 #define __except( E ) \
01232 __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \
01233 ? EXCEPTION_CONTINUE_SEARCH : ( E ) )
01234
01235 #endif
01236
01237 #ifdef __CLEANUP_CXX
01238
01239
01240
01241
01242
01243 #ifdef _MSC_VER
01244
01245
01246
01247
01248
01249 #ifndef PtW32NoCatchWarn
01250
01251 #pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.")
01252 #pragma message("------------------------------------------------------------------")
01253 #pragma message("When compiling applications with MSVC++ and C++ exception handling:")
01254 #pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads")
01255 #pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread")
01256 #pragma message(" cancelation and pthread_exit to work. For example:")
01257 #pragma message("")
01258 #pragma message(" #ifdef PtW32CatchAll")
01259 #pragma message(" PtW32CatchAll")
01260 #pragma message(" #else")
01261 #pragma message(" catch(...)")
01262 #pragma message(" #endif")
01263 #pragma message(" {")
01264 #pragma message(" ")
01265 #pragma message(" }")
01266 #pragma message("------------------------------------------------------------------")
01267
01268 #endif
01269
01270 #define PtW32CatchAll \
01271 catch( ptw32_exception & ) { throw; } \
01272 catch( ... )
01273
01274 #else
01275
01276 #define catch( E ) \
01277 catch( ptw32_exception & ) { throw; } \
01278 catch( E )
01279
01280 #endif
01281
01282 #endif
01283
01284 #endif
01285
01286 #ifdef __cplusplus
01287 }
01288 #endif
01289
01290 #ifdef PTW32__HANDLE_DEF
01291 # undef HANDLE
01292 #endif
01293 #ifdef PTW32__DWORD_DEF
01294 # undef DWORD
01295 #endif
01296
01297 #undef PTW32_LEVEL
01298 #undef PTW32_LEVEL_MAX
01299
01300 #endif