Fossil SCM

When sleeping inside the backoffice work loop, permit the sleep to be interrupted on Win32, which stops processing.

mistachkin 2018-08-02 02:27 UTC win32Proc
Commit 9840313b1ce0b528bbedbfcd0cea921c2058a2b822bdef452e44acd4dee2151e
1 file changed +33 -2
+33 -2
--- src/backoffice.c
+++ src/backoffice.c
@@ -87,10 +87,27 @@
8787
*/
8888
void backoffice_no_delay(void){
8989
backofficeNoDelay = 1;
9090
}
9191
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
+}
92109
93110
/*
94111
** Parse a unsigned 64-bit integer from a string. Return a pointer
95112
** to the character of z[] that occurs after the integer.
96113
*/
@@ -330,20 +347,34 @@
330347
db_end_transaction(0);
331348
if( g.fAnyTrace ){
332349
fprintf(stderr, "/***** Backoffice On-deck %d *****/\n", getpid());
333350
}
334351
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
+ }
336360
}else{
337361
if( lastWarning+warningDelay < tmNow ){
338362
fossil_warning(
339363
"backoffice process %lld still running after %d seconds",
340364
x.idCurrent, (int)(BKOFCE_LEASE_TIME + tmNow - x.tmCurrent));
341365
lastWarning = tmNow;
342366
warningDelay *= 2;
343367
}
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
+ }
345376
}
346377
}
347378
#if defined(_WIN32)
348379
backofficeWin32ThreadCleanup();
349380
#endif
350381
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button