[pypy-commit] pypy nogil-unsafe-2: Fixes. Now the branch seems to "work" again
arigo
pypy.commits at gmail.com
Wed Aug 16 02:06:32 EDT 2017
Author: Armin Rigo <arigo at tunes.org>
Branch: nogil-unsafe-2
Changeset: r92157:cd60a593d1b4
Date: 2017-08-16 09:44 +0400
http://bitbucket.org/pypy/pypy/changeset/cd60a593d1b4/
Log: Fixes. Now the branch seems to "work" again
diff --git a/rpython/rlib/rgil.py b/rpython/rlib/rgil.py
--- a/rpython/rlib/rgil.py
+++ b/rpython/rlib/rgil.py
@@ -3,7 +3,7 @@
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
from rpython.rtyper.extregistry import ExtRegistryEntry
-from rpython.rlib.objectmodel import not_rpython
+from rpython.rlib.objectmodel import not_rpython, we_are_translated
# these functions manipulate directly the GIL, whose definition does not
# escape the C code itself
@@ -122,21 +122,24 @@
_gil_allocate()
def release():
- return
# this function must not raise, in such a way that the exception
# transformer knows that it cannot raise!
- _gil_release()
-#release._gctransformer_hint_cannot_collect_ = True
-#release._dont_reach_me_in_del_ = True
+ if we_are_translated():
+ _gil_release()
+release._gctransformer_hint_cannot_collect_ = True
+release._dont_reach_me_in_del_ = True
def acquire():
- return
- from rpython.rlib import rthread
- _gil_acquire()
- rthread.gc_thread_run()
- _after_thread_switch()
-#acquire._gctransformer_hint_cannot_collect_ = True
-#acquire._dont_reach_me_in_del_ = True
+ ###XXX commented some lines out for nogil-unsafe-2
+ ###XXX but note that _gil_acquire() does not acquire any GIL there!
+
+ ###from rpython.rlib import rthread
+ if we_are_translated():
+ _gil_acquire()
+ ###rthread.gc_thread_run()
+ ###_after_thread_switch()
+acquire._gctransformer_hint_cannot_collect_ = True
+acquire._dont_reach_me_in_del_ = True
# The _gctransformer_hint_cannot_collect_ hack is needed for
# translations in which the *_external_call() functions are not inlined.
diff --git a/rpython/translator/c/src/thread.h b/rpython/translator/c/src/thread.h
--- a/rpython/translator/c/src/thread.h
+++ b/rpython/translator/c/src/thread.h
@@ -75,22 +75,21 @@
SLOWPATH: signal "now at safepoint"; 111 -> 110
*/
-#define _RPyGilAcquire() /*do { \
- assert((__sync_fetch_and_add( \
- &RPY_THREADLOCALREF_GET(synclock), 0) \
- & 0b001) == 0b0); \
+
+/* in the nogil-unsafe-2 branch,
+ !! THIS IS NOT A GIL !! It's the logic to do global safe-points
+*/
+#define _RPyGilAcquire() do { \
if (!__sync_bool_compare_and_swap( \
&RPY_THREADLOCALREF_GET(synclock), 0b100L, 0b101L)) \
RPyGilAcquireSlowPath(); \
- } while (0)*/
+ } while (0)
-#define _RPyGilRelease() /*do { \
- assert((__sync_fetch_and_add( \
- &RPY_THREADLOCALREF_GET(synclock), 0) & 0b101) == 0b101); \
+#define _RPyGilRelease() do { \
if (!__sync_bool_compare_and_swap( \
&RPY_THREADLOCALREF_GET(synclock), 0b101L, 0b100L)) \
RPyGilReleaseSlowPath(); \
- } while (0)*/
+ } while (0)
static inline long *_RPyFetchFastGil(void) {
abort();
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
@@ -45,6 +45,10 @@
void RPyGilAcquireSlowPath(void)
{
+ assert((__sync_fetch_and_add(
+ &RPY_THREADLOCALREF_GET(synclock), 0)
+ & 0b001) == 0b0);
+
/* wait until the master leaves the safe point */
pthread_mutex_lock(&master_mutex);
@@ -63,6 +67,9 @@
void RPyGilReleaseSlowPath(void)
{
+ assert((__sync_fetch_and_add(
+ &RPY_THREADLOCALREF_GET(synclock), 0) & 0b101) == 0b101);
+
pthread_mutex_lock(&sync_mutex);
assert(RPY_THREADLOCALREF_GET(synclock) == 0b111L);
More information about the pypy-commit
mailing list