[pypy-commit] pypy fast-gil: On Windows, a "mutex" does too much by linking to which thread locked it. A "semaphore" doesn't.

arigo noreply at buildbot.pypy.org
Tue Jun 24 21:01:49 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: fast-gil
Changeset: r72204:c00cc7d1e7c8
Date: 2014-06-24 21:01 +0200
http://bitbucket.org/pypy/pypy/changeset/c00cc7d1e7c8/

Log:	On Windows, a "mutex" does too much by linking to which thread
	locked it. A "semaphore" doesn't.

diff --git a/rpython/translator/c/src/thread_nt.c b/rpython/translator/c/src/thread_nt.c
--- a/rpython/translator/c/src/thread_nt.c
+++ b/rpython/translator/c/src/thread_nt.c
@@ -196,7 +196,7 @@
 /* GIL code                                                 */
 /************************************************************/
 
-typedef HANDLE mutex_t;
+typedef HANDLE mutex_t;   /* a semaphore, on Windows */
 
 static void gil_fatal(const char *msg) {
     fprintf(stderr, "Fatal error in the GIL: %s\n", msg);
@@ -204,9 +204,9 @@
 }
 
 static inline void mutex_init(mutex_t *mutex) {
-    *mutex = CreateMutex(NULL, 0, NULL);
+    *mutex = CreateSemaphore(NULL, 1, 1, NULL);
     if (*mutex == NULL)
-        gil_fatal("CreateMutex failed");
+        gil_fatal("CreateSemaphore failed");
 }
 
 static inline void mutex_lock(mutex_t *mutex) {
@@ -214,7 +214,7 @@
 }
 
 static inline void mutex_unlock(mutex_t *mutex) {
-    ReleaseMutex(*mutex);
+    ReleaseSemaphore(*mutex, 1, NULL);
 }
 
 static inline int mutex_lock_timeout(mutex_t *mutex, double delay)


More information about the pypy-commit mailing list