Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r1094:4024e96d9ba2
Date: 2014-03-25 14:10 +0100
http://bitbucket.org/pypy/stmgc/changeset/4024e96d9ba2/

Log:    Add an extra argument to stm_become_inevitable() just for testing.

diff --git a/c7/demo/demo_random.c b/c7/demo/demo_random.c
--- a/c7/demo/demo_random.c
+++ b/c7/demo/demo_random.c
@@ -285,12 +285,12 @@
         return (objptr_t)-1; // break current
     } else if (get_rand(20) == 1) {
         push_roots();
-        stm_become_inevitable("please");
+        stm_become_inevitable(&stm_thread_local, "please");
         pop_roots();
         return NULL;
     } else if (get_rand(240) == 1) {
         push_roots();
-        stm_become_globally_unique_transaction("really");
+        stm_become_globally_unique_transaction(&stm_thread_local, "really");
         fprintf(stderr, "[GUT/%d]", (int)STM_SEGMENT->segment_num);
         pop_roots();
         return NULL;
diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -676,9 +676,10 @@
     s_mutex_unlock();
 }
 
-void stm_become_globally_unique_transaction(const char *msg)
+void stm_become_globally_unique_transaction(stm_thread_local_t *tl,
+                                            const char *msg)
 {
-    stm_become_inevitable(msg);   /* may still abort */
+    stm_become_inevitable(tl, msg);   /* may still abort */
 
     s_mutex_lock();
     synchronize_all_threads(STOP_OTHERS_AND_BECOME_GLOBALLY_UNIQUE);
diff --git a/c7/stm/forksupport.c b/c7/stm/forksupport.c
--- a/c7/stm/forksupport.c
+++ b/c7/stm/forksupport.c
@@ -60,7 +60,7 @@
 
     bool was_in_transaction = _stm_in_transaction(this_tl);
     if (was_in_transaction) {
-        stm_become_inevitable("fork");
+        stm_become_inevitable(this_tl, "fork");
         /* Note that the line above can still fail and abort, which should
            be fine */
     }
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -275,7 +275,9 @@
 /* Turn the current transaction inevitable.  The 'jmpbuf' passed to
    STM_START_TRANSACTION() is not going to be used any more after
    this call (but the stm_become_inevitable() itself may still abort). */
-static inline void stm_become_inevitable(const char* msg) {
+static inline void stm_become_inevitable(stm_thread_local_t *tl,
+                                         const char* msg) {
+    assert(STM_SEGMENT->running_thread == tl);
     if (STM_SEGMENT->jmpbuf_ptr != NULL)
         _stm_become_inevitable(msg);
 }
@@ -330,7 +332,8 @@
    transaction is running concurrently.  Avoid as much as possible.
    Other transactions will continue running only after this transaction
    commits. */
-void stm_become_globally_unique_transaction(const char *msg);
+void stm_become_globally_unique_transaction(stm_thread_local_t *tl,
+                                            const char *msg);
 
 
 /* ==================== END ==================== */
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -53,8 +53,8 @@
 void _stm_start_transaction(stm_thread_local_t *tl, stm_jmpbuf_t *jmpbuf);
 bool _check_commit_transaction(void);
 bool _check_abort_transaction(void);
-bool _check_become_inevitable(void);
-bool _check_become_globally_unique_transaction(void);
+bool _check_become_inevitable(stm_thread_local_t *tl);
+bool _check_become_globally_unique_transaction(stm_thread_local_t *tl);
 int stm_is_inevitable(void);
 
 void _set_type_id(object_t *obj, uint32_t h);
@@ -158,12 +158,12 @@
     CHECKED(stm_abort_transaction());
 }
 
-bool _check_become_inevitable() {
-    CHECKED(stm_become_inevitable("TEST"));
+bool _check_become_inevitable(stm_thread_local_t *tl) {
+    CHECKED(stm_become_inevitable(tl, "TEST"));
 }
 
-bool _check_become_globally_unique_transaction() {
-    CHECKED(stm_become_globally_unique_transaction("TESTGUT"));
+bool _check_become_globally_unique_transaction(stm_thread_local_t *tl) {
+    CHECKED(stm_become_globally_unique_transaction(tl, "TESTGUT"));
 }
 
 #undef CHECKED
@@ -358,14 +358,6 @@
     if lib._check_stop_safe_point():
         raise Conflict()
 
-def stm_become_inevitable():
-    if lib._check_become_inevitable():
-        raise Conflict()
-
-def stm_become_globally_unique_transaction():
-    if lib._check_become_globally_unique_transaction():
-        raise Conflict()
-
 def stm_minor_collect():
     lib.stm_collect(0)
 
@@ -515,3 +507,13 @@
     def set_thread_local_obj(self, newobj):
         tl = self.tls[self.current_thread]
         tl.thread_local_obj = newobj
+
+    def become_inevitable(self):
+        tl = self.tls[self.current_thread]
+        if lib._check_become_inevitable(tl):
+            raise Conflict()
+
+    def become_globally_unique_transaction(self):
+        tl = self.tls[self.current_thread]
+        if lib._check_become_globally_unique_transaction(tl):
+            raise Conflict()
diff --git a/c7/test/test_basic.py b/c7/test/test_basic.py
--- a/c7/test/test_basic.py
+++ b/c7/test/test_basic.py
@@ -383,7 +383,7 @@
         stm_write(lp1)
         stm_set_char(lp1, 'b')
         assert lib.stm_is_inevitable() == 0
-        stm_become_inevitable()
+        self.become_inevitable()
         assert lib.stm_is_inevitable() == 1
         self.commit_transaction()
         #
diff --git a/c7/test/test_extra.py b/c7/test/test_extra.py
--- a/c7/test/test_extra.py
+++ b/c7/test/test_extra.py
@@ -86,7 +86,7 @@
         #
         self.switch(1)
         self.start_transaction()
-        lib._check_become_globally_unique_transaction()
+        self.become_globally_unique_transaction()
         assert lib.stm_is_inevitable()
         #
         py.test.raises(Conflict, self.switch, 0)
diff --git a/c7/test/test_random.py b/c7/test/test_random.py
--- a/c7/test/test_random.py
+++ b/c7/test/test_random.py
@@ -346,7 +346,7 @@
 
     thread_state.push_roots(ex)
     ex.do(raising_call(trs.check_must_abort(),
-                       "stm_become_inevitable"))
+                       "self.become_inevitable"))
     if trs.check_must_abort():
         thread_state.abort_transaction()
     else:
diff --git a/c7/test/test_weakref.py b/c7/test/test_weakref.py
--- a/c7/test/test_weakref.py
+++ b/c7/test/test_weakref.py
@@ -176,7 +176,7 @@
         # back in thread 0, we pop toref from the shadowstack
         # in an inevitable transaction
         self.start_transaction()
-        stm_become_inevitable()
+        self.become_inevitable()
         self.pop_root() # forget toref
         stm_major_collect()
 
diff --git a/duhton/glob.c b/duhton/glob.c
--- a/duhton/glob.c
+++ b/duhton/glob.c
@@ -126,7 +126,7 @@
     }
 
     _du_save1(lst);
-    stm_become_inevitable("print");
+    stm_become_inevitable(&stm_thread_local, "print");
     _du_restore1(lst);
 
     int i;
diff --git a/gil-c7/stmgc.h b/gil-c7/stmgc.h
--- a/gil-c7/stmgc.h
+++ b/gil-c7/stmgc.h
@@ -95,8 +95,12 @@
     _stm_tloc = NULL;
     if (pthread_mutex_unlock(&_stm_gil) != 0) abort();
 }
-inline static void stm_become_inevitable(const char *msg) { }
+inline static void stm_become_inevitable(
+    stm_thread_local_t *tl, const char *msg) { }
 inline static void _stm_become_inevitable(const char *msg) { }
+inline static void stm_become_globally_unique_transaction(
+    stm_thread_local_t *tl, const char *msg) { }
+
 static inline int stm_is_inevitable(void) { return 1; }
 inline static void stm_read(object_t *ob) { }
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to