Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r72912:ffabe32cdcb9
Date: 2014-08-19 18:52 +0200
http://bitbucket.org/pypy/pypy/changeset/ffabe32cdcb9/

Log:    import stmgc/bea13491352f

diff --git a/rpython/translator/stm/src_stm/revision 
b/rpython/translator/stm/src_stm/revision
--- a/rpython/translator/stm/src_stm/revision
+++ b/rpython/translator/stm/src_stm/revision
@@ -1,1 +1,1 @@
-1d2c771f29c4
+bea13491352f
diff --git a/rpython/translator/stm/src_stm/stm/extra.c 
b/rpython/translator/stm/src_stm/stm/extra.c
--- a/rpython/translator/stm/src_stm/stm/extra.c
+++ b/rpython/translator/stm/src_stm/stm/extra.c
@@ -4,50 +4,51 @@
 #endif
 
 
-static bool register_callbacks(stm_thread_local_t *tl,
+static long register_callbacks(stm_thread_local_t *tl,
                                void *key, void callback(void *), long index)
 {
     if (!_stm_in_transaction(tl)) {
         /* check that the current thread-local is really running a
            transaction, and do nothing otherwise. */
-        return false;
+        return -1;
     }
 
     if (STM_PSEGMENT->transaction_state == TS_INEVITABLE) {
         /* ignore callbacks if we're in an inevitable transaction
            (which cannot abort) */
-        return false;
+        return -1;
     }
 
     struct tree_s *callbacks;
     callbacks = STM_PSEGMENT->callbacks_on_commit_and_abort[index];
 
     if (callback == NULL) {
-        /* ignore the return value: unregistered keys can be
-           "deleted" again */
-        tree_delete_item(callbacks, (uintptr_t)key);
+        /* double-unregistering works, but return 0 */
+        return tree_delete_item(callbacks, (uintptr_t)key);
     }
     else {
         /* double-registering the same key will crash */
         tree_insert(callbacks, (uintptr_t)key, (uintptr_t)callback);
+        return 1;
     }
-    return true;
 }
 
-void stm_call_on_commit(stm_thread_local_t *tl,
+long stm_call_on_commit(stm_thread_local_t *tl,
                        void *key, void callback(void *))
 {
-    if (!register_callbacks(tl, key, callback, 0)) {
+    long result = register_callbacks(tl, key, callback, 0);
+    if (result < 0 && callback != NULL) {
         /* no regular transaction running, invoke the callback
            immediately */
         callback(key);
     }
+    return result;
 }
 
-void stm_call_on_abort(stm_thread_local_t *tl,
+long stm_call_on_abort(stm_thread_local_t *tl,
                        void *key, void callback(void *))
 {
-    register_callbacks(tl, key, callback, 1);
+    return register_callbacks(tl, key, callback, 1);
 }
 
 static void invoke_and_clear_user_callbacks(long index)
diff --git a/rpython/translator/stm/src_stm/stmgc.h 
b/rpython/translator/stm/src_stm/stmgc.h
--- a/rpython/translator/stm/src_stm/stmgc.h
+++ b/rpython/translator/stm/src_stm/stmgc.h
@@ -413,15 +413,16 @@
 /* If the current transaction aborts later, invoke 'callback(key)'.  If
    the current transaction commits, then the callback is forgotten.  You
    can only register one callback per key.  You can call
-   'stm_call_on_abort(key, NULL)' to cancel an existing callback.
+   'stm_call_on_abort(key, NULL)' to cancel an existing callback
+   (returns 0 if there was no existing callback to cancel).
    Note: 'key' must be aligned to a multiple of 8 bytes. */
-void stm_call_on_abort(stm_thread_local_t *, void *key, void callback(void *));
+long stm_call_on_abort(stm_thread_local_t *, void *key, void callback(void *));
 
 /* If the current transaction commits later, invoke 'callback(key)'.  If
    the current transaction aborts, then the callback is forgotten.  Same
    restrictions as stm_call_on_abort().  If the transaction is or becomes
    inevitable, 'callback(key)' is called immediately. */
-void stm_call_on_commit(stm_thread_local_t *, void *key, void callback(void 
*));
+long stm_call_on_commit(stm_thread_local_t *, void *key, void callback(void 
*));
 
 
 /* Similar to stm_become_inevitable(), but additionally suspend all
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to