[Python-checkins] r55173 - python/branches/release25-maint/Python/thread_nt.h

kristjan.jonsson python-checkins at python.org
Mon May 7 20:28:18 CEST 2007


Author: kristjan.jonsson
Date: Mon May  7 20:28:12 2007
New Revision: 55173

Modified:
   python/branches/release25-maint/Python/thread_nt.h
Log:
Fix NonRecursiveMutex on x64.  The signature of the faux-InterlockedCompareExchange function was wrong:  It works with LONG and not PVOID objects, and it needs to have the target marked as volatile.  Further, it is not needed at all for x64 targets, since that platform always has the real McCoy.

Modified: python/branches/release25-maint/Python/thread_nt.h
==============================================================================
--- python/branches/release25-maint/Python/thread_nt.h	(original)
+++ python/branches/release25-maint/Python/thread_nt.h	Mon May  7 20:28:12 2007
@@ -15,14 +15,14 @@
 	HANDLE hevent ;
 } NRMUTEX, *PNRMUTEX ;
 
-typedef PVOID WINAPI interlocked_cmp_xchg_t(PVOID *dest, PVOID exc, PVOID comperand) ;
+typedef LONG WINAPI interlocked_cmp_xchg_t(LONG volatile *dest, LONG exc, LONG comperand) ;
 
 /* Sorry mate, but we haven't got InterlockedCompareExchange in Win95! */
-static PVOID WINAPI
-interlocked_cmp_xchg(PVOID *dest, PVOID exc, PVOID comperand)
+static LONG WINAPI
+interlocked_cmp_xchg(LONG volatile *dest, LONG exc, LONG comperand)
 {
 	static LONG spinlock = 0 ;
-	PVOID result ;
+	LONG result ;
 	DWORD dwSleep = 0;
 
 	/* Acqire spinlock (yielding control to other threads if cant aquire for the moment) */
@@ -76,10 +76,12 @@
 	return mutex->hevent != NULL ;	/* TRUE if the mutex is created */
 }
 
+#ifndef MS_WIN64
 #ifdef InterlockedCompareExchange
 #undef InterlockedCompareExchange
 #endif
 #define InterlockedCompareExchange(dest,exchange,comperand) (ixchg((dest), (exchange), (comperand)))
+#endif
 
 VOID
 DeleteNonRecursiveMutex(PNRMUTEX mutex)
@@ -98,7 +100,7 @@
 	/* InterlockedIncrement(&mutex->owned) == 0 means that no thread currently owns the mutex */
 	if (!wait)
 	{
-		if (InterlockedCompareExchange((PVOID *)&mutex->owned, (PVOID)0, (PVOID)-1) != (PVOID)-1)
+		if (InterlockedCompareExchange(&mutex->owned, 0, -1) != -1)
 			return WAIT_TIMEOUT ;
 		ret = WAIT_OBJECT_0 ;
 	}


More information about the Python-checkins mailing list