[pypy-commit] pypy stm-thread: Adapt test_stmgcintf.*.
arigo
noreply at buildbot.pypy.org
Sat May 12 11:20:14 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm-thread
Changeset: r55053:ac4b908afa0f
Date: 2012-05-12 11:19 +0200
http://bitbucket.org/pypy/pypy/changeset/ac4b908afa0f/
Log: Adapt test_stmgcintf.*.
diff --git a/pypy/translator/stm/src_stm/core.c b/pypy/translator/stm/src_stm/core.c
--- a/pypy/translator/stm/src_stm/core.c
+++ b/pypy/translator/stm/src_stm/core.c
@@ -275,12 +275,17 @@
#ifdef USE_PTHREAD_MUTEX
/* mutex: only to avoid busy-looping too much in tx_spinloop() below */
+
+# if defined(RPY_STM_ASSERT) && defined(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP)
+static pthread_mutex_t mutex_inevitable = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+# else
+static pthread_mutex_t mutex_inevitable = PTHREAD_MUTEX_INITIALIZER;
+# endif
+
# ifndef RPY_STM_ASSERT
-static pthread_mutex_t mutex_inevitable = PTHREAD_MUTEX_INITIALIZER;
# define mutex_lock() pthread_mutex_lock(&mutex_inevitable)
# define mutex_unlock() pthread_mutex_unlock(&mutex_inevitable)
# else
-static pthread_mutex_t mutex_inevitable = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
static unsigned long locked_by = 0;
static void mutex_lock(void)
{
@@ -671,12 +676,6 @@
/************************************************************/
-long stm_thread_id(void)
-{
- struct tx_descriptor *d = thread_descriptor;
- return d->my_lock_word;
-}
-
static __thread void *rpython_tls_object;
void stm_set_tls(void *newtls)
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
@@ -15,7 +15,6 @@
void stm_set_tls(void *);
void *stm_get_tls(void);
void stm_del_tls(void);
-long stm_thread_id(void);
void *stm_tldict_lookup(void *);
void stm_tldict_add(void *, void *);
@@ -35,11 +34,8 @@
void stm_perform_transaction(long(*)(void*, long), void*, void*);
-/* these functions are declared by generated C code from pypy.rlib.rstm
- and from the GC (see llop.nop(...)) */
-extern void pypy_g__stm_thread_starting(void);
-extern void pypy_g__stm_thread_stopping(void);
-extern void *pypy_g__stm_run_transaction(void *, long);
+/* these functions are declared by generated C code from the GC
+ (see llop.nop(...)) */
extern long pypy_g__stm_getsize(void *);
extern void pypy_g__stm_enum_callback(void *, void *, void *);
diff --git a/pypy/translator/stm/stmgcintf.py b/pypy/translator/stm/stmgcintf.py
--- a/pypy/translator/stm/stmgcintf.py
+++ b/pypy/translator/stm/stmgcintf.py
@@ -68,10 +68,6 @@
get_tls = smexternal('stm_get_tls', [], llmemory.Address)
del_tls = smexternal('stm_del_tls', [], lltype.Void)
- # return the current thread id (a random non-null number, or 0 for
- # the main thread)
- thread_id = smexternal('stm_thread_id', [], lltype.Signed)
-
# lookup, add, and enumerate the content of the internal dictionary
# that maps GLOBAL objects to LOCAL objects
tldict_lookup = smexternal('stm_tldict_lookup', [llmemory.Address],
diff --git a/pypy/translator/stm/test/test_stmgcintf.c b/pypy/translator/stm/test/test_stmgcintf.c
--- a/pypy/translator/stm/test/test_stmgcintf.c
+++ b/pypy/translator/stm/test/test_stmgcintf.c
@@ -32,27 +32,9 @@
#include "src_stm/et.c"
-void *(*cb_run_transaction)(void *, long);
long (*cb_getsize)(void *);
void (*cb_enum_callback)(void *, void *, void *);
-int _thread_started = 0;
-
-
-void pypy_g__stm_thread_starting(void) {
- assert(_thread_started == 0);
- _thread_started = 1;
- stm_set_tls((void *)742, 0);
-}
-void pypy_g__stm_thread_stopping(void) {
- assert(_thread_started == 1);
- _thread_started = 0;
- stm_del_tls();
-}
-void *pypy_g__stm_run_transaction(void *a, long b) {
- assert(cb_run_transaction != NULL);
- return cb_run_transaction(a, b);
-}
long pypy_g__stm_getsize(void *a) {
assert(cb_getsize != NULL);
return cb_getsize(a);
@@ -63,52 +45,51 @@
}
-void *rt2(void *t1, long retry_counter)
+static long rt2(void *t1, long retry_counter)
{
struct pypy_pypy_rlib_rstm_Transaction0 *t = t1;
if (retry_counter > 0) {
t->foobar = retry_counter;
- return NULL;
+ return 0;
}
t->callback();
t->foobar = '.';
- return NULL;
+ return 0;
}
void run_in_transaction(void(*cb)(void), int expected)
{
struct pypy_pypy_rlib_rstm_Transaction0 t;
+ void *dummy;
t.callback = cb;
- cb_run_transaction = rt2;
- stm_run_all_transactions(&t, 1);
+ stm_perform_transaction(rt2, &t, &dummy);
assert(t.foobar == expected);
-
}
/************************************************************/
void test_set_get_del(void)
{
- stm_set_tls((void *)42, 1);
+ stm_set_tls((void *)42);
assert(stm_get_tls() == (void *)42);
stm_del_tls();
}
/************************************************************/
-void *rt1(void *t1, long retry_counter)
+static long rt1(void *t1, long retry_counter)
{
struct pypy_pypy_rlib_rstm_Transaction0 *t = t1;
assert(retry_counter == 0);
assert(t->foobar == 42);
t->foobar = 143;
- return NULL;
+ return 0;
}
void test_run_all_transactions(void)
{
struct pypy_pypy_rlib_rstm_Transaction0 t;
+ void *dummy;
t.foobar = 42;
- cb_run_transaction = rt1;
- stm_run_all_transactions(&t, 1);
+ stm_perform_transaction(rt1, &t, &dummy);
assert(t.foobar == 143);
}
@@ -191,6 +172,7 @@
void *a3 = (void *)0x4028;
void *a4 = (void *)10004;
+ stm_set_tls((void *)742);
stm_tldict_add(a1, a2);
stm_tldict_add(a3, a4);
cb_enum_callback = check_enum_1;
@@ -208,6 +190,7 @@
{
S1 s1;
int i;
+ stm_begin_inevitable_transaction();
for (i=0; i<2; i++) {
s1.header.h_tid = GCFLAG_GLOBAL | (i ? GCFLAG_WAS_COPIED : 0);
s1.header.h_version = NULL;
@@ -331,14 +314,14 @@
void try_inevitable(void)
{
assert(stm_in_transaction() == 1);
- assert(stm_thread_id() != 0);
+ assert(!stm_is_inevitable());
/* not really testing anything more than the presence of the function */
stm_try_inevitable(STM_EXPLAIN1("some explanation"));
+ assert(stm_is_inevitable());
}
void test_try_inevitable(void)
{
assert(stm_in_transaction() == 0);
- assert(stm_thread_id() == 0);
run_in_transaction(try_inevitable, '.');
}
@@ -349,6 +332,8 @@
int main(int argc, char **argv)
{
+ long res = stm_descriptor_init();
+ assert(res == 1);
XTEST(set_get_del);
XTEST(run_all_transactions);
XTEST(tldict);
More information about the pypy-commit
mailing list