[pypy-commit] pypy stm: Aborting works, even in fully untranslated py.tests.

arigo noreply at buildbot.pypy.org
Tue Sep 27 14:29:28 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r47622:72c3dfe0e868
Date: 2011-09-27 14:17 +0200
http://bitbucket.org/pypy/pypy/changeset/72c3dfe0e868/

Log:	Aborting works, even in fully untranslated py.tests.

diff --git a/pypy/translator/stm/_rffi_stm.py b/pypy/translator/stm/_rffi_stm.py
--- a/pypy/translator/stm/_rffi_stm.py
+++ b/pypy/translator/stm/_rffi_stm.py
@@ -11,12 +11,6 @@
 eci = ExternalCompilationInfo(
     include_dirs = [cdir],
     includes = ['src_stm/et.h'],
-    post_include_bits = [
-        r'''#define stm_begin_transaction_inline()  ; \
-              jmp_buf _jmpbuf;                   \
-              setjmp(_jmpbuf);                   \
-              stm_begin_transaction(&_jmpbuf);
-        '''],
     separate_module_sources = ['#include "src_stm/et.c"\n'],
 )
 
@@ -38,3 +32,5 @@
 CALLBACK = lltype.Ptr(lltype.FuncType([rffi.VOIDP], rffi.VOIDP))
 perform_transaction = llexternal('stm_perform_transaction',
                                  [CALLBACK, rffi.VOIDP], rffi.VOIDP)
+
+abort_and_retry = llexternal('stm_abort_and_retry', [], lltype.Void)
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
@@ -51,7 +51,7 @@
 /* Uncomment the line to try this extra code.  Doesn't work reliably so far */
 /*#define COMMIT_OTHER_INEV*/
 
-#define ABORT_REASONS 7
+#define ABORT_REASONS 8
 #define SPINLOOP_REASONS 10
 #define OTHERINEV_REASONS 5
 
@@ -574,8 +574,7 @@
 void* stm_perform_transaction(void*(*callback)(void*), void *arg)
 {
   void *result;
-  jmp_buf jmpbuf;
-  stm_begin_transaction(&jmpbuf);
+  stm_begin_transaction_inline();
   result = callback(arg);
   stm_commit_transaction();
   return result;
@@ -743,3 +742,8 @@
   d_inev_checking = 1;
 #endif
 }
+
+void stm_abort_and_retry(void)
+{
+  tx_abort(7);     /* manual abort */
+}
diff --git a/pypy/translator/stm/src_stm/et.h b/pypy/translator/stm/src_stm/et.h
--- a/pypy/translator/stm/src_stm/et.h
+++ b/pypy/translator/stm/src_stm/et.h
@@ -20,6 +20,12 @@
 void stm_write_word(void** addr, void* val);
 void stm_try_inevitable(void);
 void stm_begin_inevitable_transaction(void);
+void stm_abort_and_retry(void);
+
+#define stm_begin_transaction_inline()  ; \
+       jmp_buf _jmpbuf;                   \
+       setjmp(_jmpbuf);                   \
+       stm_begin_transaction(&_jmpbuf)
 
 
 #endif  /* _ET_H */
diff --git a/pypy/translator/stm/test/test_rffi_stm.py b/pypy/translator/stm/test/test_rffi_stm.py
--- a/pypy/translator/stm/test/test_rffi_stm.py
+++ b/pypy/translator/stm/test/test_rffi_stm.py
@@ -12,3 +12,20 @@
     perform_transaction(llhelper(CALLBACK, callback1),
                         lltype.nullptr(rffi.VOIDP.TO))
     descriptor_done()
+
+def test_abort_and_retry():
+    A = lltype.Struct('A', ('x', lltype.Signed), ('y', lltype.Signed))
+    a = lltype.malloc(A, immortal=True, flavor='raw')
+    a.y = 0
+    def callback1(x):
+        if a.y < 10:
+            a.y += 1    # non-transactionally
+            abort_and_retry()
+        else:
+            a.x = 42 * a.y
+            return lltype.nullptr(rffi.VOIDP.TO)
+    descriptor_init()
+    perform_transaction(llhelper(CALLBACK, callback1),
+                        lltype.nullptr(rffi.VOIDP.TO))
+    descriptor_done()
+    assert a.x == 420


More information about the pypy-commit mailing list