33 #if !defined( PTHREAD_H ) 40 #define PTW32_VERSION 2,8,0,0 41 #define PTW32_VERSION_STRING "2, 8, 0, 0\0" 73 #if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C ) 77 #if defined( __CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined(PTW32_RC_MSC)) 78 #error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler. 88 #if defined(_POSIX_SOURCE) 93 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 99 #if defined(INCLUDE_NP) 101 #define PTW32_LEVEL 2 105 #define PTW32_LEVEL_MAX 3 107 #if !defined(PTW32_LEVEL) 108 #define PTW32_LEVEL PTW32_LEVEL_MAX 113 # define HAVE_STRUCT_TIMESPEC 1 114 # define HAVE_SIGNAL_H 1 115 # undef HAVE_CONFIG_H 116 # pragma comment(lib, "pthread") 193 #if defined(__MINGW32__) && defined(__cplusplus) 194 #define PTW32_INCLUDE_WINDOWS_H 197 #ifdef PTW32_INCLUDE_WINDOWS_H 201 #if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__) 205 typedef unsigned long DWORD_PTR;
243 #ifndef PTW32_CONFIG_H 248 # if defined(_UWIN) || defined(__MINGW32__) 257 #if PTW32_LEVEL >= PTW32_LEVEL_MAX 259 #include "need_errno.h" 273 # define ETIMEDOUT 10060 282 # define EDEADLK EDEADLOCK 294 #ifndef PTW32_INCLUDE_WINDOWS_H 296 # define PTW32__HANDLE_DEF 297 # define HANDLE void * 300 # define PTW32__DWORD_DEF 301 # define DWORD unsigned long 305 #ifndef HAVE_STRUCT_TIMESPEC 306 #define HAVE_STRUCT_TIMESPEC 1 318 #define SIG_UNBLOCK 1 322 #define SIG_SETMASK 2 420 #undef _POSIX_THREADS 421 #define _POSIX_THREADS 200112L 423 #undef _POSIX_READER_WRITER_LOCKS 424 #define _POSIX_READER_WRITER_LOCKS 200112L 426 #undef _POSIX_SPIN_LOCKS 427 #define _POSIX_SPIN_LOCKS 200112L 429 #undef _POSIX_BARRIERS 430 #define _POSIX_BARRIERS 200112L 432 #undef _POSIX_THREAD_SAFE_FUNCTIONS 433 #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L 435 #undef _POSIX_THREAD_ATTR_STACKSIZE 436 #define _POSIX_THREAD_ATTR_STACKSIZE 200112L 441 #undef _POSIX_THREAD_ATTR_STACKADDR 442 #define _POSIX_THREAD_ATTR_STACKADDR -1 444 #undef _POSIX_THREAD_PRIO_INHERIT 445 #define _POSIX_THREAD_PRIO_INHERIT -1 447 #undef _POSIX_THREAD_PRIO_PROTECT 448 #define _POSIX_THREAD_PRIO_PROTECT -1 451 #undef _POSIX_THREAD_PRIORITY_SCHEDULING 452 #define _POSIX_THREAD_PRIORITY_SCHEDULING -1 454 #undef _POSIX_THREAD_PROCESS_SHARED 455 #define _POSIX_THREAD_PROCESS_SHARED -1 490 #undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS 491 #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 493 #undef PTHREAD_DESTRUCTOR_ITERATIONS 494 #define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS 496 #undef _POSIX_THREAD_KEYS_MAX 497 #define _POSIX_THREAD_KEYS_MAX 128 499 #undef PTHREAD_KEYS_MAX 500 #define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX 502 #undef PTHREAD_STACK_MIN 503 #define PTHREAD_STACK_MIN 0 505 #undef _POSIX_THREAD_THREADS_MAX 506 #define _POSIX_THREAD_THREADS_MAX 64 509 #undef PTHREAD_THREADS_MAX 510 #define PTHREAD_THREADS_MAX 2019 512 #undef _POSIX_SEM_NSEMS_MAX 513 #define _POSIX_SEM_NSEMS_MAX 256 517 #define SEM_NSEMS_MAX 1024 519 #undef _POSIX_SEM_VALUE_MAX 520 #define _POSIX_SEM_VALUE_MAX 32767 523 #define SEM_VALUE_MAX INT_MAX 526 #if __GNUC__ && ! defined (__declspec) 527 # error Please upgrade your GNU compiler to one that supports __declspec. 536 #ifndef PTW32_STATIC_LIB 538 # define PTW32_DLLPORT __declspec (dllexport) 540 # define PTW32_DLLPORT __declspec (dllimport) 543 # define PTW32_DLLPORT 556 #define PTW32_CDECL __cdecl 558 #if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX 559 # include <sys/types.h> 645 #define PTHREAD_CANCELED ((void *) -1) 655 #define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0} 673 #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1) 674 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2) 675 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3) 680 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER 681 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER 683 #define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1) 685 #define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) -1) 687 #define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t) -1) 711 #if defined(_MSC_VER) 713 #pragma warning( disable : 4229 ) 718 #if defined(_MSC_VER) 719 #pragma warning( default : 4229 ) 734 #define pthread_cleanup_push( _rout, _arg ) \ 736 ptw32_cleanup_t _cleanup; \ 738 _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); \ 739 _cleanup.arg = (_arg); \ 743 #define pthread_cleanup_pop( _execute ) \ 747 if( _execute || AbnormalTermination()) \ 749 (*(_cleanup.routine))( _cleanup.arg ); \ 762 #define pthread_cleanup_push( _rout, _arg ) \ 764 ptw32_cleanup_t _cleanup; \ 766 ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \ 768 #define pthread_cleanup_pop( _execute ) \ 769 (void) ptw32_pop_cleanup( _execute ); \ 781 class PThreadCleanup {
794 ptw32_cleanup_callback_t cleanUpRout;
810 ptw32_cleanup_callback_t routine,
812 cleanUpRout( routine ),
823 if ( executeIt && ((
void *) cleanUpRout != (
void *) 0) )
825 (void) (*cleanUpRout)( obj );
829 void execute(
int exec )
841 #define pthread_cleanup_push( _rout, _arg ) \ 843 PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), \ 846 #define pthread_cleanup_pop( _execute ) \ 847 cleanup.execute( _execute ); \ 852 #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined. 921 const pthread_attr_t * attr,
922 void *(*start) (
void *),
948 void (*init_routine) (
void));
950 #if PTW32_LEVEL >= PTW32_LEVEL_MAX 954 void (*routine) (
void *),
962 void (*destructor) (
void *));
1007 const pthread_mutexattr_t * attr);
1037 const pthread_barrierattr_t * attr,
1038 unsigned int count);
1061 const pthread_condattr_t * attr);
1066 pthread_mutex_t * mutex);
1069 pthread_mutex_t * mutex,
1095 const pthread_rwlockattr_t *attr);
1125 #if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 1181 #if PTW32_LEVEL >= PTW32_LEVEL_MAX 1214 # if defined(NEED_ERRNO) 1218 # if (defined(_MT) || defined(_DLL)) 1219 __declspec(dllimport) extern
int * __cdecl _errno(
void);
1220 # define errno (*_errno()) 1235 #if !defined(__MINGW32__) 1236 #define strtok_r( _s, _sep, _lasts ) \ 1237 ( *(_lasts) = strtok( (_s), (_sep) ) ) 1240 #define asctime_r( _tm, _buf ) \ 1241 ( strcpy( (_buf), asctime( (_tm) ) ), \ 1244 #define ctime_r( _clock, _buf ) \ 1245 ( strcpy( (_buf), ctime( (_clock) ) ), \ 1248 #define gmtime_r( _clock, _result ) \ 1249 ( *(_result) = *gmtime( (_clock) ), \ 1252 #define localtime_r( _clock, _result ) \ 1253 ( *(_result) = *localtime( (_clock) ), \ 1256 #define rand_r( _seed ) \ 1257 ( _seed == _seed? rand() : rand() ) 1263 #if defined(__BORLANDC__) 1264 # define _ftime ftime 1265 # define _timeb timeb 1273 class ptw32_exception {};
1274 class ptw32_exception_cancel :
public ptw32_exception {};
1275 class ptw32_exception_exit :
public ptw32_exception {};
1279 #if PTW32_LEVEL >= PTW32_LEVEL_MAX 1291 #ifdef __CLEANUP_SEH 1297 #define __except( E ) \ 1298 __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \ 1299 ? EXCEPTION_CONTINUE_SEARCH : ( E ) ) 1303 #ifdef __CLEANUP_CXX 1315 #ifndef PtW32NoCatchWarn 1317 #pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.") 1318 #pragma message("------------------------------------------------------------------") 1319 #pragma message("When compiling applications with MSVC++ and C++ exception handling:") 1320 #pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads") 1321 #pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread") 1322 #pragma message(" cancelation and pthread_exit to work. For example:") 1324 #pragma message(" #ifdef PtW32CatchAll") 1325 #pragma message(" PtW32CatchAll") 1326 #pragma message(" #else") 1327 #pragma message(" catch(...)") 1328 #pragma message(" #endif") 1329 #pragma message(" {") 1330 #pragma message(" ") 1331 #pragma message(" }") 1332 #pragma message("------------------------------------------------------------------") 1336 #define PtW32CatchAll \ 1337 catch( ptw32_exception & ) { throw; } \ 1342 #define catch( E ) \ 1343 catch( ptw32_exception & ) { throw; } \ 1356 #ifdef PTW32__HANDLE_DEF 1359 #ifdef PTW32__DWORD_DEF 1364 #undef PTW32_LEVEL_MAX PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy(pthread_attr_t *attr)
PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock)
PTW32_DLLPORT int PTW32_CDECL pthread_mutex_lock(pthread_mutex_t *mutex)
PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock, const struct timespec *abstime)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
PTW32_DLLPORT int PTW32_CDECL pthread_once(pthread_once_t *once_control, void(*init_routine)(void))
PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock)
PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate(int state, int *oldstate)
PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void)
PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock(pthread_spinlock_t *lock)
PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock(pthread_spinlock_t *lock)
PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind)
PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self(void)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread)
PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal(pthread_cond_t *cond)
struct pthread_condattr_t_ * pthread_condattr_t
Header file for Config class definitions.
PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait(pthread_barrier_t *barrier)
PTW32_DLLPORT int PTW32_CDECL pthread_key_delete(pthread_key_t key)
PTW32_DLLPORT int PTW32_CDECL pthread_mutex_trylock(pthread_mutex_t *mutex)
PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared)
PTW32_DLLPORT int PTW32_CDECL pthread_detach(pthread_t tid)
PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init(pthread_condattr_t *attr)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched)
PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype(int type, int *oldtype)
PTW32_DLLPORT void *PTW32_CDECL pthread_getspecific(pthread_key_t key)
PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *kind)
PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy(pthread_condattr_t *attr)
struct pthread_barrierattr_t_ * pthread_barrierattr_t
PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
PTW32_DLLPORT int PTW32_CDECL pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
struct pthread_rwlock_t_ * pthread_rwlock_t
PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, int *pshared)
PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared)
PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
PTW32_DLLPORT int PTW32_CDECL pthread_mutex_unlock(pthread_mutex_t *mutex)
PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void)
struct pthread_barrier_t_ * pthread_barrier_t
PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void)
PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast(pthread_cond_t *cond)
PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void)
PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared)
PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait(HANDLE waitHandle, DWORD timeout)
PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared)
struct pthread_key_t_ * pthread_key_t
struct ptw32_cleanup_t * prev
PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy(pthread_barrier_t *barrier)
PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup(ptw32_cleanup_t *cleanup, void(*routine)(void *), void *arg)
PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy(pthread_cond_t *cond)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope(const pthread_attr_t *, int *)
ptw32_cleanup_callback_t routine
PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared)
PTW32_DLLPORT int PTW32_CDECL pthread_setspecific(pthread_key_t key, const void *value)
PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void)
PTW32_DLLPORT ptw32_cleanup_t *PTW32_CDECL ptw32_pop_cleanup(int execute)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy(pthread_attr_t *, int)
struct pthread_spinlock_t_ * pthread_spinlock_t
PTW32_DLLPORT int PTW32_CDECL pthread_cancel(pthread_t thread)
PTW32_DLLPORT int PTW32_CDECL pthread_join(pthread_t thread, void **value_ptr)
PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait(HANDLE waitHandle)
PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock(pthread_spinlock_t *lock)
PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init(pthread_mutexattr_t *attr)
struct pthread_cond_t_ * pthread_cond_t
PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *)
struct pthread_attr_t_ * pthread_attr_t
PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency(int)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy(pthread_attr_t *, int *)
PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy(pthread_barrierattr_t *attr)
PTW32_DLLPORT int PTW32_CDECL pthread_create(pthread_t *tid, const pthread_attr_t *attr, void *(*start)(void *), void *arg)
PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init(pthread_barrierattr_t *attr)
PTW32_DLLPORT void *PTW32_CDECL pthread_timechange_handler_np(void *)
PTW32_DLLPORT int PTW32_CDECL pthread_key_create(pthread_key_t *key, void(*destructor)(void *))
PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy(pthread_mutex_t *mutex)
PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy(pthread_spinlock_t *lock)
PTW32_DLLPORT int PTW32_CDECL pthread_equal(pthread_t t1, pthread_t t2)
PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock)
struct pthread_mutex_t_ * pthread_mutex_t
PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock, const struct timespec *abstime)
PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void)
PTW32_DLLPORT void PTW32_CDECL pthread_testcancel(void)
PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency(void)
PTW32_DLLPORT int PTW32_CDECL pthread_delay_np(struct timespec *interval)
struct pthread_mutexattr_t_ * pthread_mutexattr_t
PTW32_DLLPORT int PTW32_CDECL pthread_attr_init(pthread_attr_t *attr)
PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock, const pthread_rwlockattr_t *attr)
struct pthread_rwlockattr_t_ * pthread_rwlockattr_t
PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int)
PTW32_DLLPORT int PTW32_CDECL pthread_spin_init(pthread_spinlock_t *lock, int pshared)
PTW32_DLLPORT void PTW32_CDECL pthread_exit(void *value_ptr)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(pthread_attr_t *attr, int *inheritsched)
PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t *attr, int *kind)
PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope(pthread_attr_t *, int)