Author: Remi Meier <remi.me...@gmail.com> Branch: c7 Changeset: r605:0789b61edcca Date: 2014-01-14 15:16 +0100 http://bitbucket.org/pypy/stmgc/changeset/0789b61edcca/
Log: address conversion functions diff --git a/c7/core.c b/c7/core.c --- a/c7/core.c +++ b/c7/core.c @@ -182,11 +182,33 @@ return REAL_ADDRESS(_STM_TL2->thread_base, src); } + static char *get_thread_base(long thread_num) { return object_pages + thread_num * (NB_PAGES * 4096UL); } + +char *_stm_real_address(object_t *o) +{ + if (o == NULL) + return NULL; + assert(FIRST_OBJECT_PAGE * 4096 <= (uintptr_t)o + && (uintptr_t)o < NB_PAGES * 4096); + return real_address((uintptr_t)o); +} + +object_t *_stm_tl_address(char *ptr) +{ + if (ptr == NULL) + return NULL; + + uintptr_t res = ptr - _STM_TL2->thread_base; + assert(FIRST_OBJECT_PAGE * 4096 <= res + && res < NB_PAGES * 4096); + return (object_t*)res; +} + void stm_abort_transaction(void); enum detect_conflicts_e { CANNOT_CONFLICT, CAN_CONFLICT }; diff --git a/c7/core.h b/c7/core.h --- a/c7/core.h +++ b/c7/core.h @@ -90,5 +90,6 @@ void stm_setup_thread(void); void stm_start_transaction(jmpbufptr_t *jmpbufptr); void stm_stop_transaction(void); - +char *_stm_real_address(object_t *o); +object_t *_stm_tl_address(char *ptr); #endif diff --git a/c7/test/support.py b/c7/test/support.py --- a/c7/test/support.py +++ b/c7/test/support.py @@ -2,6 +2,7 @@ import cffi # ---------- +os.environ['CC'] = 'clang' parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -44,6 +45,8 @@ void _stm_teardown(void); void _stm_teardown_thread(void); +char *_stm_real_address(object_t *o); +object_t *_stm_tl_address(char *ptr); void *memset(void *s, int c, size_t n); """) @@ -63,23 +66,21 @@ extra_compile_args=['-g', '-O0', '-Werror'], force_generic_engine=True) -def intptr(p): - return int(ffi.cast("intptr_t", p)) def stm_allocate(size): - return ffi.cast("char *", lib.stm_allocate(size)) + return lib._stm_real_address(lib.stm_allocate(size)) def stm_read(ptr): - lib.stm_read(ffi.cast("struct object_s *", ptr)) + lib.stm_read(lib._stm_tl_address(ptr)) def stm_write(ptr): - lib.stm_write(ffi.cast("struct object_s *", ptr)) + lib.stm_write(lib._stm_tl_address(ptr)) def _stm_was_read(ptr): - return lib._stm_was_read(ffi.cast("struct object_s *", ptr)) + return lib._stm_was_read(lib._stm_tl_address(ptr)) def _stm_was_written(ptr): - return lib._stm_was_written(ffi.cast("struct object_s *", ptr)) + return lib._stm_was_written(lib._stm_tl_address(ptr)) def stm_start_transaction(): lib.stm_start_transaction() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit