[pypy-commit] pypy stm: add the stm_thread_id() helper
arigo
noreply at buildbot.pypy.org
Mon Jan 23 17:30:23 CET 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51689:6eb15b35a17d
Date: 2012-01-23 16:16 +0100
http://bitbucket.org/pypy/pypy/changeset/6eb15b35a17d/
Log: add the stm_thread_id() helper
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
@@ -38,3 +38,4 @@
stm_abort_and_retry = llexternal('stm_abort_and_retry', [], lltype.Void)
stm_debug_get_state = llexternal('stm_debug_get_state', [], lltype.Signed)
+stm_thread_id = llexternal('stm_thread_id', [], lltype.Signed)
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
@@ -71,13 +71,14 @@
unsigned num_aborts[ABORT_REASONS];
unsigned num_spinloops[SPINLOOP_REASONS];
unsigned int spinloop_counter;
+ int transaction_active;
owner_version_t my_lock_word;
struct RedoLog redolog; /* last item, because it's the biggest one */
- int transaction_active;
};
static const struct tx_descriptor null_tx = {
- .transaction_active = 0
+ .transaction_active = 0,
+ .my_lock_word = 0
};
#define NULL_TX ((struct tx_descriptor *)(&null_tx))
@@ -833,4 +834,10 @@
return 2;
}
+long stm_thread_id(void)
+{
+ struct tx_descriptor *d = thread_descriptor;
+ return d->my_lock_word;
+}
+
#endif /* PYPY_NOT_MAIN_FILE */
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
@@ -31,6 +31,8 @@
0: not in a transaction
1: in a regular transaction
2: in an inevitable transaction */
+long stm_thread_id(void); /* returns a unique thread id,
+ or 0 if descriptor_init() was not called */
// XXX little-endian only!
/* this macro is used if 'base' is a word-aligned pointer and 'offset'
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
@@ -68,3 +68,10 @@
stm_perform_transaction(llhelper(CALLBACK, callback1),
lltype.nullptr(rffi.VOIDP.TO))
stm_descriptor_done()
+
+def test_stm_thread_id():
+ assert stm_thread_id() == 0
+ stm_descriptor_init()
+ assert stm_thread_id() != 0
+ stm_descriptor_done()
+ assert stm_thread_id() == 0
More information about the pypy-commit
mailing list