Author: Tobias Weber <[email protected]>
Branch: c8-fix-commit-signalling
Changeset: r2084:f27950321d3c
Date: 2017-07-04 12:47 +0200
http://bitbucket.org/pypy/stmgc/changeset/f27950321d3c/
Log: Evaluate signal to commit only if running inevitable, and refactor
wait implementation of become inevitable method
diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -1571,7 +1571,7 @@
void _stm_become_inevitable(const char *msg)
{
- int num_waits = 0;
+ int num_waits = NB_SEGMENTS; //0; // TODO try disable
timing_become_inevitable();
@@ -1588,8 +1588,6 @@
stm_abort_transaction(); /* is already inevitable, abort */
#endif
- bool timed_out = false;
-
s_mutex_lock();
if (any_soon_finished_or_inevitable_thread_segment() &&
!safe_point_requested()) {
@@ -1598,36 +1596,33 @@
/* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */
EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE);
- if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ,
- 0.000054321))
- timed_out = true;
+ if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ,
0.00001)) {
+ s_mutex_unlock();
+ /* try to detach another inevitable transaction, but
+ only after waiting a bit. This is necessary to avoid
+ deadlocks in some situations, which are hopefully
+ not too common. We don't want two threads constantly
+ detaching each other. */
+ intptr_t detached = fetch_detached_transaction();
+ if (detached != 0) {
+ EMIT_WAIT_DONE();
+ commit_fetched_detached_transaction(detached);
+ }
+ goto retry_from_start;
+ }
+ num_waits++;
}
s_mutex_unlock();
-
- if (timed_out) {
- /* try to detach another inevitable transaction, but
- only after waiting a bit. This is necessary to avoid
- deadlocks in some situations, which are hopefully
- not too common. We don't want two threads constantly
- detaching each other. */
- intptr_t detached = fetch_detached_transaction();
- if (detached != 0) {
- EMIT_WAIT_DONE();
- commit_fetched_detached_transaction(detached);
- }
+ goto retry_from_start;
+ } else {
+ EMIT_WAIT_DONE();
+ if (!_validate_and_turn_inevitable()) {
+ goto retry_from_start;
}
- else {
- num_waits++;
- }
- goto retry_from_start;
}
- EMIT_WAIT_DONE();
- if (!_validate_and_turn_inevitable())
- goto retry_from_start;
}
- else {
- if (!_validate_and_turn_inevitable())
- return;
+ else if (!_validate_and_turn_inevitable()) {
+ return;
}
/* There may be a concurrent commit of a detached Tx going on.
diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c
--- a/c8/stm/nursery.c
+++ b/c8/stm/nursery.c
@@ -500,8 +500,10 @@
pseg->pub.nursery_current = (stm_char *)_stm_nursery_start;
pseg->pub.nursery_mark -= nursery_used;
- if (pseg->commit_if_not_atomic &&
pseg->pub.running_thread->self_or_0_if_atomic != 0) {
- // not atomic and commit signalled by waiting thread: commit
immediately
+ if (pseg->commit_if_not_atomic
+ && pseg->transaction_state == TS_INEVITABLE
+ && pseg->pub.running_thread->self_or_0_if_atomic != 0) {
+ // transaction is inevitable, not atomic, and commit has been
signalled by waiting thread: commit immediately
pseg->pub.nursery_mark = 0;
}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit