[pypy-commit] stmgc default: stm_atomic().
arigo
noreply at buildbot.pypy.org
Sun Jun 30 19:48:42 CEST 2013
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r324:59eb9a85c3d1
Date: 2013-06-30 19:48 +0200
http://bitbucket.org/pypy/stmgc/changeset/59eb9a85c3d1/
Log: stm_atomic().
diff --git a/c4/et.c b/c4/et.c
--- a/c4/et.c
+++ b/c4/et.c
@@ -903,6 +903,15 @@
d->reads_size_limit = d->atomic ? ULONG_MAX : d->reads_size_limit_nonatomic;
}
+long stm_atomic(long delta)
+{
+ struct tx_descriptor *d = thread_descriptor;
+ d->atomic += delta;
+ assert(d->atomic >= 0);
+ update_reads_size_limit(d);
+ return d->atomic;
+}
+
static void init_transaction(struct tx_descriptor *d)
{
assert(d->active == 0);
diff --git a/c4/stmgc.h b/c4/stmgc.h
--- a/c4/stmgc.h
+++ b/c4/stmgc.h
@@ -77,6 +77,13 @@
void stm_set_transaction_length(long length_max);
_Bool stm_should_break_transaction(void);
+/* change the atomic counter by 'delta' and return the new value. Used
+ with +1 to enter or with -1 to leave atomic mode, or with 0 to just
+ know the current value of the counter. The current transaction is
+ *never* interrupted as long as this counter is positive. */
+long stm_atomic(long delta);
+
+
/* callback: get the size of an object */
extern size_t stmcb_size(gcptr);
diff --git a/c4/test/support.py b/c4/test/support.py
--- a/c4/test/support.py
+++ b/c4/test/support.py
@@ -62,6 +62,7 @@
void stm_begin_inevitable_transaction(void);
void stm_set_transaction_length(long length_max);
_Bool stm_should_break_transaction(void);
+ long stm_atomic(long delta);
/* extra non-public code */
void printfcolor(char *msg);
diff --git a/c4/test/test_atomic.py b/c4/test/test_atomic.py
--- a/c4/test/test_atomic.py
+++ b/c4/test/test_atomic.py
@@ -31,3 +31,28 @@
should_br[i + 1] = should_break_transaction()
#
assert should_br == [False, False, False, False, True, True, True]
+
+def test_stm_atomic():
+ assert lib.stm_atomic(0) == 0
+ x = lib.stm_atomic(+1)
+ assert x == 1
+ x = lib.stm_atomic(+1)
+ assert x == 2
+ x = lib.stm_atomic(-1)
+ assert x == 1
+ x = lib.stm_atomic(0)
+ assert x == 1
+ x = lib.stm_atomic(-1)
+ assert x == 0
+
+def test_transaction_atomic_mode():
+ assert lib.stm_in_transaction()
+ lib.stm_commit_transaction()
+ assert not lib.stm_in_transaction()
+ lib.stm_begin_inevitable_transaction()
+ assert lib.stm_in_transaction()
+ lib.stm_atomic(+1)
+ lib.stm_commit_transaction()
+ assert lib.stm_in_transaction()
+ lib.stm_begin_inevitable_transaction()
+ lib.stm_atomic(-1)
More information about the pypy-commit
mailing list