Author: Remi Meier <[email protected]>
Branch: c7
Changeset: r622:c6c73c285527
Date: 2014-01-17 12:33 +0100
http://bitbucket.org/pypy/stmgc/changeset/c6c73c285527/
Log: fix and add tests
diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -150,42 +150,38 @@
struct tx_descriptor *in_single_thread = NULL;
-void stm_start_sharedlock(void)
+void stm_start_shared_lock(void)
{
int err = pthread_rwlock_rdlock(&rwlock_shared);
if (err != 0)
abort();
}
-void stm_stop_sharedlock(void)
+void stm_stop_lock(void)
{
int err = pthread_rwlock_unlock(&rwlock_shared);
if (err != 0)
abort();
}
-static void start_exclusivelock(void)
+static void stm_start_exclusive_lock(void)
{
int err = pthread_rwlock_wrlock(&rwlock_shared);
if (err != 0)
abort();
-}
-
-static void stop_exclusivelock(void)
-{
- int err = pthread_rwlock_unlock(&rwlock_shared);
- if (err != 0)
- abort();
+ if (_STM_TL2->need_abort) {
+ stm_abort_transaction();
+ }
}
void _stm_start_safe_point(void)
{
- stm_stop_sharedlock();
+ stm_stop_lock();
}
void _stm_stop_safe_point(void)
{
- stm_start_sharedlock();
+ stm_start_shared_lock();
if (_STM_TL2->need_abort)
stm_abort_transaction();
}
@@ -757,7 +753,7 @@
{
assert(!_STM_TL2->running_transaction);
- stm_start_sharedlock();
+ stm_start_shared_lock();
uint8_t old_rv = _STM_TL1->transaction_read_version;
_STM_TL1->transaction_read_version = old_rv + 1;
@@ -805,8 +801,8 @@
void stm_stop_transaction(void)
{
assert(_STM_TL2->running_transaction);
- stm_stop_sharedlock();
- start_exclusivelock();
+ stm_stop_lock();
+ stm_start_exclusive_lock();
_STM_TL1->jmpbufptr = NULL; /* cannot abort any more */
@@ -908,7 +904,7 @@
/* } */
_STM_TL2->running_transaction = 0;
- stop_exclusivelock();
+ stm_stop_lock();
}
void stm_abort_transaction(void)
@@ -927,6 +923,6 @@
assert(_STM_TL1->jmpbufptr != NULL);
assert(_STM_TL1->jmpbufptr != (jmpbufptr_t *)-1); /* for tests only */
_STM_TL2->running_transaction = 0;
- stm_stop_sharedlock();
+ stm_stop_lock();
__builtin_longjmp(*_STM_TL1->jmpbufptr, 1);
}
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -188,6 +188,9 @@
HDR = lib.SIZEOF_MYOBJ
+class Conflict(Exception):
+ pass
+
def is_in_nursery(o):
return lib._stm_is_young(o)
@@ -252,22 +255,19 @@
def stm_start_transaction():
lib.stm_start_transaction(ffi.cast("jmpbufptr_t*", -1))
-def stm_stop_transaction(expected_conflict=False):
+def stm_stop_transaction():
res = lib._stm_stop_transaction()
- if expected_conflict:
- assert res == 1
- else:
- assert res == 0
+ if res:
+ raise Conflict()
+
def stm_start_safe_point():
lib._stm_start_safe_point()
-def stm_stop_safe_point(expected_conflict=False):
+def stm_stop_safe_point():
res = lib._stm_check_stop_safe_point()
- if expected_conflict:
- assert res == 1
- else:
- assert res == 0
+ if res:
+ raise Conflict()
class BaseTest(object):
@@ -295,14 +295,12 @@
lib._stm_teardown_thread()
lib._stm_teardown()
- def switch(self, thread_num, expect_conflict=False):
+ def switch(self, thread_num):
assert thread_num != self.current_thread
if lib._stm_is_in_transaction():
stm_start_safe_point()
lib._stm_restore_local_state(thread_num)
if lib._stm_is_in_transaction():
- stm_stop_safe_point(expect_conflict)
- elif expect_conflict:
- assert False
+ stm_stop_safe_point()
self.current_thread = thread_num
diff --git a/c7/test/test_basic.py b/c7/test/test_basic.py
--- a/c7/test/test_basic.py
+++ b/c7/test/test_basic.py
@@ -1,5 +1,5 @@
from support import *
-
+import py
class TestBasic(BaseTest):
@@ -92,9 +92,9 @@
assert stm_get_char(lp1) == 'a'
#
self.switch(1)
- stm_stop_transaction(False)
+ stm_stop_transaction()
#
- self.switch(0, expect_conflict=True) # detects rw conflict
+ py.test.raises(Conflict, self.switch, 0) # detects rw conflict
def test_commit_fresh_objects(self):
stm_start_transaction()
@@ -207,10 +207,10 @@
#
self.switch(1)
stm_start_transaction()
- stm_stop_transaction(False)
+ stm_stop_transaction()
#
self.switch(0)
- stm_stop_transaction(False)
+ stm_stop_transaction()
def test_resolve_no_conflict_write_only_in_already_committed(self):
stm_start_transaction()
@@ -218,7 +218,7 @@
p1 = stm_get_real_address(lp1)
p1[HDR] = 'a'
stm_push_root(lp1)
- stm_stop_transaction(False)
+ stm_stop_transaction()
lp1 = stm_pop_root()
# 'a' in SHARED_PAGE
@@ -231,7 +231,7 @@
p1 = stm_get_real_address(lp1)
assert p1[HDR] == 'a'
p1[HDR] = 'b'
- stm_stop_transaction(False)
+ stm_stop_transaction()
# 'b' both private pages
#
self.switch(0)
@@ -239,29 +239,50 @@
assert p1[HDR] == 'b'
p1 = stm_get_real_address(lp1)
assert p1[HDR] == 'b'
- stm_stop_transaction(False)
+ stm_stop_transaction()
assert p1[HDR] == 'b'
- # def test_resolve_write_read_conflict(self):
- # stm_start_transaction()
- # p1 = stm_allocate(16)
- # p1[8] = 'a'
- # stm_stop_transaction(False)
- # stm_start_transaction()
- # #
- # self.switch(1)
- # stm_start_transaction()
- # stm_write(p1)
- # p1[8] = 'b'
- # stm_stop_transaction(False)
- # #
- # self.switch(0)
- # stm_read(p1)
- # assert p1[8] == 'a'
- # stm_stop_transaction(expected_conflict=True)
- # assert p1[8] in ('a', 'b')
- # stm_start_transaction()
- # assert p1[8] == 'b'
+ def test_not_resolve_write_read_conflict(self):
+ stm_start_transaction()
+ lp1 = stm_allocate(16)
+ stm_set_char(lp1, 'a')
+ stm_push_root(lp1)
+ stm_stop_transaction()
+ lp1 = stm_pop_root()
+
+ stm_start_transaction()
+ stm_read(lp1)
+ #
+ self.switch(1)
+ stm_start_transaction()
+ stm_write(lp1)
+ stm_set_char(lp1, 'b')
+ stm_stop_transaction()
+ #
+ py.test.raises(Conflict, self.switch, 0)
+ stm_start_transaction()
+ assert stm_get_char(lp1) == 'b'
+
+ def test_resolve_write_read_conflict(self):
+ stm_start_transaction()
+ lp1 = stm_allocate(16)
+ stm_set_char(lp1, 'a')
+ stm_push_root(lp1)
+ stm_stop_transaction()
+ lp1 = stm_pop_root()
+
+ stm_start_transaction()
+ #
+ self.switch(1)
+ stm_start_transaction()
+ stm_write(lp1)
+ stm_set_char(lp1, 'b')
+ stm_stop_transaction()
+ #
+ self.switch(0)
+ assert stm_get_char(lp1) == 'b'
+
+
# def test_resolve_write_write_conflict(self):
# stm_start_transaction()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit