Author: Armin Rigo <[email protected]>
Branch: stm-thread-2
Changeset: r60178:3fe775d4717c
Date: 2013-01-18 16:42 +0100
http://bitbucket.org/pypy/pypy/changeset/3fe775d4717c/
Log: Fix at least one of the ztranslated test: test_targetdemo.
diff --git a/pypy/translator/c/src/mem.c b/pypy/translator/c/src/mem.c
--- a/pypy/translator/c/src/mem.c
+++ b/pypy/translator/c/src/mem.c
@@ -15,25 +15,37 @@
static struct pypy_debug_alloc_s *pypy_debug_alloc_list = NULL;
+#ifdef RPY_STM
+# include "src_stm/atomic_ops.h"
+static volatile Unsigned pypy_debug_alloc_lock = 0;
+#else
+# define stm_lock_acquire(lock) /* nothing */
+# define stm_lock_release(lock) /* nothing */
+#endif
+
void pypy_debug_alloc_start(void *addr, const char *funcname)
{
struct pypy_debug_alloc_s *p = malloc(sizeof(struct pypy_debug_alloc_s));
RPyAssert(p, "out of memory");
- p->next = pypy_debug_alloc_list;
p->addr = addr;
p->funcname = funcname;
+ stm_lock_acquire(pypy_debug_alloc_lock);
+ p->next = pypy_debug_alloc_list;
pypy_debug_alloc_list = p;
+ stm_lock_release(pypy_debug_alloc_lock);
}
void pypy_debug_alloc_stop(void *addr)
{
struct pypy_debug_alloc_s **p;
+ stm_lock_acquire(pypy_debug_alloc_lock);
for (p = &pypy_debug_alloc_list; *p; p = &((*p)->next))
if ((*p)->addr == addr)
{
struct pypy_debug_alloc_s *dying;
dying = *p;
*p = dying->next;
+ stm_lock_release(pypy_debug_alloc_lock);
free(dying);
return;
}
diff --git a/pypy/translator/stm/src_stm/atomic_ops.h
b/pypy/translator/stm/src_stm/atomic_ops.h
--- a/pypy/translator/stm/src_stm/atomic_ops.h
+++ b/pypy/translator/stm/src_stm/atomic_ops.h
@@ -33,13 +33,13 @@
#else
/* x86 (32 bits and 64 bits) */
static inline _Bool
-bool_cas(volatile revision_t *ptr, revision_t old, revision_t _new)
+bool_cas(volatile Unsigned *ptr, Unsigned old, Unsigned _new)
{
- revision_t prev;
+ Unsigned prev;
#if defined(__amd64__)
- assert(sizeof(revision_t) == 8);
+ assert(sizeof(Unsigned) == 8);
#elif defined(__i386__)
- assert(sizeof(revision_t) == 4);
+ assert(sizeof(Unsigned) == 4);
#else
# error "the custom version of bool_cas() is only for x86 or x86-64"
#endif
@@ -67,4 +67,11 @@
}
+#define stm_lock_acquire(lock) \
+ do { while (!bool_cas(&(lock), 0, 1)) spinloop(); } while (0)
+
+#define stm_lock_release(lock) \
+ (lock) = 0;
+
+
#endif /* _SRCSTM_ATOMIC_OPS_ */
diff --git a/pypy/translator/stm/test/test_ztranslated.py
b/pypy/translator/stm/test/test_ztranslated.py
--- a/pypy/translator/stm/test/test_ztranslated.py
+++ b/pypy/translator/stm/test/test_ztranslated.py
@@ -6,7 +6,7 @@
class TestNoGcSTMTranslated(NoGcCompiledSTMTests):
- def test_targetdemo(self):
+ def test_nogc_targetdemo(self):
t, cbuilder = self.compile(targetdemo2.entry_point)
data, dataerr = cbuilder.cmdexec('4 100', err=True)
assert 'check ok!' in data
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit