[pypy-commit] pypy stm-gc: Fix the tests and add in_main_thread() as an stm call.

arigo noreply at buildbot.pypy.org
Thu Feb 9 17:13:47 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r52312:75b3f0c7b338
Date: 2012-02-09 17:12 +0100
http://bitbucket.org/pypy/pypy/changeset/75b3f0c7b338/

Log:	Fix the tests and add in_main_thread() as an stm call.

diff --git a/pypy/rpython/memory/gc/stmgc.py b/pypy/rpython/memory/gc/stmgc.py
--- a/pypy/rpython/memory/gc/stmgc.py
+++ b/pypy/rpython/memory/gc/stmgc.py
@@ -286,6 +286,8 @@
         #
         @dont_inline
         def _stm_write_barrier_global(obj):
+            if stm_operations.in_main_thread():
+                return obj
             # we need to find of make a local copy
             hdr = self.header(obj)
             if hdr.tid & GCFLAG_WAS_COPIED == 0:
diff --git a/pypy/rpython/memory/gc/test/test_stmgc.py b/pypy/rpython/memory/gc/test/test_stmgc.py
--- a/pypy/rpython/memory/gc/test/test_stmgc.py
+++ b/pypy/rpython/memory/gc/test/test_stmgc.py
@@ -26,6 +26,9 @@
     def setup_size_getter(self, getsize_fn):
         self._getsize_fn = getsize_fn
 
+    def in_main_thread(self):
+        return self.threadnum == 0
+
     def set_tls(self, tls, in_main_thread):
         assert lltype.typeOf(tls) == llmemory.Address
         assert tls
@@ -304,6 +307,11 @@
         u_adr = self.gc.stm_writebarrier(u_adr)  # local object
         assert u_adr == t_adr
 
+    def test_write_barrier_main_thread(self):
+        t, t_adr = self.malloc(S)
+        obj = self.gc.stm_writebarrier(t_adr)     # main thread
+        assert obj == t_adr
+
     def test_commit_transaction_empty(self):
         self.select_thread(1)
         s, s_adr = self.malloc(S)
diff --git a/pypy/translator/stm/src_stm/et.c b/pypy/translator/stm/src_stm/et.c
--- a/pypy/translator/stm/src_stm/et.c
+++ b/pypy/translator/stm/src_stm/et.c
@@ -685,7 +685,7 @@
   if (is_main_thread(d))
     return;
 
-#ifdef RPY_STM_ASSERT
+#ifdef RPY_STM_DEBUG_PRINT
   PYPY_DEBUG_START("stm-inevitable");
   if (PYPY_HAVE_DEBUG_PRINTS)
     {
@@ -696,7 +696,7 @@
 
   if (is_inevitable(d))
     {
-#ifdef RPY_STM_ASSERT
+#ifdef RPY_STM_DEBUG_PRINT
       PYPY_DEBUG_STOP("stm-inevitable");
 #endif
       return;  /* I am already inevitable */
@@ -726,7 +726,7 @@
       mutex_unlock();
     }
   d->setjmp_buf = NULL;   /* inevitable from now on */
-#ifdef RPY_STM_ASSERT
+#ifdef RPY_STM_DEBUG_PRINT
   PYPY_DEBUG_STOP("stm-inevitable");
 #endif
 }
@@ -803,4 +803,10 @@
   rpython_get_size = getsize_fn;
 }
 
+long stm_in_main_thread(void)
+{
+  struct tx_descriptor *d = thread_descriptor;
+  return is_main_thread(d);
+}
+
 #endif  /* PYPY_NOT_MAIN_FILE */
diff --git a/pypy/translator/stm/stmgcintf.py b/pypy/translator/stm/stmgcintf.py
--- a/pypy/translator/stm/stmgcintf.py
+++ b/pypy/translator/stm/stmgcintf.py
@@ -18,6 +18,8 @@
     setup_size_getter = smexternal('stm_setup_size_getter', [GETSIZE],
                                    lltype.Void)
 
+    in_main_thread = smexternal('stm_in_main_thread', [], lltype.Signed)
+
     set_tls = smexternal('stm_set_tls', [llmemory.Address, lltype.Signed],
                          lltype.Void)
     get_tls = smexternal('stm_get_tls', [], llmemory.Address)
diff --git a/pypy/translator/stm/test/test_stmgcintf.py b/pypy/translator/stm/test/test_stmgcintf.py
--- a/pypy/translator/stm/test/test_stmgcintf.py
+++ b/pypy/translator/stm/test/test_stmgcintf.py
@@ -173,3 +173,10 @@
         lltype.free(s2, flavor='raw')
         lltype.free(s1, flavor='raw')
     test_stm_copy_transactional_to_raw.in_main_thread = False
+
+    def test_in_main_thread(self):
+        assert stm_operations.in_main_thread()
+
+    def test_not_in_main_thread(self):
+        assert not stm_operations.in_main_thread()
+    test_not_in_main_thread.in_main_thread = False


More information about the pypy-commit mailing list