From: H.G. Muller Date: Sun, 7 Feb 2010 15:43:36 +0000 (+0100) Subject: Remove race condition in clock switching X-Git-Tag: v4.4.3.20100220~13 X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=6bd78a44338ad11ff03a2ac554e6fd5bd5ed8418;p=xboard.git Remove race condition in clock switching The move number is now incremented inside SwitchClock, when no timer interrupt is scheduled, so the interrupt cannot occur at the wrong side of the increment, and decrement the wrong clock. --- diff --git a/backend.c b/backend.c index 2f7ee57..ecf338c 100644 --- a/backend.c +++ b/backend.c @@ -189,7 +189,7 @@ void ParseGameHistory P((char *game)); void ParseBoard12 P((char *string)); void KeepAlive P((void)); void StartClocks P((void)); -void SwitchClocks P((void)); +void SwitchClocks P((int nr)); void StopClocks P((void)); void ResetClocks P((void)); char *PGNDate P((void)); @@ -3048,10 +3048,10 @@ read_from_ics(isr, closure, data, count, error) looking_at(buf, &i, "It is not your move")) { /* Illegal move */ if (ics_user_moved && forwardMostMove > backwardMostMove) { // only backup if we already moved - currentMove = --forwardMostMove; + currentMove = forwardMostMove-1; DisplayMove(currentMove - 1); /* before DMError */ DrawPosition(FALSE, boards[currentMove]); - SwitchClocks(); + SwitchClocks(forwardMostMove-1); // [HGM] race DisplayBothClocks(); } DisplayMoveError(_("Illegal move (rejected by ICS)")); // [HGM] but always relay error msg @@ -6657,9 +6657,9 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. gameMode = EditGame; ModeHighlight(); } - currentMove = --forwardMostMove; + currentMove = forwardMostMove-1; DisplayMove(currentMove-1); /* before DisplayMoveError */ - SwitchClocks(); + SwitchClocks(forwardMostMove-1); // [HGM] race DisplayBothClocks(); sprintf(buf1, _("Illegal move \"%s\" (rejected by %s chess program)"), parseList[currentMove], cps->which); @@ -7737,8 +7737,8 @@ MakeMove(fromX, fromY, toX, toY, promoChar) {int i; for(i=0; i= 0) lastTickLength = 0; blackTimeRemaining -= lastTickLength; /* [HGM] PGNtime: save time for PGN file if engine did not give it */ @@ -13390,6 +13390,7 @@ SwitchClocks() } flagged = CheckFlags(); } + forwardMostMove = newMoveNr; // [HGM] race: change stm when no timer interrupt scheduled CheckTimeControl(); if (flagged || !appData.clockMode) return;