diff -uNr a/GNUmakefile b/GNUmakefile --- a/GNUmakefile Wed Jun 23 06:18:51 2010 +++ b/GNUmakefile Thu Jun 24 23:44:21 2010 @@ -64,7 +64,7 @@ RCFLAGS = --include-dir=. # Uncomment this if config.h defines RETAIN_WSALASTERROR -#LFLAGS = -lwsock32 +#LFLAGS = -lws2_32 # ---------------------------------------------------------------------- # The library can be built with some alternative behaviour to diff -uNr a/Makefile b/Makefile --- a/Makefile Wed Jun 23 06:18:51 2010 +++ b/Makefile Thu Jun 24 23:20:10 2010 @@ -27,7 +27,7 @@ OPTIM = /O2 /Ob2 OPTIMD = -CFLAGS = /W3 /MD /nologo /I. /D_WIN32_WINNT=0x400 /DHAVE_CONFIG_H +CFLAGS = /W3 /nologo /I. /D_WIN32_WINNT=0x400 /DHAVE_CONFIG_H CFLAGSD = /Zi $(CFLAGS) # Uncomment this if config.h defines RETAIN_WSALASTERROR @@ -399,50 +399,50 @@ @ nmake clean VC-inlined-debug VCE: - @ nmake /nologo EHFLAGS="$(OPTIM) $(VCEFLAGS)" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VER).dll + @ nmake /nologo EHFLAGS="$(OPTIM) /MD $(VCEFLAGS)" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VER).dll VCE-debug: - @ nmake /nologo EHFLAGS="$(OPTIMD) $(VCEFLAGSD)" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VERD).dll + @ nmake /nologo EHFLAGS="$(OPTIMD) /MDd $(VCEFLAGSD)" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VERD).dll VSE: - @ nmake /nologo EHFLAGS="$(OPTIM) $(VSEFLAGS)" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VER).dll + @ nmake /nologo EHFLAGS="$(OPTIM) /MD $(VSEFLAGS)" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VER).dll VSE-debug: - @ nmake /nologo EHFLAGS="$(OPTIMD) $(VSEFLAGSD)" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VERD).dll + @ nmake /nologo EHFLAGS="$(OPTIMD) /MDd $(VSEFLAGSD)" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VERD).dll VC: - @ nmake /nologo EHFLAGS="$(OPTIM) $(VCFLAGS)" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).dll + @ nmake /nologo EHFLAGS="$(OPTIM) /MD $(VCFLAGS)" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).dll VC-debug: - @ nmake /nologo EHFLAGS="$(OPTIMD) $(VCFLAGSD)" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).dll + @ nmake /nologo EHFLAGS="$(OPTIMD) /MDd $(VCFLAGSD)" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).dll # # The so-called inlined DLL is just a single translation unit with # inlining optimisation turned on. # VCE-inlined: - @ nmake /nologo EHFLAGS="$(OPTIM) $(VCEFLAGS) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VER).stamp + @ nmake /nologo EHFLAGS="$(OPTIM) /MD $(VCEFLAGS) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VER).stamp VCE-inlined-debug: - @ nmake /nologo EHFLAGS="$(OPTIMD) $(VCEFLAGSD) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VERD).stamp + @ nmake /nologo EHFLAGS="$(OPTIMD) /MDd $(VCEFLAGSD) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VERD).stamp VSE-inlined: - @ nmake /nologo EHFLAGS="$(OPTIM) $(VSEFLAGS) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VER).stamp + @ nmake /nologo EHFLAGS="$(OPTIM) /MD $(VSEFLAGS) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VER).stamp VSE-inlined-debug: - @ nmake /nologo EHFLAGS="$(OPTIMD) $(VSEFLAGSD) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VERD).stamp + @ nmake /nologo EHFLAGS="$(OPTIMD) /MDd $(VSEFLAGSD) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VERD).stamp VC-inlined: - @ nmake /nologo EHFLAGS="$(OPTIM) $(VCFLAGS) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).stamp + @ nmake /nologo EHFLAGS="$(OPTIM) /MD $(VCFLAGS) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).stamp VC-inlined-debug: - nmake /nologo EHFLAGS="$(OPTIMD) $(VCFLAGSD) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).stamp + nmake /nologo EHFLAGS="$(OPTIMD) /MDd $(VCFLAGSD) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).stamp VC-static: - @ nmake /nologo EHFLAGS="$(OPTIM) $(VCFLAGS) /DPTW32_BUILD_INLINED /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).static + @ nmake /nologo EHFLAGS="$(OPTIM) /MT $(VCFLAGS) /DPTW32_BUILD_INLINED /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).static VC-static-debug: - @ nmake /nologo EHFLAGS="$(OPTIMD) $(VCFLAGSD) /DPTW32_BUILD_INLINED /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).static + @ nmake /nologo EHFLAGS="$(OPTIMD) /MTd $(VCFLAGSD) /DPTW32_BUILD_INLINED /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).static realclean: clean if exist pthread*.dll del pthread*.dll diff -uNr a/config.h b/config.h --- a/config.h Wed Jun 23 06:18:51 2010 +++ b/config.h Thu Jun 24 23:20:10 2010 @@ -124,6 +124,9 @@ #ifdef __MINGW32__ #define HAVE_MODE_T +#ifdef _WIN64 +#define HAVE_STRUCT_TIMESPEC 1 +#endif #endif #ifdef __BORLANDC__ diff -uNr a/create.c b/create.c --- a/create.c Sat Jan 6 13:44:40 2007 +++ b/create.c Thu Jun 24 23:20:10 2010 @@ -90,7 +90,7 @@ int result = EAGAIN; int run = PTW32_TRUE; ThreadParms *parms = NULL; - long stackSize; + size_t stackSize; int priority; pthread_t self; diff -uNr a/implement.h b/implement.h --- a/implement.h Wed Jun 23 06:18:51 2010 +++ b/implement.h Thu Jun 24 23:44:11 2010 @@ -77,14 +77,37 @@ #include "sched.h" #if defined(HAVE_C_INLINE) || defined(__cplusplus) -#define INLINE inline +# define INLINE inline +# ifdef PTW32_BUILD_INLINED +# define EXTERN_INLINE inline +# else +# define EXTERN_INLINE +# endif #else -#define INLINE +# define INLINE +# define EXTERN_INLINE +#endif + +#if (defined(_MSC_VER) && _MSC_VER < 1200 || defined(__DMC__)) && !defined(_WIN64) +/* + * VC++5.0 or early compiler's header has no INT_PTR/UINT_PTR types. + */ +#define INT_PTR long +#define UINT_PTR unsigned long +#endif + +#if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__) +/* + * VC++6.0 or early compiler's header has no DWORD_PTR/LONG_PTR/ULONG_PTR types. + */ +#define DWORD_PTR UINT_PTR +#define LONG_PTR INT_PTR +#define ULONG_PTR UINT_PTR #endif #if defined (__MINGW32__) || (_MSC_VER >= 1300) -#define PTW32_INTERLOCKED_LONG long -#define PTW32_INTERLOCKED_LPLONG long* +#define PTW32_INTERLOCKED_LONG LONG +#define PTW32_INTERLOCKED_LPLONG LPLONG #else #define PTW32_INTERLOCKED_LONG PVOID #define PTW32_INTERLOCKED_LPLONG PVOID* @@ -219,7 +242,7 @@ }; /* - * Possible values, other than PTW32_OBJECT_INVALID, + * Possible values, other than PTW32_SPIN_INVALID, * for the "interlock" element in a spinlock. * * In this implementation, when a spinlock is initialised, @@ -235,13 +258,14 @@ * "u.cpus" isn't used for anything yet, but could be used at * some point to optimise spinlock behaviour. */ +#define PTW32_SPIN_INVALID (0) #define PTW32_SPIN_UNLOCKED (1) #define PTW32_SPIN_LOCKED (2) #define PTW32_SPIN_USE_MUTEX (3) struct pthread_spinlock_t_ { - long interlock; /* Locking element for multi-cpus. */ + LONG interlock; /* Locking element for multi-cpus. */ union { int cpus; /* No. of cpus if multi cpus, or */ @@ -256,9 +280,9 @@ { struct ptw32_mcs_node_t_ **lock; /* ptr to tail of queue */ struct ptw32_mcs_node_t_ *next; /* ptr to successor in queue */ - LONG readyFlag; /* set after lock is released by + LONG_PTR readyFlag; /* set after lock is released by predecessor */ - LONG nextFlag; /* set after 'next' ptr is set by + LONG_PTR nextFlag; /* set after 'next' ptr is set by successor */ }; @@ -268,8 +292,8 @@ struct pthread_barrier_t_ { - unsigned int nCurrentBarrierHeight; - unsigned int nInitialBarrierHeight; + ULONG nCurrentBarrierHeight; + ULONG nInitialBarrierHeight; int pshared; sem_t semBarrierBreeched; void * lock; /* MCS lock */ @@ -567,6 +591,7 @@ int ptw32_cond_check_need_init (pthread_cond_t * cond); int ptw32_mutex_check_need_init (pthread_mutex_t * mutex); int ptw32_rwlock_check_need_init (pthread_rwlock_t * rwlock); + int ptw32_spinlock_check_need_init (pthread_spinlock_t * lock); PTW32_INTERLOCKED_LONG WINAPI ptw32_InterlockedCompareExchange (PTW32_INTERLOCKED_LPLONG location, @@ -663,8 +688,8 @@ # endif # endif #else -# include -# endif +# include +#endif /* @@ -672,11 +697,15 @@ * See ptw32_InterlockedCompareExchange.c */ #ifndef PTW32_INTERLOCKED_COMPARE_EXCHANGE -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE ptw32_interlocked_compare_exchange -# endif +# ifdef _WIN64 +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange +# else +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE ptw32_interlocked_compare_exchange +# endif +#endif #ifndef PTW32_INTERLOCKED_EXCHANGE -#define PTW32_INTERLOCKED_EXCHANGE InterlockedExchange +# define PTW32_INTERLOCKED_EXCHANGE InterlockedExchange #endif diff -uNr a/pthread.h b/pthread.h --- a/pthread.h Wed Jun 23 06:18:51 2010 +++ b/pthread.h Thu Jun 24 23:20:10 2010 @@ -198,12 +198,6 @@ #include #endif -#if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__) -/* - * VC++6.0 or early compiler's header has no DWORD_PTR type. - */ -typedef unsigned long DWORD_PTR; -#endif /* * ----------------- * autoconf switches @@ -248,6 +242,9 @@ # if defined(_UWIN) || defined(__MINGW32__) # define HAVE_MODE_T # endif +# if defined(__MINGW32__) && defined(_WIN64) +# define HAVE_STRUCT_TIMESPEC 1 +# endif #endif /* @@ -1227,6 +1224,7 @@ # endif #endif +#if 0 /* * WIN32 C runtime library had been made thread-safe * without affecting the user interface. Provide @@ -1266,6 +1264,7 @@ #define rand_r( _seed ) \ ( _seed == _seed? rand() : rand() ) +#endif /* * Some compiler environments don't define some things. diff -uNr a/pthread_barrier_wait.c b/pthread_barrier_wait.c --- a/pthread_barrier_wait.c Wed Jun 23 06:18:52 2010 +++ b/pthread_barrier_wait.c Thu Jun 24 23:20:10 2010 @@ -87,8 +87,8 @@ result = ptw32_semwait (&(b->semBarrierBreeched)); } - if ((PTW32_INTERLOCKED_LONG)InterlockedIncrement((LPLONG)&b->nCurrentBarrierHeight) - == (PTW32_INTERLOCKED_LONG)b->nInitialBarrierHeight) + if ((ULONG)InterlockedIncrement((LPLONG)&b->nCurrentBarrierHeight) + == b->nInitialBarrierHeight) { /* * We are the last thread to cross this barrier diff -uNr a/pthread_cancel.c b/pthread_cancel.c --- a/pthread_cancel.c Wed Jun 23 06:18:52 2010 +++ b/pthread_cancel.c Thu Jun 24 23:20:10 2010 @@ -47,7 +47,7 @@ } static void CALLBACK -ptw32_cancel_callback (DWORD unused) +ptw32_cancel_callback (DWORD_PTR unused) { ptw32_throw (PTW32_EPS_CANCEL); diff -uNr a/pthread_exit.c b/pthread_exit.c --- a/pthread_exit.c Tue May 15 13:46:42 2007 +++ b/pthread_exit.c Thu Jun 24 23:20:10 2010 @@ -89,7 +89,7 @@ */ #if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) - _endthreadex ((unsigned) value_ptr); + _endthreadex ((unsigned)(UINT_PTR) value_ptr); #else _endthread (); #endif diff -uNr a/pthread_mutex_lock.c b/pthread_mutex_lock.c --- a/pthread_mutex_lock.c Tue May 15 13:46:42 2007 +++ b/pthread_mutex_lock.c Thu Jun 24 23:20:10 2010 @@ -72,11 +72,11 @@ if (mx->kind == PTHREAD_MUTEX_NORMAL) { - if ((LONG) PTW32_INTERLOCKED_EXCHANGE( + if (PTW32_INTERLOCKED_EXCHANGE( (LPLONG) &mx->lock_idx, (LONG) 1) != 0) { - while ((LONG) PTW32_INTERLOCKED_EXCHANGE( + while (PTW32_INTERLOCKED_EXCHANGE( (LPLONG) &mx->lock_idx, (LONG) -1) != 0) { @@ -92,7 +92,7 @@ { pthread_t self = pthread_self(); - if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( + if ((LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, (PTW32_INTERLOCKED_LONG) 1, (PTW32_INTERLOCKED_LONG) 0) == 0) @@ -115,7 +115,7 @@ } else { - while ((LONG) PTW32_INTERLOCKED_EXCHANGE( + while (PTW32_INTERLOCKED_EXCHANGE( (LPLONG) &mx->lock_idx, (LONG) -1) != 0) { diff -uNr a/pthread_mutex_timedlock.c b/pthread_mutex_timedlock.c --- a/pthread_mutex_timedlock.c Mon Apr 25 14:42:42 2005 +++ b/pthread_mutex_timedlock.c Thu Jun 24 23:20:10 2010 @@ -134,11 +134,11 @@ if (mx->kind == PTHREAD_MUTEX_NORMAL) { - if ((LONG) PTW32_INTERLOCKED_EXCHANGE( + if (PTW32_INTERLOCKED_EXCHANGE( (LPLONG) &mx->lock_idx, (LONG) 1) != 0) { - while ((LONG) PTW32_INTERLOCKED_EXCHANGE( + while (PTW32_INTERLOCKED_EXCHANGE( (LPLONG) &mx->lock_idx, (LONG) -1) != 0) { @@ -153,7 +153,7 @@ { pthread_t self = pthread_self(); - if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( + if ((LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, (PTW32_INTERLOCKED_LONG) 1, (PTW32_INTERLOCKED_LONG) 0) == 0) @@ -176,7 +176,7 @@ } else { - while ((LONG) PTW32_INTERLOCKED_EXCHANGE( + while (PTW32_INTERLOCKED_EXCHANGE( (LPLONG) &mx->lock_idx, (LONG) -1) != 0) { diff -uNr a/pthread_mutex_unlock.c b/pthread_mutex_unlock.c --- a/pthread_mutex_unlock.c Tue Jan 25 07:58:21 2005 +++ b/pthread_mutex_unlock.c Thu Jun 24 23:20:10 2010 @@ -61,8 +61,8 @@ { LONG idx; - idx = (LONG) PTW32_INTERLOCKED_EXCHANGE ((LPLONG) &mx->lock_idx, - (LONG) 0); + idx = PTW32_INTERLOCKED_EXCHANGE ((LPLONG) &mx->lock_idx, + (LONG) 0); if (idx != 0) { if (idx < 0) @@ -93,8 +93,8 @@ { mx->ownerThread.p = NULL; - if ((LONG) PTW32_INTERLOCKED_EXCHANGE ((LPLONG) &mx->lock_idx, - (LONG) 0) < 0) + if (PTW32_INTERLOCKED_EXCHANGE ((LPLONG) &mx->lock_idx, + (LONG) 0) < 0) { /* Someone may be waiting on that mutex */ if (SetEvent (mx->event) == 0) diff -uNr a/pthread_spin_destroy.c b/pthread_spin_destroy.c --- a/pthread_spin_destroy.c Sat Jan 1 14:36:17 2005 +++ b/pthread_spin_destroy.c Thu Jun 24 23:20:10 2010 @@ -55,13 +55,11 @@ { result = pthread_mutex_destroy (&(s->u.mutex)); } - else if ((PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED != - PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_LPLONG) - & (s->interlock), - (PTW32_INTERLOCKED_LONG) - PTW32_OBJECT_INVALID, - (PTW32_INTERLOCKED_LONG) - PTW32_SPIN_UNLOCKED)) + else if (PTW32_SPIN_UNLOCKED != + (LONG)PTW32_INTERLOCKED_COMPARE_EXCHANGE ( + (PTW32_INTERLOCKED_LPLONG)&(s->interlock), + (PTW32_INTERLOCKED_LONG)PTW32_SPIN_INVALID, + (PTW32_INTERLOCKED_LONG)PTW32_SPIN_UNLOCKED)) { result = EINVAL; } diff -uNr a/pthread_spin_lock.c b/pthread_spin_lock.c --- a/pthread_spin_lock.c Sat Jan 1 14:36:17 2005 +++ b/pthread_spin_lock.c Thu Jun 24 23:20:10 2010 @@ -60,13 +60,11 @@ s = *lock; - while ((PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED == - PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_LPLONG) & - (s->interlock), - (PTW32_INTERLOCKED_LONG) - PTW32_SPIN_LOCKED, - (PTW32_INTERLOCKED_LONG) - PTW32_SPIN_UNLOCKED)) + while (PTW32_SPIN_LOCKED == + (LONG)PTW32_INTERLOCKED_COMPARE_EXCHANGE ( + (PTW32_INTERLOCKED_LPLONG)&(s->interlock), + (PTW32_INTERLOCKED_LONG)PTW32_SPIN_LOCKED, + (PTW32_INTERLOCKED_LONG)PTW32_SPIN_UNLOCKED)) { } diff -uNr a/pthread_spin_trylock.c b/pthread_spin_trylock.c --- a/pthread_spin_trylock.c Sat Jan 1 14:36:17 2005 +++ b/pthread_spin_trylock.c Thu Jun 24 23:20:10 2010 @@ -60,13 +60,11 @@ s = *lock; - switch ((long) - PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_LPLONG) & - (s->interlock), - (PTW32_INTERLOCKED_LONG) - PTW32_SPIN_LOCKED, - (PTW32_INTERLOCKED_LONG) - PTW32_SPIN_UNLOCKED)) + switch ((LONG) + PTW32_INTERLOCKED_COMPARE_EXCHANGE ( + (PTW32_INTERLOCKED_LPLONG)&(s->interlock), + (PTW32_INTERLOCKED_LONG)PTW32_SPIN_LOCKED, + (PTW32_INTERLOCKED_LONG)PTW32_SPIN_UNLOCKED)) { case PTW32_SPIN_UNLOCKED: return 0; diff -uNr a/pthread_spin_unlock.c b/pthread_spin_unlock.c --- a/pthread_spin_unlock.c Sat Jan 1 14:36:17 2005 +++ b/pthread_spin_unlock.c Thu Jun 24 23:20:10 2010 @@ -55,13 +55,11 @@ return EPERM; } - switch ((long) - PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_LPLONG) & - (s->interlock), - (PTW32_INTERLOCKED_LONG) - PTW32_SPIN_UNLOCKED, - (PTW32_INTERLOCKED_LONG) - PTW32_SPIN_LOCKED)) + switch ((LONG) + PTW32_INTERLOCKED_COMPARE_EXCHANGE ( + (PTW32_INTERLOCKED_LPLONG)&(s->interlock), + (PTW32_INTERLOCKED_LONG)PTW32_SPIN_UNLOCKED, + (PTW32_INTERLOCKED_LONG)PTW32_SPIN_LOCKED)) { case PTW32_SPIN_LOCKED: return 0; diff -uNr a/pthread_timechange_handler_np.c b/pthread_timechange_handler_np.c --- a/pthread_timechange_handler_np.c Sat Jan 1 14:36:17 2005 +++ b/pthread_timechange_handler_np.c Thu Jun 24 23:20:10 2010 @@ -103,5 +103,5 @@ LeaveCriticalSection (&ptw32_cond_list_lock); - return (void *) (result != 0 ? EAGAIN : 0); + return (void *)(INT_PTR) (result != 0 ? EAGAIN : 0); } diff -uNr a/ptw32_MCS_lock.c b/ptw32_MCS_lock.c --- a/ptw32_MCS_lock.c Wed Jun 23 06:18:52 2010 +++ b/ptw32_MCS_lock.c Thu Jun 24 23:20:10 2010 @@ -98,13 +98,20 @@ * Set event if an event handle has been stored in the flag, and * set flag to -1 otherwise. Note that -1 cannot be a valid handle value. */ -INLINE void -ptw32_mcs_flag_set (LONG * flag) +static INLINE void +ptw32_mcs_flag_set (LONG_PTR * flag) { +#ifdef _WIN64 + HANDLE e = (HANDLE)InterlockedCompareExchange64( + (PLONGLONG)flag, + (LONGLONG)-1, + (LONGLONG)0); +#else HANDLE e = (HANDLE)PTW32_INTERLOCKED_COMPARE_EXCHANGE( (PTW32_INTERLOCKED_LPLONG)flag, (PTW32_INTERLOCKED_LONG)-1, (PTW32_INTERLOCKED_LONG)0); +#endif if ((HANDLE)0 != e) { /* another thread has already stored an event handle in the flag */ @@ -118,19 +125,30 @@ * Store an event handle in the flag and wait on it if the flag has not been * set, and proceed without creating an event otherwise. */ -INLINE void -ptw32_mcs_flag_wait (LONG * flag) +static INLINE void +ptw32_mcs_flag_wait (LONG_PTR * flag) { +#ifdef _WIN64 + if (0 == InterlockedExchangeAdd64((PLONGLONG)flag, 0)) /* MBR fence */ +#else if (0 == InterlockedExchangeAdd((LPLONG)flag, 0)) /* MBR fence */ +#endif { /* the flag is not set. create event. */ HANDLE e = CreateEvent(NULL, PTW32_FALSE, PTW32_FALSE, NULL); - if (0 == PTW32_INTERLOCKED_COMPARE_EXCHANGE( +#ifdef _WIN64 + if (0 == InterlockedCompareExchange64( + (PLONGLONG)flag, + (LONGLONG)e, + (LONGLONG)0)) +#else + if (0 == (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( (PTW32_INTERLOCKED_LPLONG)flag, (PTW32_INTERLOCKED_LONG)e, (PTW32_INTERLOCKED_LONG)0)) +#endif { /* stored handle in the flag. wait on it now. */ WaitForSingleObject(e, INFINITE); @@ -148,7 +166,7 @@ * Algorithms for Scalable Synchronization on Shared-Memory Multiprocessors. * ACM Transactions on Computer Systems, 9(1):21-65, Feb. 1991. */ -INLINE void +EXTERN_INLINE void ptw32_mcs_lock_acquire (ptw32_mcs_lock_t * lock, ptw32_mcs_local_node_t * node) { ptw32_mcs_local_node_t *pred; @@ -159,8 +177,13 @@ node->next = 0; /* initially, no successor */ /* queue for the lock */ - pred = (ptw32_mcs_local_node_t *)PTW32_INTERLOCKED_EXCHANGE((PTW32_INTERLOCKED_LPLONG)lock, - (PTW32_INTERLOCKED_LONG)node); +#ifdef _WIN64 + pred = (ptw32_mcs_local_node_t *)InterlockedExchange64((PLONGLONG)lock, + (LONGLONG)node); +#else + pred = (ptw32_mcs_local_node_t *)PTW32_INTERLOCKED_EXCHANGE((LPLONG)lock, + (LONG)node); +#endif if (0 != pred) { @@ -179,22 +202,33 @@ * Algorithms for Scalable Synchronization on Shared-Memory Multiprocessors. * ACM Transactions on Computer Systems, 9(1):21-65, Feb. 1991. */ -INLINE void +EXTERN_INLINE void ptw32_mcs_lock_release (ptw32_mcs_local_node_t * node) { ptw32_mcs_lock_t *lock = node->lock; ptw32_mcs_local_node_t *next = (ptw32_mcs_local_node_t *) +#ifdef _WIN64 + InterlockedExchangeAdd64((PLONGLONG)&node->next, + (LONGLONG)0); /* MBR fence */ +#else InterlockedExchangeAdd((LPLONG)&node->next, (LONG)0); /* MBR fence */ +#endif if (0 == next) { /* no known successor */ if (node == (ptw32_mcs_local_node_t *) +#ifdef _WIN64 + InterlockedCompareExchange64((PLONGLONG)lock, + (LONGLONG)0, + (LONGLONG)node)) +#else PTW32_INTERLOCKED_COMPARE_EXCHANGE((PTW32_INTERLOCKED_LPLONG)lock, (PTW32_INTERLOCKED_LONG)0, (PTW32_INTERLOCKED_LONG)node)) +#endif { /* no successor, lock is free now */ return; @@ -203,7 +237,11 @@ /* wait for successor */ ptw32_mcs_flag_wait(&node->nextFlag); next = (ptw32_mcs_local_node_t *) +#ifdef _WIN64 + InterlockedExchangeAdd64((PLONGLONG)&node->next, 0); /* MBR fence */ +#else InterlockedExchangeAdd((LPLONG)&node->next, 0); /* MBR fence */ +#endif } /* pass the lock */ @@ -213,7 +251,7 @@ /* * ptw32_mcs_lock_try_acquire */ -INLINE int +EXTERN_INLINE int ptw32_mcs_lock_try_acquire (ptw32_mcs_lock_t * lock, ptw32_mcs_local_node_t * node) { node->lock = lock; @@ -221,11 +259,19 @@ node->readyFlag = 0; node->next = 0; /* initially, no successor */ - return ((PTW32_INTERLOCKED_LPLONG)PTW32_INTERLOCKED_COMPARE_EXCHANGE( +#ifdef _WIN64 + return (InterlockedCompareExchange64( + (PLONGLONG)lock, + (LONGLONG)node, + (LONGLONG)0) + == 0) ? 0 : EBUSY; +#else + return ((LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( (PTW32_INTERLOCKED_LPLONG)lock, (PTW32_INTERLOCKED_LONG)node, (PTW32_INTERLOCKED_LONG)0) - == (PTW32_INTERLOCKED_LPLONG)0) ? 0 : EBUSY; + == 0) ? 0 : EBUSY; +#endif } /* @@ -239,7 +285,7 @@ * * Should only be called by the thread that has the lock. */ -INLINE void +EXTERN_INLINE void ptw32_mcs_node_substitute (ptw32_mcs_local_node_t * new_node, ptw32_mcs_local_node_t * old_node) { new_node->lock = old_node->lock; @@ -247,9 +293,15 @@ new_node->readyFlag = 0; /* Not needed - we were waiting on this */ new_node->next = 0; +#ifdef _WIN64 + if ((ptw32_mcs_local_node_t *)InterlockedCompareExchange64((PLONGLONG)new_node->lock, + (LONGLONG)new_node, + (LONGLONG)old_node) != old_node) +#else if ((ptw32_mcs_local_node_t *)PTW32_INTERLOCKED_COMPARE_EXCHANGE((PTW32_INTERLOCKED_LPLONG)new_node->lock, (PTW32_INTERLOCKED_LONG)new_node, (PTW32_INTERLOCKED_LONG)old_node) != old_node) +#endif { /* * A successor has queued after us, so wait for them to link to us diff -uNr a/ptw32_callUserDestroyRoutines.c b/ptw32_callUserDestroyRoutines.c --- a/ptw32_callUserDestroyRoutines.c Mon May 9 08:31:31 2005 +++ b/ptw32_callUserDestroyRoutines.c Thu Jun 24 23:20:10 2010 @@ -39,10 +39,20 @@ #include "implement.h" #ifdef __cplusplus -# if ! defined (_MSC_VER) && ! (defined(__GNUC__) && __GNUC__ < 3) && ! defined(__WATCOMC__) +#if defined(_MSC_VER) +# include +#elif defined(__WATCOMC__) +# include +# include +#else +# if defined(__GNUC__) && __GNUC__ < 3 +# include +# else +# include using std::terminate; # endif +#endif #endif void diff -uNr a/ptw32_cond_check_need_init.c b/ptw32_cond_check_need_init.c --- a/ptw32_cond_check_need_init.c Sat Jan 1 14:36:17 2005 +++ b/ptw32_cond_check_need_init.c Thu Jun 24 23:20:10 2010 @@ -39,7 +39,7 @@ #include "implement.h" -INLINE int +EXTERN_INLINE int ptw32_cond_check_need_init (pthread_cond_t * cond) { int result = 0; diff -uNr a/ptw32_mutex_check_need_init.c b/ptw32_mutex_check_need_init.c --- a/ptw32_mutex_check_need_init.c Sat Jan 1 14:36:17 2005 +++ b/ptw32_mutex_check_need_init.c Thu Jun 24 23:20:10 2010 @@ -45,7 +45,7 @@ static pthread_mutexattr_t ptw32_errorcheck_mutexattr = &ptw32_errorcheck_mutexattr_s; -INLINE int +EXTERN_INLINE int ptw32_mutex_check_need_init (pthread_mutex_t * mutex) { register int result = 0; diff -uNr a/ptw32_relmillisecs.c b/ptw32_relmillisecs.c --- a/ptw32_relmillisecs.c Tue May 15 13:46:42 2007 +++ b/ptw32_relmillisecs.c Thu Jun 24 23:20:10 2010 @@ -44,7 +44,7 @@ #endif -INLINE DWORD +EXTERN_INLINE DWORD ptw32_relmillisecs (const struct timespec * abstime) { const int64_t NANOSEC_PER_MILLISEC = 1000000; diff -uNr a/ptw32_rwlock_check_need_init.c b/ptw32_rwlock_check_need_init.c --- a/ptw32_rwlock_check_need_init.c Sat Jan 1 14:36:18 2005 +++ b/ptw32_rwlock_check_need_init.c Thu Jun 24 23:20:10 2010 @@ -37,7 +37,7 @@ #include "pthread.h" #include "implement.h" -INLINE int +EXTERN_INLINE int ptw32_rwlock_check_need_init (pthread_rwlock_t * rwlock) { int result = 0; diff -uNr a/ptw32_spinlock_check_need_init.c b/ptw32_spinlock_check_need_init.c --- a/ptw32_spinlock_check_need_init.c Sat Jan 1 14:36:18 2005 +++ b/ptw32_spinlock_check_need_init.c Thu Jun 24 23:44:52 2010 @@ -38,7 +38,7 @@ #include "implement.h" -INLINE int +EXTERN_INLINE int ptw32_spinlock_check_need_init (pthread_spinlock_t * lock) { int result = 0; diff -uNr a/ptw32_threadStart.c b/ptw32_threadStart.c --- a/ptw32_threadStart.c Sun May 15 15:28:27 2005 +++ b/ptw32_threadStart.c Thu Jun 24 23:20:10 2010 @@ -344,7 +344,7 @@ #endif #if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) - _endthreadex ((unsigned) status); + _endthreadex ((unsigned)(UINT_PTR) status); #else _endthread (); #endif @@ -354,7 +354,7 @@ */ #if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) - return (unsigned) status; + return (unsigned)(UINT_PTR) status; #endif } /* ptw32_threadStart */ diff -uNr a/ptw32_throw.c b/ptw32_throw.c --- a/ptw32_throw.c Fri Jun 6 00:23:20 2008 +++ b/ptw32_throw.c Thu Jun 24 23:20:10 2010 @@ -79,12 +79,12 @@ switch (exception) { case PTW32_EPS_CANCEL: - exitCode = (unsigned) PTHREAD_CANCELED; + exitCode = (unsigned)(UINT_PTR) PTHREAD_CANCELED; break; case PTW32_EPS_EXIT: if (NULL != sp) { - exitCode = (unsigned) sp->exitStatus; + exitCode = (unsigned)(UINT_PTR) sp->exitStatus; } break; } @@ -166,7 +166,7 @@ #else - return (DWORD) NULL; + return (DWORD)(DWORD_PTR) NULL; #endif } diff -uNr a/ptw32_timespec.c b/ptw32_timespec.c --- a/ptw32_timespec.c Sat Jan 1 14:36:18 2005 +++ b/ptw32_timespec.c Thu Jun 24 23:20:10 2010 @@ -47,7 +47,7 @@ #define PTW32_TIMESPEC_TO_FILETIME_OFFSET \ ( ((LONGLONG) 27111902 << 32) + (LONGLONG) 3577643008 ) -INLINE void +EXTERN_INLINE void ptw32_timespec_to_filetime (const struct timespec *ts, FILETIME * ft) /* * ------------------------------------------------------------------- @@ -62,7 +62,7 @@ + (ts->tv_nsec + 50) / 100 + PTW32_TIMESPEC_TO_FILETIME_OFFSET; } -INLINE void +EXTERN_INLINE void ptw32_filetime_to_timespec (const FILETIME * ft, struct timespec *ts) /* * -------------------------------------------------------------------