Author: Armin Rigo <ar...@tunes.org> Branch: stm-gc Changeset: r52354:e71b8bc58097 Date: 2012-02-10 15:39 +0100 http://bitbucket.org/pypy/pypy/changeset/e71b8bc58097/
Log: Tweaks diff --git a/pypy/rlib/rstm.py b/pypy/rlib/rstm.py --- a/pypy/rlib/rstm.py +++ b/pypy/rlib/rstm.py @@ -18,9 +18,11 @@ arg = cast_base_ptr_to_instance(argcls, llarg) else: arg = lltype.TLS.stm_callback_arg - res = func(arg, retry_counter) - assert res is None - llop.stm_commit_transaction(lltype.Void) + try: + res = func(arg, retry_counter) + assert res is None + finally: + llop.stm_commit_transaction(lltype.Void) return lltype.nullptr(rffi.VOIDP.TO) return _stm_callback diff --git a/pypy/rpython/memory/gc/stmgc.py b/pypy/rpython/memory/gc/stmgc.py --- a/pypy/rpython/memory/gc/stmgc.py +++ b/pypy/rpython/memory/gc/stmgc.py @@ -119,7 +119,7 @@ if in_main_thread: tls.malloc_flags = GCFLAG_GLOBAL else: - tls.malloc_flags = 0 + tls.malloc_flags = -1 # don't malloc outside a transaction! return tls def _setup_secondary_thread(self): @@ -172,6 +172,8 @@ # modes, but set different flags. tls = self.collector.get_tls() flags = tls.malloc_flags + ll_assert(flags != -1, "malloc() in a transactional thread but " + "outside a transaction") # # Get the memory from the nursery. size_gc_header = self.gcheaderbuilder.size_gc_header @@ -192,6 +194,8 @@ # XXX Be more subtle, e.g. detecting overflows, at least tls = self.collector.get_tls() flags = tls.malloc_flags + ll_assert(flags != -1, "malloc() in a transactional thread but " + "outside a transaction") size_gc_header = self.gcheaderbuilder.size_gc_header nonvarsize = size_gc_header + size totalsize = nonvarsize + itemsize * length @@ -350,10 +354,10 @@ # ---------- def acquire(self, lock): - ll_thread.c_thread_acquirelock(lock, 1) + ll_thread.c_thread_acquirelock_NOAUTO(lock, 1) def release(self, lock): - ll_thread.c_thread_releaselock(lock) + ll_thread.c_thread_releaselock_NOAUTO(lock) # ---------- @@ -392,6 +396,7 @@ """Start a transaction, by clearing and resetting the tls nursery.""" tls = self.get_tls() self.gc.reset_nursery(tls) + tls.malloc_flags = 0 def commit_transaction(self): @@ -402,6 +407,7 @@ debug_start("gc-collect-commit") # tls = self.get_tls() + tls.malloc_flags = -1 # # Do a mark-and-move minor collection out of the tls' nursery # into the main thread's global area (which is right now also diff --git a/pypy/translator/stm/test/targetdemo.py b/pypy/translator/stm/test/targetdemo.py --- a/pypy/translator/stm/test/targetdemo.py +++ b/pypy/translator/stm/test/targetdemo.py @@ -17,10 +17,11 @@ glob = Global() class Arg: - _alloc_nonmovable_ = True + _alloc_nonmovable_ = True # XXX kill me def add_at_end_of_chained_list(arg, retry_counter): + assert arg.foobar == 42 node = arg.anchor value = arg.value x = Node(value) @@ -66,10 +67,14 @@ try: debug_print("thread starting...") arg = Arg() - for i in range(glob.LENGTH): + arg.foobar = 41 + i = 0 + while i < glob.LENGTH: arg.anchor = glob.anchor arg.value = i + arg.foobar = 42 rstm.perform_transaction(add_at_end_of_chained_list, Arg, arg) + i += 1 rstm.perform_transaction(increment_done, Arg, arg) finally: rstm.descriptor_done() _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit