Author: Remi Meier <remi.me...@gmail.com> Branch: c7 Changeset: r623:feff1f2a98a1 Date: 2014-01-17 12:56 +0100 http://bitbucket.org/pypy/stmgc/changeset/feff1f2a98a1/
Log: changes in testing framework and fix diff --git a/c7/core.c b/c7/core.c --- a/c7/core.c +++ b/c7/core.c @@ -363,18 +363,20 @@ _STM_TL2->old_objects_to_trace = stm_list_append (_STM_TL2->old_objects_to_trace, obj); - obj->stm_flags &= ~GCFLAG_WRITE_BARRIER; - + /* for old objects from the same transaction we don't need to privatize the page */ if ((flag_page_private[pagenum] == UNCOMMITTED_SHARED_PAGE) || (obj->stm_flags & GCFLAG_NOT_COMMITTED)) { + obj->stm_flags &= ~GCFLAG_WRITE_BARRIER; return; } /* privatize if SHARED_PAGE */ _stm_privatize(pagenum); + obj->stm_flags &= ~GCFLAG_WRITE_BARRIER; + /* lock the object for writing in thread 0's page */ uintptr_t t0_offset = (uintptr_t)obj; char* t0_addr = get_thread_base(0) + t0_offset; @@ -382,7 +384,7 @@ int previous = __sync_lock_test_and_set(&t0_obj->stm_write_lock, 1); if (previous) - abort(); /* XXX */ + stm_abort_transaction(); stm_read(obj); diff --git a/c7/test/support.py b/c7/test/support.py --- a/c7/test/support.py +++ b/c7/test/support.py @@ -39,6 +39,7 @@ void stm_read(object_t *object); void stm_write(object_t *object); +bool _checked_stm_write(object_t *object); _Bool _stm_was_read(object_t *object); _Bool _stm_was_written(object_t *object); @@ -85,6 +86,20 @@ return 16; } + +bool _checked_stm_write(object_t *object) { + jmpbufptr_t here; + if (__builtin_setjmp(here) == 0) { // returned directly + assert(_STM_TL1->jmpbufptr == (jmpbufptr_t*)-1); + _STM_TL1->jmpbufptr = &here; + stm_write(object); + _STM_TL1->jmpbufptr = (jmpbufptr_t*)-1; + return 0; + } + _STM_TL1->jmpbufptr = (jmpbufptr_t*)-1; + return 1; +} + bool _stm_stop_transaction(void) { jmpbufptr_t here; if (__builtin_setjmp(here) == 0) { // returned directly @@ -238,7 +253,8 @@ lib.stm_read(o) def stm_write(o): - lib.stm_write(o) + if lib._checked_stm_write(o): + raise Conflict() def stm_was_read(o): return lib._stm_was_read(o) @@ -256,8 +272,7 @@ lib.stm_start_transaction(ffi.cast("jmpbufptr_t*", -1)) def stm_stop_transaction(): - res = lib._stm_stop_transaction() - if res: + if lib._stm_stop_transaction(): raise Conflict() @@ -265,8 +280,7 @@ lib._stm_start_safe_point() def stm_stop_safe_point(): - res = lib._stm_check_stop_safe_point() - if res: + if lib._stm_check_stop_safe_point(): raise Conflict() 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 @@ -282,29 +282,21 @@ self.switch(0) assert stm_get_char(lp1) == 'b' - + def test_resolve_write_write_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_write(lp1) + # + self.switch(1) + stm_start_transaction() + py.test.raises(Conflict, stm_write, lp1) # write-write conflict - # def test_resolve_write_write_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) - # assert p1[8] == 'a' - # stm_write(p1) - # p1[8] = 'c' - # stm_stop_transaction(expected_conflict=True) - # assert p1[8] in ('a', 'b') - # stm_start_transaction() - # assert p1[8] == 'b' + # def test_resolve_write_write_no_conflict(self): # stm_start_transaction() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit