Author: Armin Rigo <ar...@tunes.org> Branch: c8-gil-like Changeset: r1793:f85a069a561e Date: 2015-06-07 11:57 +0200 http://bitbucket.org/pypy/stmgc/changeset/f85a069a561e/
Log: hg merge default diff --git a/c8/stm/core.h b/c8/stm/core.h --- a/c8/stm/core.h +++ b/c8/stm/core.h @@ -170,6 +170,10 @@ TS_INEVITABLE, }; +#define in_transaction(tl) \ + (get_segment((tl)->last_associated_segment_num)->running_thread == (tl)) + + /* Commit Log things */ struct stm_undo_s { union { diff --git a/c8/stm/extra.c b/c8/stm/extra.c --- a/c8/stm/extra.c +++ b/c8/stm/extra.c @@ -8,7 +8,7 @@ { dprintf(("register_callbacks: tl=%p key=%p callback=%p index=%ld\n", tl, key, callback, index)); - if (tl->associated_segment_num == -1) { + if (!in_transaction(tl)) { /* check that the provided thread-local is really running a transaction, and do nothing otherwise. */ dprintf((" NOT IN TRANSACTION\n")); diff --git a/c8/stm/forksupport.c b/c8/stm/forksupport.c --- a/c8/stm/forksupport.c +++ b/c8/stm/forksupport.c @@ -41,6 +41,7 @@ bool was_in_transaction = _stm_in_transaction(this_tl); if (!was_in_transaction) stm_start_transaction(this_tl); + assert(in_transaction(this_tl)); stm_become_inevitable(this_tl, "fork"); /* Note that the line above can still fail and abort, which should @@ -83,7 +84,8 @@ struct stm_priv_segment_info_s *pr = get_priv_segment(i); stm_thread_local_t *tl = pr->pub.running_thread; dprintf(("forksupport_child: abort in seg%ld\n", i)); - assert(tl->associated_segment_num == i); + assert(tl->last_associated_segment_num == i); + assert(in_transaction(tl)); assert(pr->transaction_state != TS_INEVITABLE); set_gs_register(get_segment_base(i)); assert(STM_SEGMENT->segment_num == i); @@ -150,7 +152,7 @@ /* Restore a few things: the new pthread_self(), and the %gs register */ - int segnum = fork_this_tl->associated_segment_num; + int segnum = fork_this_tl->last_associated_segment_num; assert(1 <= segnum && segnum < NB_SEGMENTS); *_get_cpth(fork_this_tl) = pthread_self(); set_gs_register(get_segment_base(segnum)); diff --git a/c8/stm/setup.c b/c8/stm/setup.c --- a/c8/stm/setup.c +++ b/c8/stm/setup.c @@ -244,7 +244,6 @@ /* assign numbers consecutively, but that's for tests; we could also assign the same number to all of them and they would get their own numbers automatically. */ - tl->associated_segment_num = -1; tl->last_associated_segment_num = num + 1; tl->thread_local_counter = ++thread_local_counters; *_get_cpth(tl) = pthread_self(); diff --git a/c8/stm/sync.c b/c8/stm/sync.c --- a/c8/stm/sync.c +++ b/c8/stm/sync.c @@ -176,8 +176,10 @@ sync_ctl.in_use1[num+1] = 1; assert(STM_SEGMENT->segment_num == num+1); assert(STM_SEGMENT->running_thread == NULL); - tl->associated_segment_num = tl->last_associated_segment_num; + assert(tl->last_associated_segment_num == STM_SEGMENT->segment_num); + assert(!in_transaction(tl)); STM_SEGMENT->running_thread = tl; + assert(in_transaction(tl)); return true; } @@ -188,9 +190,10 @@ cond_signal(C_SEGMENT_FREE); assert(STM_SEGMENT->running_thread == tl); - assert(tl->associated_segment_num == tl->last_associated_segment_num); - tl->associated_segment_num = -1; + assert(tl->last_associated_segment_num == STM_SEGMENT->segment_num); + assert(in_transaction(tl)); STM_SEGMENT->running_thread = NULL; + assert(!in_transaction(tl)); assert(sync_ctl.in_use1[tl->last_associated_segment_num] == 1); sync_ctl.in_use1[tl->last_associated_segment_num] = 0; @@ -204,22 +207,15 @@ bool _stm_in_transaction(stm_thread_local_t *tl) { - if (tl->associated_segment_num == -1) { - return false; - } - else { - int num = tl->associated_segment_num; - OPT_ASSERT(1 <= num && num < NB_SEGMENTS); - OPT_ASSERT(num == tl->last_associated_segment_num); - OPT_ASSERT(get_segment(num)->running_thread == tl); - return true; - } + int num = tl->last_associated_segment_num; + OPT_ASSERT(1 <= num && num < NB_SEGMENTS); + return in_transaction(tl); } void _stm_test_switch(stm_thread_local_t *tl) { assert(_stm_in_transaction(tl)); - set_gs_register(get_segment_base(tl->associated_segment_num)); + set_gs_register(get_segment_base(tl->last_associated_segment_num)); assert(STM_SEGMENT->running_thread == tl); exec_local_finalizers(); } diff --git a/c8/stmgc.h b/c8/stmgc.h --- a/c8/stmgc.h +++ b/c8/stmgc.h @@ -69,8 +69,7 @@ (this field is not modified on a successful commit) */ long last_abort__bytes_in_nursery; /* the next fields are handled internally by the library */ - int associated_segment_num; - int last_associated_segment_num; + int last_associated_segment_num; /* always a valid seg num */ int thread_local_counter; struct stm_thread_local_s *prev, *next; void *creating_pthread[2]; diff --git a/c8/test/support.py b/c8/test/support.py --- a/c8/test/support.py +++ b/c8/test/support.py @@ -29,7 +29,6 @@ char *mem_clear_on_abort; size_t mem_bytes_to_clear_on_abort; long last_abort__bytes_in_nursery; - int associated_segment_num; int last_associated_segment_num; struct stm_thread_local_s *prev, *next; void *creating_pthread[2]; @@ -798,8 +797,8 @@ seen = set() for tl1 in self.tls: if lib._stm_in_transaction(tl1): - assert tl1.associated_segment_num not in seen - seen.add(tl1.associated_segment_num) + assert tl1.last_associated_segment_num not in seen + seen.add(tl1.last_associated_segment_num) def commit_transaction(self): tl = self.tls[self.current_thread] diff --git a/c8/test/test_finalizer.py b/c8/test/test_finalizer.py --- a/c8/test/test_finalizer.py +++ b/c8/test/test_finalizer.py @@ -13,9 +13,10 @@ segnum = lib.current_segment_num() tlnum = '?' for n, tl in enumerate(self.tls): - if tl.associated_segment_num == segnum: - tlnum = n - break + if lib._stm_in_transaction(tl): + if tl.last_associated_segment_num == segnum: + tlnum = n + break self.light_finalizers_called.append((obj, tlnum)) self.light_finalizers_called = [] lib.stmcb_light_finalizer = light_finalizer _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit