Author: Armin Rigo <[email protected]>
Branch:
Changeset: r973:6718bfcdc402
Date: 2014-03-11 10:28 +0100
http://bitbucket.org/pypy/stmgc/changeset/6718bfcdc402/
Log: PyPy calls stm_call_on_abort() even outside transactions.
diff --git a/c7/stm/extra.c b/c7/stm/extra.c
--- a/c7/stm/extra.c
+++ b/c7/stm/extra.c
@@ -3,9 +3,14 @@
#endif
-void stm_call_on_abort(void *key, void callback(void *))
+void stm_call_on_abort(stm_thread_local_t *tl,
+ void *key, void callback(void *))
{
- assert(_running_transaction());
+ if (!_stm_in_transaction(tl)) {
+ /* check that the current thread-local is really running a
+ transaction, and do nothing otherwise. */
+ return;
+ }
if (STM_PSEGMENT->transaction_state == TS_INEVITABLE) {
/* ignore callbacks if we're in an inevitable transaction
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -282,7 +282,7 @@
can only register one callback per key. You can call
'stm_call_on_abort(key, NULL)' to cancel an existing callback.
Note: 'key' must be aligned to a multiple of 8 bytes. */
-void stm_call_on_abort(void *key, void callback(void *));
+void stm_call_on_abort(stm_thread_local_t *, void *key, void callback(void *));
/* ==================== END ==================== */
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -81,7 +81,7 @@
void stm_set_prebuilt_identityhash(object_t *obj, uint64_t hash);
int stm_can_move(object_t *);
-void stm_call_on_abort(void *key, void callback(void *));
+void stm_call_on_abort(stm_thread_local_t *, void *key, void callback(void *));
""")
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
@@ -39,17 +39,17 @@
p[0] = chr(ord(p[0]) + 1)
#
self.start_transaction()
- lib.stm_call_on_abort(p0, clear_me)
+ lib.stm_call_on_abort(self.get_stm_thread_local(), p0, clear_me)
# the registered callbacks are removed on
# successful commit
self.commit_transaction()
assert ffi.string(p0) == "aaa"
#
self.start_transaction()
- lib.stm_call_on_abort(p1, clear_me)
- lib.stm_call_on_abort(p2, clear_me)
- lib.stm_call_on_abort(p3, clear_me)
- lib.stm_call_on_abort(p2, ffi.NULL)
+ lib.stm_call_on_abort(self.get_stm_thread_local(), p1, clear_me)
+ lib.stm_call_on_abort(self.get_stm_thread_local(), p2, clear_me)
+ lib.stm_call_on_abort(self.get_stm_thread_local(), p3, clear_me)
+ lib.stm_call_on_abort(self.get_stm_thread_local(), p2, ffi.NULL)
assert ffi.string(p0) == "aaa"
assert ffi.string(p1) == "hello"
assert ffi.string(p2) == "removed"
@@ -68,3 +68,15 @@
assert ffi.string(p1) == "iello"
assert ffi.string(p2) == "removed"
assert ffi.string(p3) == "xorld"
+
+ def test_ignores_if_outside_transaction(self):
+ @ffi.callback("void(void *)")
+ def dont_see_me(p):
+ seen.append(p)
+ #
+ seen = []
+ p0 = ffi_new_aligned("aaa")
+ lib.stm_call_on_abort(self.get_stm_thread_local(), p0, dont_see_me)
+ self.start_transaction()
+ self.abort_transaction()
+ assert seen == []
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit