diff options
| -rw-r--r-- | ChangeLog | 8 | ||||
| -rw-r--r-- | implement.h | 75 | ||||
| -rw-r--r-- | pthread_barrier_wait.c | 4 | ||||
| -rwxr-xr-x | pthread_mutex_consistent.c | 16 | ||||
| -rw-r--r-- | pthread_mutex_lock.c | 70 | ||||
| -rw-r--r-- | pthread_mutex_timedlock.c | 70 | ||||
| -rw-r--r-- | pthread_mutex_trylock.c | 22 | ||||
| -rw-r--r-- | pthread_mutex_unlock.c | 22 | ||||
| -rw-r--r-- | pthread_once.c | 2 | ||||
| -rw-r--r-- | pthread_spin_destroy.c | 8 | ||||
| -rw-r--r-- | pthread_spin_lock.c | 8 | ||||
| -rw-r--r-- | pthread_spin_trylock.c | 6 | ||||
| -rw-r--r-- | pthread_spin_unlock.c | 6 | ||||
| -rw-r--r-- | pthread_win32_attach_detach_np.c | 4 | ||||
| -rw-r--r-- | ptw32_InterlockedCompareExchange.c | 10 | ||||
| -rw-r--r-- | ptw32_MCS_lock.c | 20 | ||||
| -rw-r--r-- | sched.h | 6 | 
17 files changed, 181 insertions, 176 deletions
@@ -1,3 +1,11 @@ +2011-06-29  Ross Johnson <ross dot johnson at homemail dot com dot au>
 +
 +	* *.[ch] (PTW32_INTERLOCKED_*): These macros should now work for
 +	both 32 and 64 bit builds. The MingW versions are all inlined asm
 +	while the MSVC versions expand to their Interlocked* or Interlocked*64
 +	counterparts appropriately. The argument type have also been changed
 +	to cast to the appropriate value or pointer size for the architecture.
 +
  2011-05-29  Ross Johnson <ross dot johnson at homemail dot com dot au>
  	* *.[ch] (#ifdef): Extended cleanup to whole project.
 diff --git a/implement.h b/implement.h index bd2836b..0053193 100644 --- a/implement.h +++ b/implement.h @@ -82,14 +82,14 @@ typedef VOID (APIENTRY *PAPCFUNC)(DWORD dwParam);  #define INLINE  #endif -#if defined(__MINGW64__) || defined(__MINGW32__) || defined(_MSC_VER) -#define PTW32_INTERLOCKED_LONG unsigned long -#define PTW32_INTERLOCKED_LPLONG volatile unsigned long* +#if defined(_WIN64) +#define PTW32_INTERLOCKED_VALUE size_t +#define PTW32_INTERLOCKED_PTR volatile size_t*  #define PTW32_INTERLOCKED_PVOID PVOID  #define PTW32_INTERLOCKED_PVOID_PTR volatile PVOID*  #else -#define PTW32_INTERLOCKED_LONG PVOID -#define PTW32_INTERLOCKED_LPLONG volatile PVOID* +#define PTW32_INTERLOCKED_VALUE size_t +#define PTW32_INTERLOCKED_PTR volatile size_t*  #define PTW32_INTERLOCKED_PVOID PVOID  #define PTW32_INTERLOCKED_PVOID_PTR volatile PVOID*  #endif @@ -736,13 +736,14 @@ extern "C"   * The above aren't available in Mingw32 as of gcc 4.5.2 so define our own.   */  #if defined(__GNUC__) +# if defined(_WIN64)  # define PTW32_INTERLOCKED_COMPARE_EXCHANGE(location, value, comparand)    \      ({                                                                     \        __typeof (value) _result;                                            \        __asm__ __volatile__                                                 \        (                                                                    \          "lock\n\t"                                                         \ -        "cmpxchgl       %2,(%1)"                                           \ +        "cmpxchgq      %2,(%1)"                                            \          :"=a" (_result)                                                    \          :"r"  (location), "r" (value), "a" (comparand)                     \          :"memory", "cc");                                                  \ @@ -753,7 +754,7 @@ extern "C"        __typeof (value) _result;                                            \        __asm__ __volatile__                                                 \        (                                                                    \ -        "xchgl	 %0,(%1)"                                                  \ +        "xchgq	 %0,(%1)"                                                  \          :"=r" (_result)                                                    \          :"r" (location), "0" (value)                                       \          :"memory", "cc");                                                  \ @@ -765,7 +766,7 @@ extern "C"        __asm__ __volatile__                                                 \        (                                                                    \          "lock\n\t"                                                         \ -        "xaddl	 %0,(%1)"                                                  \ +        "xaddq	 %0,(%1)"                                                  \          :"=r" (_result)                                                    \          :"r" (location), "0" (value)                                       \          :"memory", "cc");                                                  \ @@ -773,11 +774,11 @@ extern "C"      })  # define PTW32_INTERLOCKED_INCREMENT(location)                             \      ({                                                                     \ -      long _temp = 1;                                                      \ +      long long _temp = 1;                                                 \        __asm__ __volatile__                                                 \        (                                                                    \          "lock\n\t"                                                         \ -        "xaddl	 %0,(%1)"                                                  \ +        "xaddq	 %0,(%1)"                                                  \          :"+r" (_temp)                                                      \          :"r" (location)                                                    \          :"memory", "cc");                                                  \ @@ -785,100 +786,96 @@ extern "C"      })  # define PTW32_INTERLOCKED_DECREMENT(location)                             \      ({                                                                     \ -      long _temp = -1;                                                     \ +      long long _temp = -1;                                                \        __asm__ __volatile__                                                 \        (                                                                    \          "lock\n\t"                                                         \ -        "xaddl	 %0,(%1)"                                                  \ +        "xaddq	 %2,(%1)"                                                  \          :"+r" (_temp)                                                      \          :"r" (location)                                                    \          :"memory", "cc");                                                  \        --_temp;                                                             \      }) -# if defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE64(location, value, comparand)  \ +#else +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE(location, value, comparand)    \      ({                                                                     \        __typeof (value) _result;                                            \        __asm__ __volatile__                                                 \        (                                                                    \          "lock\n\t"                                                         \ -        "cmpxchgq      %2,(%1)"                                            \ +        "cmpxchgl       %2,(%1)"                                           \          :"=a" (_result)                                                    \          :"r"  (location), "r" (value), "a" (comparand)                     \          :"memory", "cc");                                                  \        _result;                                                             \      }) -# define PTW32_INTERLOCKED_EXCHANGE64(location, value)                     \ +# define PTW32_INTERLOCKED_EXCHANGE(location, value)                       \      ({                                                                     \        __typeof (value) _result;                                            \        __asm__ __volatile__                                                 \        (                                                                    \ -        "xchgq	 %0,(%1)"                                                  \ +        "xchgl	 %0,(%1)"                                                  \          :"=r" (_result)                                                    \          :"r" (location), "0" (value)                                       \          :"memory", "cc");                                                  \        _result;                                                             \      }) -# define PTW32_INTERLOCKED_EXCHANGE_ADD64(location, value)                 \ +# define PTW32_INTERLOCKED_EXCHANGE_ADD(location, value)                   \      ({                                                                     \        __typeof (value) _result;                                            \        __asm__ __volatile__                                                 \        (                                                                    \          "lock\n\t"                                                         \ -        "xaddq	 %0,(%1)"                                                  \ +        "xaddl	 %0,(%1)"                                                  \          :"=r" (_result)                                                    \          :"r" (location), "0" (value)                                       \          :"memory", "cc");                                                  \        _result;                                                             \      }) -# define PTW32_INTERLOCKED_INCREMENT64(location)                           \ +# define PTW32_INTERLOCKED_INCREMENT(location)                             \      ({                                                                     \        long _temp = 1;                                                      \        __asm__ __volatile__                                                 \        (                                                                    \          "lock\n\t"                                                         \ -        "xaddq	 %0,(%1)"                                                  \ +        "xaddl	 %0,(%1)"                                                  \          :"+r" (_temp)                                                      \          :"r" (location)                                                    \          :"memory", "cc");                                                  \        ++_temp;                                                             \      }) -# define PTW32_INTERLOCKED_DECREMENT64(location)                           \ +# define PTW32_INTERLOCKED_DECREMENT(location)                             \      ({                                                                     \        long _temp = -1;                                                     \        __asm__ __volatile__                                                 \        (                                                                    \          "lock\n\t"                                                         \ -        "xaddq	 %0,(%1)"                                                  \ +        "xaddl	 %0,(%1)"                                                  \          :"+r" (_temp)                                                      \          :"r" (location)                                                    \          :"memory", "cc");                                                  \        --_temp;                                                             \      }) -#   define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(location, value, comparand) \ -      PTW32_INTERLOCKED_COMPARE_EXCHANGE64(location, (size_t)value, (size_t)comparand) -#   define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \ -      PTW32_INTERLOCKED_EXCHANGE64(location, (size_t)value) -# else +#endif  #   define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(location, value, comparand) \        PTW32_INTERLOCKED_COMPARE_EXCHANGE(location, (size_t)value, (size_t)comparand)  #   define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \        PTW32_INTERLOCKED_EXCHANGE(location, (size_t)value) -# endif  #else -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange  # define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR InterlockedCompareExchangePointer -# define PTW32_INTERLOCKED_EXCHANGE InterlockedExchange  # define PTW32_INTERLOCKED_EXCHANGE_PTR InterlockedExchangePointer -# define PTW32_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd -# define PTW32_INTERLOCKED_INCREMENT InterlockedIncrement -# define PTW32_INTERLOCKED_DECREMENT InterlockedDecrement  # if defined(_WIN64) -#   define PTW32_INTERLOCKED_COMPARE_EXCHANGE64 InterlockedCompareExchange64 -#   define PTW32_INTERLOCKED_EXCHANGE64 InterlockedExchange64 -#   define PTW32_INTERLOCKED_EXCHANGE_ADD64 InterlockedExchangeAdd64 -#   define PTW32_INTERLOCKED_INCREMENT64 InterlockedIncrement64 -#   define PTW32_INTERLOCKED_DECREMENT64 InterlockedDecrement64 +#   define PTW32_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange64 +#   define PTW32_INTERLOCKED_EXCHANGE InterlockedExchange64 +#   define PTW32_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd64 +#   define PTW32_INTERLOCKED_INCREMENT InterlockedIncrement64 +#   define PTW32_INTERLOCKED_DECREMENT InterlockedDecrement64 +# else +#   define PTW32_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange +#   define PTW32_INTERLOCKED_EXCHANGE InterlockedExchange +#   define PTW32_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd +#   define PTW32_INTERLOCKED_INCREMENT InterlockedIncrement +#   define PTW32_INTERLOCKED_DECREMENT InterlockedDecrement  # endif  #endif diff --git a/pthread_barrier_wait.c b/pthread_barrier_wait.c index d01b7d4..7a2cab2 100644 --- a/pthread_barrier_wait.c +++ b/pthread_barrier_wait.c @@ -87,8 +87,8 @@ pthread_barrier_wait (pthread_barrier_t * barrier)        result = ptw32_semwait (&(b->semBarrierBreeched));      } -  if ((PTW32_INTERLOCKED_LONG)PTW32_INTERLOCKED_INCREMENT((LPLONG)&b->nCurrentBarrierHeight) -		  == (PTW32_INTERLOCKED_LONG)b->nInitialBarrierHeight) +  if ((PTW32_INTERLOCKED_VALUE)PTW32_INTERLOCKED_INCREMENT((PTW32_INTERLOCKED_PTR)&b->nCurrentBarrierHeight) +		  == (PTW32_INTERLOCKED_VALUE)b->nInitialBarrierHeight)      {        /*         * We are the last thread to cross this barrier diff --git a/pthread_mutex_consistent.c b/pthread_mutex_consistent.c index 681358c..0f63d1b 100755 --- a/pthread_mutex_consistent.c +++ b/pthread_mutex_consistent.c @@ -80,10 +80,10 @@ ptw32_robust_mutex_inherit(pthread_mutex_t * mutex)    pthread_mutex_t mx = *mutex;    ptw32_robust_node_t* robust = mx->robustNode; -  switch (PTW32_INTERLOCKED_COMPARE_EXCHANGE( -            (LPLONG)&robust->stateInconsistent, -            (LONG)PTW32_ROBUST_INCONSISTENT, -            -1L /* The terminating thread sets this */)) +  switch ((LONG)(size_t)PTW32_INTERLOCKED_COMPARE_EXCHANGE( +            (PTW32_INTERLOCKED_PTR)&robust->stateInconsistent, +            (PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_INCONSISTENT, +            (PTW32_INTERLOCKED_VALUE)-1 /* The terminating thread sets this */))      {        case -1L:            result = EOWNERDEAD; @@ -177,10 +177,10 @@ pthread_mutex_consistent (pthread_mutex_t* mutex)      }    if (mx->kind >= 0 -        || (LONG)PTW32_ROBUST_INCONSISTENT != PTW32_INTERLOCKED_COMPARE_EXCHANGE( -                                                (LPLONG)&mx->robustNode->stateInconsistent, -                                                (LONG)PTW32_ROBUST_CONSISTENT, -                                                (LONG)PTW32_ROBUST_INCONSISTENT)) +        || (PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_INCONSISTENT != PTW32_INTERLOCKED_COMPARE_EXCHANGE( +                                                (PTW32_INTERLOCKED_PTR)&mx->robustNode->stateInconsistent, +                                                (PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_CONSISTENT, +                                                (PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_INCONSISTENT))      {        result = EINVAL;      } diff --git a/pthread_mutex_lock.c b/pthread_mutex_lock.c index 0d4fde8..f6bdcbd 100644 --- a/pthread_mutex_lock.c +++ b/pthread_mutex_lock.c @@ -77,13 +77,13 @@ pthread_mutex_lock (pthread_mutex_t * mutex)        /* Non-robust */        if (PTHREAD_MUTEX_NORMAL == kind)          { -          if ((LONG) PTW32_INTERLOCKED_EXCHANGE( -		       (LPLONG) &mx->lock_idx, -		       (LONG) 1) != 0) +          if ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +		       (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +		       (PTW32_INTERLOCKED_VALUE) 1) != 0)  	    { -	      while ((LONG) PTW32_INTERLOCKED_EXCHANGE( -                              (LPLONG) &mx->lock_idx, -			      (LONG) -1) != 0) +	      while ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +                              (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +			      (PTW32_INTERLOCKED_VALUE) -1) != 0)  	        {  	          if (WAIT_OBJECT_0 != WaitForSingleObject (mx->event, INFINITE))  	            { @@ -97,10 +97,10 @@ pthread_mutex_lock (pthread_mutex_t * mutex)          {            pthread_t self = pthread_self(); -          if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( -                       (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, -		       (PTW32_INTERLOCKED_LONG) 1, -		       (PTW32_INTERLOCKED_LONG) 0) == 0) +          if ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_COMPARE_EXCHANGE( +                       (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +		       (PTW32_INTERLOCKED_VALUE) 1, +		       (PTW32_INTERLOCKED_VALUE) 0) == 0)  	    {  	      mx->recursive_count = 1;  	      mx->ownerThread = self; @@ -120,9 +120,9 @@ pthread_mutex_lock (pthread_mutex_t * mutex)  	        }  	      else  	        { -	          while ((LONG) PTW32_INTERLOCKED_EXCHANGE( -                                  (LPLONG) &mx->lock_idx, -			          (LONG) -1) != 0) +	          while ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +                                  (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +			          (PTW32_INTERLOCKED_VALUE) -1) != 0)  		    {  	              if (WAIT_OBJECT_0 != WaitForSingleObject (mx->event, INFINITE))  		        { @@ -149,9 +149,9 @@ pthread_mutex_lock (pthread_mutex_t * mutex)         */        ptw32_robust_state_t* statePtr = &mx->robustNode->stateInconsistent; -      if ((LONG)PTW32_ROBUST_NOTRECOVERABLE == PTW32_INTERLOCKED_EXCHANGE_ADD( -                                                 (LPLONG)statePtr, -                                                 0L)) +      if ((PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_NOTRECOVERABLE == PTW32_INTERLOCKED_EXCHANGE_ADD( +                                                 (PTW32_INTERLOCKED_PTR)statePtr, +                                                 (PTW32_INTERLOCKED_VALUE)0))          {            result = ENOTRECOVERABLE;          } @@ -163,24 +163,24 @@ pthread_mutex_lock (pthread_mutex_t * mutex)            if (PTHREAD_MUTEX_NORMAL == kind)              { -              if ((LONG) PTW32_INTERLOCKED_EXCHANGE( -                           (LPLONG) &mx->lock_idx, -                           (LONG) 1) != 0) +              if ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +                           (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +                           (PTW32_INTERLOCKED_VALUE) 1) != 0)                  {                    while (0 == (result = ptw32_robust_mutex_inherit(mutex)) -                           && (LONG) PTW32_INTERLOCKED_EXCHANGE( -                                       (LPLONG) &mx->lock_idx, -                                       (LONG) -1) != 0) +                           && (PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +                                       (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +                                       (PTW32_INTERLOCKED_VALUE) -1) != 0)                      {                        if (WAIT_OBJECT_0 != WaitForSingleObject (mx->event, INFINITE))                          {                            result = EINVAL;                            break;                          } -                      if ((LONG)PTW32_ROBUST_NOTRECOVERABLE == +                      if ((PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_NOTRECOVERABLE ==                                    PTW32_INTERLOCKED_EXCHANGE_ADD( -                                    (LPLONG)statePtr, -                                    0L)) +                                    (PTW32_INTERLOCKED_PTR)statePtr, +                                    (PTW32_INTERLOCKED_VALUE)0))                          {                            /* Unblock the next thread */                            SetEvent(mx->event); @@ -200,10 +200,10 @@ pthread_mutex_lock (pthread_mutex_t * mutex)              }            else              { -              if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( -                           (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, -                           (PTW32_INTERLOCKED_LONG) 1, -                           (PTW32_INTERLOCKED_LONG) 0) == 0) +              if ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_COMPARE_EXCHANGE( +                           (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +                           (PTW32_INTERLOCKED_VALUE) 1, +                           (PTW32_INTERLOCKED_VALUE) 0) == 0)                  {                    mx->recursive_count = 1;                    /* @@ -228,19 +228,19 @@ pthread_mutex_lock (pthread_mutex_t * mutex)                    else                      {                        while (0 == (result = ptw32_robust_mutex_inherit(mutex)) -                               && (LONG) PTW32_INTERLOCKED_EXCHANGE( -                                           (LPLONG) &mx->lock_idx, -                                           (LONG) -1) != 0) +                               && (PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +                                           (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +                                           (PTW32_INTERLOCKED_VALUE) -1) != 0)                          {                            if (WAIT_OBJECT_0 != WaitForSingleObject (mx->event, INFINITE))                              {                                result = EINVAL;                                break;                              } -                          if ((LONG)PTW32_ROBUST_NOTRECOVERABLE == +                          if ((PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_NOTRECOVERABLE ==                                        PTW32_INTERLOCKED_EXCHANGE_ADD( -                                        (LPLONG)statePtr, -                                        0L)) +                                        (PTW32_INTERLOCKED_PTR)statePtr, +                                        (PTW32_INTERLOCKED_VALUE)0))                              {                                /* Unblock the next thread */                                SetEvent(mx->event); diff --git a/pthread_mutex_timedlock.c b/pthread_mutex_timedlock.c index 3f759b5..14843af 100644 --- a/pthread_mutex_timedlock.c +++ b/pthread_mutex_timedlock.c @@ -138,13 +138,13 @@ pthread_mutex_timedlock (pthread_mutex_t * mutex,      {        if (mx->kind == PTHREAD_MUTEX_NORMAL)          { -          if ((LONG) PTW32_INTERLOCKED_EXCHANGE( -		       (LPLONG) &mx->lock_idx, -		       (LONG) 1) != 0) +          if ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +		       (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +		       (PTW32_INTERLOCKED_VALUE) 1) != 0)  	    { -              while ((LONG) PTW32_INTERLOCKED_EXCHANGE( -                              (LPLONG) &mx->lock_idx, -			      (LONG) -1) != 0) +              while ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +                              (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +			      (PTW32_INTERLOCKED_VALUE) -1) != 0)                  {  	          if (0 != (result = ptw32_timed_eventwait (mx->event, abstime)))  		    { @@ -157,10 +157,10 @@ pthread_mutex_timedlock (pthread_mutex_t * mutex,          {            pthread_t self = pthread_self(); -          if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( -                       (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, -		       (PTW32_INTERLOCKED_LONG) 1, -		       (PTW32_INTERLOCKED_LONG) 0) == 0) +          if ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_COMPARE_EXCHANGE( +                       (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +		       (PTW32_INTERLOCKED_VALUE) 1, +		       (PTW32_INTERLOCKED_VALUE) 0) == 0)  	    {  	      mx->recursive_count = 1;  	      mx->ownerThread = self; @@ -180,9 +180,9 @@ pthread_mutex_timedlock (pthread_mutex_t * mutex,  	        }  	      else  	        { -                  while ((LONG) PTW32_INTERLOCKED_EXCHANGE( -                                  (LPLONG) &mx->lock_idx, -			          (LONG) -1) != 0) +                  while ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +                                  (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +			          (PTW32_INTERLOCKED_VALUE) -1) != 0)                      {  		      if (0 != (result = ptw32_timed_eventwait (mx->event, abstime)))  		        { @@ -205,9 +205,9 @@ pthread_mutex_timedlock (pthread_mutex_t * mutex,         */        ptw32_robust_state_t* statePtr = &mx->robustNode->stateInconsistent; -      if ((LONG)PTW32_ROBUST_NOTRECOVERABLE == PTW32_INTERLOCKED_EXCHANGE_ADD( -                                                 (LPLONG)statePtr, -                                                 0L)) +      if ((PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_NOTRECOVERABLE == PTW32_INTERLOCKED_EXCHANGE_ADD( +                                                 (PTW32_INTERLOCKED_PTR)statePtr, +                                                 (PTW32_INTERLOCKED_VALUE)0))          {            result = ENOTRECOVERABLE;          } @@ -219,23 +219,23 @@ pthread_mutex_timedlock (pthread_mutex_t * mutex,            if (PTHREAD_MUTEX_NORMAL == kind)              { -              if ((LONG) PTW32_INTERLOCKED_EXCHANGE( -		           (LPLONG) &mx->lock_idx, -		           (LONG) 1) != 0) +              if ((PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +		           (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +		           (PTW32_INTERLOCKED_VALUE) 1) != 0)  	        {                    while (0 == (result = ptw32_robust_mutex_inherit(mutex)) -                           && (LONG) PTW32_INTERLOCKED_EXCHANGE( -                                  (LPLONG) &mx->lock_idx, -			          (LONG) -1) != 0) +                           && (PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +                                  (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +			          (PTW32_INTERLOCKED_VALUE) -1) != 0)                      {  	              if (0 != (result = ptw32_timed_eventwait (mx->event, abstime)))  		        {  		          return result;  		        } -                      if ((LONG)PTW32_ROBUST_NOTRECOVERABLE == +                      if ((PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_NOTRECOVERABLE ==                                    PTW32_INTERLOCKED_EXCHANGE_ADD( -                                    (LPLONG)statePtr, -                                    0L)) +                                    (PTW32_INTERLOCKED_PTR)statePtr, +                                    (PTW32_INTERLOCKED_VALUE)0))                          {                            /* Unblock the next thread */                            SetEvent(mx->event); @@ -258,10 +258,10 @@ pthread_mutex_timedlock (pthread_mutex_t * mutex,              {                pthread_t self = pthread_self(); -              if ((PTW32_INTERLOCKED_LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( -                           (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, -		           (PTW32_INTERLOCKED_LONG) 1, -		           (PTW32_INTERLOCKED_LONG) 0) == 0) +              if (0 == (PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_COMPARE_EXCHANGE( +                           (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +		           (PTW32_INTERLOCKED_VALUE) 1, +		           (PTW32_INTERLOCKED_VALUE) 0))  	        {  	          mx->recursive_count = 1;                    /* @@ -286,9 +286,9 @@ pthread_mutex_timedlock (pthread_mutex_t * mutex,  	          else  	            {                        while (0 == (result = ptw32_robust_mutex_inherit(mutex)) -                               && (LONG) PTW32_INTERLOCKED_EXCHANGE( -                                          (LPLONG) &mx->lock_idx, -			                  (LONG) -1) != 0) +                               && (PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_EXCHANGE( +                                          (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +			                  (PTW32_INTERLOCKED_VALUE) -1) != 0)                          {  		          if (0 != (result = ptw32_timed_eventwait (mx->event, abstime)))  		            { @@ -296,10 +296,10 @@ pthread_mutex_timedlock (pthread_mutex_t * mutex,  		            }  		        } -                      if ((LONG)PTW32_ROBUST_NOTRECOVERABLE == +                      if ((PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_NOTRECOVERABLE ==                                    PTW32_INTERLOCKED_EXCHANGE_ADD( -                                    (LPLONG)statePtr, -                                    0L)) +                                    (PTW32_INTERLOCKED_PTR)statePtr, +                                    (PTW32_INTERLOCKED_VALUE)0))                          {                            /* Unblock the next thread */                            SetEvent(mx->event); diff --git a/pthread_mutex_trylock.c b/pthread_mutex_trylock.c index 6fcff75..a57986c 100644 --- a/pthread_mutex_trylock.c +++ b/pthread_mutex_trylock.c @@ -69,10 +69,10 @@ pthread_mutex_trylock (pthread_mutex_t * mutex)    if (kind >= 0)      {        /* Non-robust */ -      if (0 == (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE ( -		         (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, -		         (PTW32_INTERLOCKED_LONG) 1, -		         (PTW32_INTERLOCKED_LONG) 0)) +      if (0 == (PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_COMPARE_EXCHANGE ( +		         (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +		         (PTW32_INTERLOCKED_VALUE) 1, +		         (PTW32_INTERLOCKED_VALUE) 0))          {            if (kind != PTHREAD_MUTEX_NORMAL)  	    { @@ -103,10 +103,10 @@ pthread_mutex_trylock (pthread_mutex_t * mutex)        pthread_t self;        ptw32_robust_state_t* statePtr = &mx->robustNode->stateInconsistent; -      if ((LONG)PTW32_ROBUST_NOTRECOVERABLE == +      if ((PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_NOTRECOVERABLE ==                    PTW32_INTERLOCKED_EXCHANGE_ADD( -                    (LPLONG)statePtr, -                    0L)) +                    (PTW32_INTERLOCKED_PTR)statePtr, +                    (PTW32_INTERLOCKED_VALUE)0))          {            return ENOTRECOVERABLE;          } @@ -114,10 +114,10 @@ pthread_mutex_trylock (pthread_mutex_t * mutex)        self = pthread_self();        kind = -kind - 1; /* Convert to non-robust range */ -      if (0 == (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE ( -        	         (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, -        	         (PTW32_INTERLOCKED_LONG) 1, -        	         (PTW32_INTERLOCKED_LONG) 0)) +      if (0 == (PTW32_INTERLOCKED_VALUE) PTW32_INTERLOCKED_COMPARE_EXCHANGE ( +        	         (PTW32_INTERLOCKED_PTR) &mx->lock_idx, +        	         (PTW32_INTERLOCKED_VALUE) 1, +        	         (PTW32_INTERLOCKED_VALUE) 0))          {            if (kind != PTHREAD_MUTEX_NORMAL)              { diff --git a/pthread_mutex_unlock.c b/pthread_mutex_unlock.c index 5cd51af..59604fd 100644 --- a/pthread_mutex_unlock.c +++ b/pthread_mutex_unlock.c @@ -66,8 +66,8 @@ pthread_mutex_unlock (pthread_mutex_t * mutex)  	    {  	      LONG idx; -	      idx = (LONG) PTW32_INTERLOCKED_EXCHANGE ((LPLONG) &mx->lock_idx, -						       (LONG) 0); +	      idx = (LONG)(size_t) PTW32_INTERLOCKED_EXCHANGE ((PTW32_INTERLOCKED_PTR)&mx->lock_idx, +						       (PTW32_INTERLOCKED_VALUE)0);  	      if (idx != 0)  	        {  	          if (idx < 0) @@ -91,8 +91,8 @@ pthread_mutex_unlock (pthread_mutex_t * mutex)  		    {  		      mx->ownerThread.p = NULL; -		      if ((LONG) PTW32_INTERLOCKED_EXCHANGE ((LPLONG) &mx->lock_idx, -							     (LONG) 0) < 0) +		      if ((LONG)(size_t) PTW32_INTERLOCKED_EXCHANGE ((PTW32_INTERLOCKED_PTR)&mx->lock_idx, +							     (PTW32_INTERLOCKED_VALUE)0) < 0)  		        {  		          /* Someone may be waiting on that mutex */  		          if (SetEvent (mx->event) == 0) @@ -120,15 +120,15 @@ pthread_mutex_unlock (pthread_mutex_t * mutex)             */            if (pthread_equal (mx->ownerThread, self))              { -              PTW32_INTERLOCKED_COMPARE_EXCHANGE((LPLONG) &mx->robustNode->stateInconsistent, -                                                 (LONG)PTW32_ROBUST_NOTRECOVERABLE, -                                                 (LONG)PTW32_ROBUST_INCONSISTENT); +              PTW32_INTERLOCKED_COMPARE_EXCHANGE((PTW32_INTERLOCKED_PTR) &mx->robustNode->stateInconsistent, +                                                 (PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_NOTRECOVERABLE, +                                                 (PTW32_INTERLOCKED_VALUE)PTW32_ROBUST_INCONSISTENT);                if (PTHREAD_MUTEX_NORMAL == kind)                  {                    ptw32_robust_mutex_remove(mutex, NULL); -                  if ((LONG) PTW32_INTERLOCKED_EXCHANGE((LPLONG) &mx->lock_idx, -                                                          (LONG) 0) < 0) +                  if ((LONG)(size_t) PTW32_INTERLOCKED_EXCHANGE((PTW32_INTERLOCKED_PTR) &mx->lock_idx, +                                                          (PTW32_INTERLOCKED_VALUE) 0) < 0)                      {                        /*                         * Someone may be waiting on that mutex. @@ -146,8 +146,8 @@ pthread_mutex_unlock (pthread_mutex_t * mutex)                      {                        ptw32_robust_mutex_remove(mutex, NULL); -                      if ((LONG) PTW32_INTERLOCKED_EXCHANGE((LPLONG) &mx->lock_idx, -                                                            (LONG) 0) < 0) +                      if ((LONG)(size_t) PTW32_INTERLOCKED_EXCHANGE((PTW32_INTERLOCKED_PTR) &mx->lock_idx, +                                                            (PTW32_INTERLOCKED_VALUE) 0) < 0)                          {                            /*                             * Someone may be waiting on that mutex. diff --git a/pthread_once.c b/pthread_once.c index f5998fa..ca66dce 100644 --- a/pthread_once.c +++ b/pthread_once.c @@ -54,7 +54,7 @@ pthread_once (pthread_once_t * once_control, void (*init_routine) (void))        return EINVAL;      } -  if (!PTW32_INTERLOCKED_EXCHANGE_ADD((LPLONG)&once_control->done, 0)) /* MBR fence */ +  if (!PTW32_INTERLOCKED_EXCHANGE_ADD((LPLONG)&once_control->done, (size_t)0)) /* MBR fence */      {        ptw32_mcs_local_node_t node; diff --git a/pthread_spin_destroy.c b/pthread_spin_destroy.c index 2ff1425..2be1e32 100644 --- a/pthread_spin_destroy.c +++ b/pthread_spin_destroy.c @@ -55,12 +55,12 @@ pthread_spin_destroy (pthread_spinlock_t * lock)  	{  	  result = pthread_mutex_destroy (&(s->u.mutex));  	} -      else if ((PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED != -	       PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_LPLONG) +      else if ((PTW32_INTERLOCKED_VALUE) PTW32_SPIN_UNLOCKED != +	       PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_PTR)  						   & (s->interlock), -						   (PTW32_INTERLOCKED_LONG) +						   (PTW32_INTERLOCKED_VALUE)  						   (size_t)PTW32_OBJECT_INVALID, -						   (PTW32_INTERLOCKED_LONG) +						   (PTW32_INTERLOCKED_VALUE)  						   (size_t)PTW32_SPIN_UNLOCKED))  	{  	  result = EINVAL; diff --git a/pthread_spin_lock.c b/pthread_spin_lock.c index 90b3abe..1e1a51f 100644 --- a/pthread_spin_lock.c +++ b/pthread_spin_lock.c @@ -60,12 +60,12 @@ pthread_spin_lock (pthread_spinlock_t * lock)    s = *lock; -  while ((PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED == -	 PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_LPLONG) & +  while ((PTW32_INTERLOCKED_VALUE) PTW32_SPIN_LOCKED == +	 PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_PTR) &  					     (s->interlock), -					     (PTW32_INTERLOCKED_LONG) +					     (PTW32_INTERLOCKED_VALUE)  					     PTW32_SPIN_LOCKED, -					     (PTW32_INTERLOCKED_LONG) +					     (PTW32_INTERLOCKED_VALUE)  					     PTW32_SPIN_UNLOCKED))      {      } diff --git a/pthread_spin_trylock.c b/pthread_spin_trylock.c index c601a19..fbcf526 100644 --- a/pthread_spin_trylock.c +++ b/pthread_spin_trylock.c @@ -61,11 +61,11 @@ pthread_spin_trylock (pthread_spinlock_t * lock)    s = *lock;    switch ((long) -	  PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_LPLONG) & +	  PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_PTR) &  					      (s->interlock), -					      (PTW32_INTERLOCKED_LONG) +					      (PTW32_INTERLOCKED_VALUE)  					      PTW32_SPIN_LOCKED, -					      (PTW32_INTERLOCKED_LONG) +					      (PTW32_INTERLOCKED_VALUE)  					      PTW32_SPIN_UNLOCKED))      {      case PTW32_SPIN_UNLOCKED: diff --git a/pthread_spin_unlock.c b/pthread_spin_unlock.c index 67bc2c2..c5317ea 100644 --- a/pthread_spin_unlock.c +++ b/pthread_spin_unlock.c @@ -56,11 +56,11 @@ pthread_spin_unlock (pthread_spinlock_t * lock)      }    switch ((long) -	  PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_LPLONG) & +	  PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_PTR) &  					      (s->interlock), -					      (PTW32_INTERLOCKED_LONG) +					      (PTW32_INTERLOCKED_VALUE)  					      PTW32_SPIN_UNLOCKED, -					      (PTW32_INTERLOCKED_LONG) +					      (PTW32_INTERLOCKED_VALUE)  					      PTW32_SPIN_LOCKED))      {      case PTW32_SPIN_LOCKED: diff --git a/pthread_win32_attach_detach_np.c b/pthread_win32_attach_detach_np.c index 25bcb95..6a42c93 100644 --- a/pthread_win32_attach_detach_np.c +++ b/pthread_win32_attach_detach_np.c @@ -209,8 +209,8 @@ pthread_win32_thread_detach_np ()                pthread_mutex_t mx = sp->robustMxList->mx;                ptw32_robust_mutex_remove(&mx, sp);                (void) PTW32_INTERLOCKED_EXCHANGE( -                       (LPLONG)&mx->robustNode->stateInconsistent, -                       -1L); +                       (PTW32_INTERLOCKED_PTR)&mx->robustNode->stateInconsistent, +                       (PTW32_INTERLOCKED_VALUE)-1);                /*                 * If there are no waiters then the next thread to block will                 * sleep, wakeup immediately and then go back to sleep. diff --git a/ptw32_InterlockedCompareExchange.c b/ptw32_InterlockedCompareExchange.c index 2a42b22..df0c0cc 100644 --- a/ptw32_InterlockedCompareExchange.c +++ b/ptw32_InterlockedCompareExchange.c @@ -49,10 +49,10 @@   * We now use this version wherever possible so we can inline it.   */ -PTW32_INTERLOCKED_LONG WINAPI -ptw32_InterlockedCompareExchange (PTW32_INTERLOCKED_LPLONG location, -				  PTW32_INTERLOCKED_LONG value, -				  PTW32_INTERLOCKED_LONG comparand) +PTW32_INTERLOCKED_VALUE WINAPI +ptw32_InterlockedCompareExchange (PTW32_INTERLOCKED_PTR location, +				  PTW32_INTERLOCKED_VALUE value, +				  PTW32_INTERLOCKED_VALUE comparand)  {  #if defined(__WATCOMC__) @@ -60,7 +60,7 @@ ptw32_InterlockedCompareExchange (PTW32_INTERLOCKED_LPLONG location,  #pragma disable_message (200)  #endif -  PTW32_INTERLOCKED_LONG result; +  PTW32_INTERLOCKED_VALUE result;    /*     * Using the LOCK prefix on uni-processor machines is significantly slower diff --git a/ptw32_MCS_lock.c b/ptw32_MCS_lock.c index d63ef5a..303fba9 100644 --- a/ptw32_MCS_lock.c +++ b/ptw32_MCS_lock.c @@ -102,10 +102,10 @@  INLINE void   ptw32_mcs_flag_set (LONG * flag)  { -  HANDLE e = (HANDLE)(size_t)PTW32_INTERLOCKED_COMPARE_EXCHANGE( -						(PTW32_INTERLOCKED_LPLONG)flag, -						(PTW32_INTERLOCKED_LONG)(size_t)-1, -						(PTW32_INTERLOCKED_LONG)(size_t)0); +  HANDLE e = (HANDLE)(PTW32_INTERLOCKED_VALUE)PTW32_INTERLOCKED_COMPARE_EXCHANGE( +						(PTW32_INTERLOCKED_PTR)flag, +						(PTW32_INTERLOCKED_VALUE)-1, +						(PTW32_INTERLOCKED_VALUE)0);    if ((HANDLE)0 != e)      {        /* another thread has already stored an event handle in the flag */ @@ -122,16 +122,16 @@ ptw32_mcs_flag_set (LONG * flag)  INLINE void   ptw32_mcs_flag_wait (LONG * flag)  { -  if (0 == PTW32_INTERLOCKED_EXCHANGE_ADD((LPLONG)flag, 0)) /* MBR fence */ +  if (0 == PTW32_INTERLOCKED_EXCHANGE_ADD((PTW32_INTERLOCKED_PTR)flag, (PTW32_INTERLOCKED_VALUE)0)) /* MBR fence */      {        /* the flag is not set. create event. */        HANDLE e = CreateEvent(NULL, PTW32_FALSE, PTW32_FALSE, NULL);        if (0 == PTW32_INTERLOCKED_COMPARE_EXCHANGE( -			                  (PTW32_INTERLOCKED_LPLONG)flag, -			                  (PTW32_INTERLOCKED_LONG)(size_t)e, -			                  (PTW32_INTERLOCKED_LONG)(size_t)0)) +			                  (PTW32_INTERLOCKED_PTR)flag, +			                  (PTW32_INTERLOCKED_VALUE)e, +			                  (PTW32_INTERLOCKED_VALUE)0))  	{  	  /* stored handle in the flag. wait on it now. */  	  WaitForSingleObject(e, INFINITE); @@ -191,7 +191,7 @@ 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 *)(size_t) -    PTW32_INTERLOCKED_EXCHANGE_ADD((LPLONG)&node->next, 0); /* MBR fence */ +    PTW32_INTERLOCKED_EXCHANGE_ADD((PTW32_INTERLOCKED_PTR)&node->next, (PTW32_INTERLOCKED_VALUE)0); /* MBR fence */    if (0 == next)      { @@ -209,7 +209,7 @@ ptw32_mcs_lock_release (ptw32_mcs_local_node_t * node)        /* wait for successor */        ptw32_mcs_flag_wait(&node->nextFlag);        next = (ptw32_mcs_local_node_t *)(size_t) -	PTW32_INTERLOCKED_EXCHANGE_ADD((PTW32_INTERLOCKED_LPLONG)&node->next, 0); /* MBR fence */ +	PTW32_INTERLOCKED_EXCHANGE_ADD((PTW32_INTERLOCKED_PTR)&node->next, (PTW32_INTERLOCKED_VALUE)0); /* MBR fence */      }    /* pass the lock */ @@ -60,7 +60,7 @@  #define PTW32_SCHED_LEVEL_MAX 3 -#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 )  || !defined(PTW32_LEVEL) +#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 )  || !defined(PTW32_SCHED_LEVEL)  #define PTW32_SCHED_LEVEL PTW32_SCHED_LEVEL_MAX  /* Include everything */  #endif @@ -123,10 +123,10 @@  /* Required by Unix 98 */  #  include <time.h>  # else -  typedef int pid_t; +   typedef int pid_t;  # endif  #else -typedef int pid_t; + typedef int pid_t;  #endif  /* Thread scheduling policies */  | 
