[pypy-commit] pypy fast-gil: On Windows, save the LastError in addition to the errno

arigo noreply at buildbot.pypy.org
Wed Jun 25 19:48:07 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: fast-gil
Changeset: r72230:a0d7c3cc50e7
Date: 2014-06-25 19:47 +0200
http://bitbucket.org/pypy/pypy/changeset/a0d7c3cc50e7/

Log:	On Windows, save the LastError in addition to the errno

diff --git a/rpython/translator/c/src/thread_gil.c b/rpython/translator/c/src/thread_gil.c
--- a/rpython/translator/c/src/thread_gil.c
+++ b/rpython/translator/c/src/thread_gil.c
@@ -68,7 +68,7 @@
     }
     else {
         /* Otherwise, another thread is busy with the GIL. */
-        int old_errno = errno;
+        SAVE_ERRNO();
 
         /* Register me as one of the threads that is actively waiting
            for the GIL.  The number of such threads is found in
@@ -109,7 +109,7 @@
         atomic_decrement(&rpy_waiting_threads);
         mutex_unlock(&mutex_gil_stealer);
 
-        errno = old_errno;
+        RESTORE_ERRNO();
     }
     assert(RPY_FASTGIL_LOCKED(rpy_fastgil));
 
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
@@ -227,4 +227,9 @@
 #define atomic_increment(ptr)          InterlockedIncrement(ptr)
 #define atomic_decrement(ptr)          InterlockedDecrement(ptr)
 
+#define SAVE_ERRNO()      int saved_errno = errno; \
+                          DWORD saved_lasterr = GetLastError()
+#define RESTORE_ERRNO()   errno = saved_errno; \
+                          SetLastError(saved_lasterr)
+
 #include "src/thread_gil.c"
diff --git a/rpython/translator/c/src/thread_pthread.c b/rpython/translator/c/src/thread_pthread.c
--- a/rpython/translator/c/src/thread_pthread.c
+++ b/rpython/translator/c/src/thread_pthread.c
@@ -517,4 +517,7 @@
 #define atomic_increment(ptr)          __sync_fetch_and_add(ptr, 1)
 #define atomic_decrement(ptr)          __sync_fetch_and_sub(ptr, 1)
 
+#define SAVE_ERRNO()      int saved_errno = errno
+#define RESTORE_ERRNO()   errno = saved_errno
+
 #include "src/thread_gil.c"


More information about the pypy-commit mailing list