Fossil SCM
When sleeping inside the backoffice work loop, permit the sleep to be interrupted on Win32, which stops processing.
Commit
9840313b1ce0b528bbedbfcd0cea921c2058a2b822bdef452e44acd4dee2151e
Parent
f13ae35f5e2cfd1…
1 file changed
+33
-2
+33
-2
| --- src/backoffice.c | ||
| +++ src/backoffice.c | ||
| @@ -87,10 +87,27 @@ | ||
| 87 | 87 | */ |
| 88 | 88 | void backoffice_no_delay(void){ |
| 89 | 89 | backofficeNoDelay = 1; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | + | |
| 93 | +/* | |
| 94 | +** Sleeps for the specified number of milliseconds -OR- until interrupted | |
| 95 | +** by another thread (if supported by the underlying platform). Non-zero | |
| 96 | +** will be returned if the sleep was interrupted. | |
| 97 | +*/ | |
| 98 | +static int backofficeSleep(int milliseconds){ | |
| 99 | +#if defined(_WIN32) | |
| 100 | + assert( milliseconds>=0 ); | |
| 101 | + if( SleepEx((DWORD)milliseconds, TRUE)==WAIT_IO_COMPLETION ){ | |
| 102 | + return 1; | |
| 103 | + } | |
| 104 | +#else | |
| 105 | + sqlite3_sleep(milliseconds); | |
| 106 | +#endif | |
| 107 | + return 0; | |
| 108 | +} | |
| 92 | 109 | |
| 93 | 110 | /* |
| 94 | 111 | ** Parse a unsigned 64-bit integer from a string. Return a pointer |
| 95 | 112 | ** to the character of z[] that occurs after the integer. |
| 96 | 113 | */ |
| @@ -330,20 +347,34 @@ | ||
| 330 | 347 | db_end_transaction(0); |
| 331 | 348 | if( g.fAnyTrace ){ |
| 332 | 349 | fprintf(stderr, "/***** Backoffice On-deck %d *****/\n", getpid()); |
| 333 | 350 | } |
| 334 | 351 | if( x.tmCurrent >= tmNow ){ |
| 335 | - sqlite3_sleep(1000*(x.tmCurrent - tmNow + 1)); | |
| 352 | + if( backofficeSleep(1000*(x.tmCurrent - tmNow + 1)) ){ | |
| 353 | + /* The sleep was interrupted by a signal from another thread. */ | |
| 354 | + if( g.fAnyTrace ){ | |
| 355 | + fprintf(stderr, "/***** Backoffice Interrupt %d *****/\n", getpid()); | |
| 356 | + } | |
| 357 | + db_end_transaction(0); | |
| 358 | + break; | |
| 359 | + } | |
| 336 | 360 | }else{ |
| 337 | 361 | if( lastWarning+warningDelay < tmNow ){ |
| 338 | 362 | fossil_warning( |
| 339 | 363 | "backoffice process %lld still running after %d seconds", |
| 340 | 364 | x.idCurrent, (int)(BKOFCE_LEASE_TIME + tmNow - x.tmCurrent)); |
| 341 | 365 | lastWarning = tmNow; |
| 342 | 366 | warningDelay *= 2; |
| 343 | 367 | } |
| 344 | - sqlite3_sleep(1000); | |
| 368 | + if( backofficeSleep(1000) ){ | |
| 369 | + /* The sleep was interrupted by a signal from another thread. */ | |
| 370 | + if( g.fAnyTrace ){ | |
| 371 | + fprintf(stderr, "/***** Backoffice Interrupt %d *****/\n", getpid()); | |
| 372 | + } | |
| 373 | + db_end_transaction(0); | |
| 374 | + break; | |
| 375 | + } | |
| 345 | 376 | } |
| 346 | 377 | } |
| 347 | 378 | #if defined(_WIN32) |
| 348 | 379 | backofficeWin32ThreadCleanup(); |
| 349 | 380 | #endif |
| 350 | 381 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -87,10 +87,27 @@ | |
| 87 | */ |
| 88 | void backoffice_no_delay(void){ |
| 89 | backofficeNoDelay = 1; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /* |
| 94 | ** Parse a unsigned 64-bit integer from a string. Return a pointer |
| 95 | ** to the character of z[] that occurs after the integer. |
| 96 | */ |
| @@ -330,20 +347,34 @@ | |
| 330 | db_end_transaction(0); |
| 331 | if( g.fAnyTrace ){ |
| 332 | fprintf(stderr, "/***** Backoffice On-deck %d *****/\n", getpid()); |
| 333 | } |
| 334 | if( x.tmCurrent >= tmNow ){ |
| 335 | sqlite3_sleep(1000*(x.tmCurrent - tmNow + 1)); |
| 336 | }else{ |
| 337 | if( lastWarning+warningDelay < tmNow ){ |
| 338 | fossil_warning( |
| 339 | "backoffice process %lld still running after %d seconds", |
| 340 | x.idCurrent, (int)(BKOFCE_LEASE_TIME + tmNow - x.tmCurrent)); |
| 341 | lastWarning = tmNow; |
| 342 | warningDelay *= 2; |
| 343 | } |
| 344 | sqlite3_sleep(1000); |
| 345 | } |
| 346 | } |
| 347 | #if defined(_WIN32) |
| 348 | backofficeWin32ThreadCleanup(); |
| 349 | #endif |
| 350 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -87,10 +87,27 @@ | |
| 87 | */ |
| 88 | void backoffice_no_delay(void){ |
| 89 | backofficeNoDelay = 1; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /* |
| 94 | ** Sleeps for the specified number of milliseconds -OR- until interrupted |
| 95 | ** by another thread (if supported by the underlying platform). Non-zero |
| 96 | ** will be returned if the sleep was interrupted. |
| 97 | */ |
| 98 | static int backofficeSleep(int milliseconds){ |
| 99 | #if defined(_WIN32) |
| 100 | assert( milliseconds>=0 ); |
| 101 | if( SleepEx((DWORD)milliseconds, TRUE)==WAIT_IO_COMPLETION ){ |
| 102 | return 1; |
| 103 | } |
| 104 | #else |
| 105 | sqlite3_sleep(milliseconds); |
| 106 | #endif |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | ** Parse a unsigned 64-bit integer from a string. Return a pointer |
| 112 | ** to the character of z[] that occurs after the integer. |
| 113 | */ |
| @@ -330,20 +347,34 @@ | |
| 347 | db_end_transaction(0); |
| 348 | if( g.fAnyTrace ){ |
| 349 | fprintf(stderr, "/***** Backoffice On-deck %d *****/\n", getpid()); |
| 350 | } |
| 351 | if( x.tmCurrent >= tmNow ){ |
| 352 | if( backofficeSleep(1000*(x.tmCurrent - tmNow + 1)) ){ |
| 353 | /* The sleep was interrupted by a signal from another thread. */ |
| 354 | if( g.fAnyTrace ){ |
| 355 | fprintf(stderr, "/***** Backoffice Interrupt %d *****/\n", getpid()); |
| 356 | } |
| 357 | db_end_transaction(0); |
| 358 | break; |
| 359 | } |
| 360 | }else{ |
| 361 | if( lastWarning+warningDelay < tmNow ){ |
| 362 | fossil_warning( |
| 363 | "backoffice process %lld still running after %d seconds", |
| 364 | x.idCurrent, (int)(BKOFCE_LEASE_TIME + tmNow - x.tmCurrent)); |
| 365 | lastWarning = tmNow; |
| 366 | warningDelay *= 2; |
| 367 | } |
| 368 | if( backofficeSleep(1000) ){ |
| 369 | /* The sleep was interrupted by a signal from another thread. */ |
| 370 | if( g.fAnyTrace ){ |
| 371 | fprintf(stderr, "/***** Backoffice Interrupt %d *****/\n", getpid()); |
| 372 | } |
| 373 | db_end_transaction(0); |
| 374 | break; |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | #if defined(_WIN32) |
| 379 | backofficeWin32ThreadCleanup(); |
| 380 | #endif |
| 381 |