Fossil SCM

Improvements to comments. No code changes.

drh 2018-08-07 18:28 fork-backoffice
Commit 1b54dd79bfc98862cb5745f458c0f7536efafd0aed9746a40b2c478cb00d7a6c
1 file changed +31 -12
+31 -12
--- src/backoffice.c
+++ src/backoffice.c
@@ -35,10 +35,29 @@
3535
** Backoffice processes should die off after doing whatever work they need
3636
** to do. In this way, we avoid having lots of idle processes in the
3737
** process table, doing nothing on rarely accessed repositories, and
3838
** if the Fossil binary is updated on a system, the backoffice processes
3939
** will restart using the new binary automatically.
40
+**
41
+** At any point in time there should be at most two backoffice processes.
42
+** There is a main process that is doing the actually work, and there is
43
+** a second stand-by process that is waiting for the main process to finish
44
+** and that will become the main process after a delay.
45
+**
46
+** After any successful web page reply, the backoffice_check_if_needed()
47
+** routine is called. That routine checks to see if both one or both of
48
+** the backoffice processes are already running. That routine remembers the
49
+** status in a global variable.
50
+**
51
+** Later, after the repository database is closed, the
52
+** backoffice_run_if_needed() routine is called. If the prior call
53
+** to backoffice_check_if_needed() indicated that backoffice processing
54
+** might be required, the run_if_needed() attempts to kick off a backoffice
55
+** process.
56
+**
57
+** All work performance by the backoffice is in the backoffice_work()
58
+** routine.
4059
*/
4160
#include "config.h"
4261
#include "backoffice.h"
4362
#include <time.h>
4463
#if defined(_WIN32)
@@ -52,26 +71,26 @@
5271
/*
5372
** The BKOFCE_LEASE_TIME is the amount of time for which a single backoffice
5473
** processing run is valid. Each backoffice run monopolizes the lease for
5574
** at least this amount of time. Hopefully all backoffice processing is
5675
** finished much faster than this - usually in less than a second. But
57
-** regardless of how fast each invocations run, successive backoffice runs
76
+** regardless of how long each invocation lasts, successive backoffice runs
5877
** must be spaced out by at least this much time.
5978
*/
60
-#define BKOFCE_LEASE_TIME 60 /* Length of lease validity */
79
+#define BKOFCE_LEASE_TIME 60 /* Length of lease validity in seconds */
6180
6281
#if LOCAL_INTERFACE
6382
/*
6483
** An instance of the following object describes a lease on the backoffice
6584
** processing timeslot. This lease is used to help ensure that no more than
66
-** one processing is running backoffice at a time.
85
+** one process is running backoffice at a time.
6786
*/
6887
struct Lease {
69
- sqlite3_uint64 idCurrent; /* ID for the current lease holder */
70
- sqlite3_uint64 tmCurrent; /* Expiration of the current lease */
71
- sqlite3_uint64 idNext; /* ID for the next lease holder on queue */
72
- sqlite3_uint64 tmNext; /* Expiration of the next lease */
88
+ sqlite3_uint64 idCurrent; /* process ID for the current lease holder */
89
+ sqlite3_uint64 tmCurrent; /* Expiration of the current lease */
90
+ sqlite3_uint64 idNext; /* process ID for the next lease holder on queue */
91
+ sqlite3_uint64 tmNext; /* Expiration of the next lease */
7392
};
7493
#endif
7594
7695
/***************************************************************************
7796
** Local state variables
@@ -150,11 +169,11 @@
150169
pLease->idCurrent, pLease->tmCurrent,
151170
pLease->idNext, pLease->tmNext);
152171
}
153172
154173
/*
155
-** Check to see if the process identified by selfId is alive. If
174
+** Check to see if the process identified by pid is alive. If
156175
** we cannot prove the the process is dead, return true.
157176
*/
158177
static int backofficeProcessExists(sqlite3_uint64 pid){
159178
#if defined(_WIN32)
160179
return 1;
@@ -162,11 +181,11 @@
162181
return pid>0 && kill((pid_t)pid, 0)==0;
163182
#endif
164183
}
165184
166185
/*
167
-** Check to see if the process identified by selfId has finished. If
186
+** Check to see if the process identified by pid has finished. If
168187
** we cannot prove the the process is still running, return true.
169188
*/
170189
static int backofficeProcessDone(sqlite3_uint64 pid){
171190
#if defined(_WIN32)
172191
return 1;
@@ -226,11 +245,11 @@
226245
backofficeProcessDone(x));
227246
}
228247
}
229248
230249
/*
231
-** If backoffice processing is needed set the backofficeDb value to the
250
+** If backoffice processing is needed set the backofficeDb variable to the
232251
** name of the database file. If no backoffice processing is needed,
233252
** this routine makes no changes to state.
234253
*/
235254
void backoffice_check_if_needed(void){
236255
Lease x;
@@ -268,19 +287,19 @@
268287
}
269288
}
270289
271290
/* This is the main loop for backoffice processing.
272291
**
273
-** If others process is already working as the current backoffice and
292
+** If another process is already working as the current backoffice and
274293
** the on-deck backoffice, then this routine returns very quickly
275294
** without doing any work.
276295
**
277296
** If no backoffice processes are running at all, this routine becomes
278297
** the main backoffice.
279298
**
280299
** If a primary backoffice is running, but a on-deck backoffice is
281
-** needed, this routine becomes that backoffice.
300
+** needed, this routine becomes that on-desk backoffice.
282301
*/
283302
static void backoffice_thread(void){
284303
Lease x;
285304
sqlite3_uint64 tmNow;
286305
sqlite3_uint64 idSelf;
287306
--- src/backoffice.c
+++ src/backoffice.c
@@ -35,10 +35,29 @@
35 ** Backoffice processes should die off after doing whatever work they need
36 ** to do. In this way, we avoid having lots of idle processes in the
37 ** process table, doing nothing on rarely accessed repositories, and
38 ** if the Fossil binary is updated on a system, the backoffice processes
39 ** will restart using the new binary automatically.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40 */
41 #include "config.h"
42 #include "backoffice.h"
43 #include <time.h>
44 #if defined(_WIN32)
@@ -52,26 +71,26 @@
52 /*
53 ** The BKOFCE_LEASE_TIME is the amount of time for which a single backoffice
54 ** processing run is valid. Each backoffice run monopolizes the lease for
55 ** at least this amount of time. Hopefully all backoffice processing is
56 ** finished much faster than this - usually in less than a second. But
57 ** regardless of how fast each invocations run, successive backoffice runs
58 ** must be spaced out by at least this much time.
59 */
60 #define BKOFCE_LEASE_TIME 60 /* Length of lease validity */
61
62 #if LOCAL_INTERFACE
63 /*
64 ** An instance of the following object describes a lease on the backoffice
65 ** processing timeslot. This lease is used to help ensure that no more than
66 ** one processing is running backoffice at a time.
67 */
68 struct Lease {
69 sqlite3_uint64 idCurrent; /* ID for the current lease holder */
70 sqlite3_uint64 tmCurrent; /* Expiration of the current lease */
71 sqlite3_uint64 idNext; /* ID for the next lease holder on queue */
72 sqlite3_uint64 tmNext; /* Expiration of the next lease */
73 };
74 #endif
75
76 /***************************************************************************
77 ** Local state variables
@@ -150,11 +169,11 @@
150 pLease->idCurrent, pLease->tmCurrent,
151 pLease->idNext, pLease->tmNext);
152 }
153
154 /*
155 ** Check to see if the process identified by selfId is alive. If
156 ** we cannot prove the the process is dead, return true.
157 */
158 static int backofficeProcessExists(sqlite3_uint64 pid){
159 #if defined(_WIN32)
160 return 1;
@@ -162,11 +181,11 @@
162 return pid>0 && kill((pid_t)pid, 0)==0;
163 #endif
164 }
165
166 /*
167 ** Check to see if the process identified by selfId has finished. If
168 ** we cannot prove the the process is still running, return true.
169 */
170 static int backofficeProcessDone(sqlite3_uint64 pid){
171 #if defined(_WIN32)
172 return 1;
@@ -226,11 +245,11 @@
226 backofficeProcessDone(x));
227 }
228 }
229
230 /*
231 ** If backoffice processing is needed set the backofficeDb value to the
232 ** name of the database file. If no backoffice processing is needed,
233 ** this routine makes no changes to state.
234 */
235 void backoffice_check_if_needed(void){
236 Lease x;
@@ -268,19 +287,19 @@
268 }
269 }
270
271 /* This is the main loop for backoffice processing.
272 **
273 ** If others process is already working as the current backoffice and
274 ** the on-deck backoffice, then this routine returns very quickly
275 ** without doing any work.
276 **
277 ** If no backoffice processes are running at all, this routine becomes
278 ** the main backoffice.
279 **
280 ** If a primary backoffice is running, but a on-deck backoffice is
281 ** needed, this routine becomes that backoffice.
282 */
283 static void backoffice_thread(void){
284 Lease x;
285 sqlite3_uint64 tmNow;
286 sqlite3_uint64 idSelf;
287
--- src/backoffice.c
+++ src/backoffice.c
@@ -35,10 +35,29 @@
35 ** Backoffice processes should die off after doing whatever work they need
36 ** to do. In this way, we avoid having lots of idle processes in the
37 ** process table, doing nothing on rarely accessed repositories, and
38 ** if the Fossil binary is updated on a system, the backoffice processes
39 ** will restart using the new binary automatically.
40 **
41 ** At any point in time there should be at most two backoffice processes.
42 ** There is a main process that is doing the actually work, and there is
43 ** a second stand-by process that is waiting for the main process to finish
44 ** and that will become the main process after a delay.
45 **
46 ** After any successful web page reply, the backoffice_check_if_needed()
47 ** routine is called. That routine checks to see if both one or both of
48 ** the backoffice processes are already running. That routine remembers the
49 ** status in a global variable.
50 **
51 ** Later, after the repository database is closed, the
52 ** backoffice_run_if_needed() routine is called. If the prior call
53 ** to backoffice_check_if_needed() indicated that backoffice processing
54 ** might be required, the run_if_needed() attempts to kick off a backoffice
55 ** process.
56 **
57 ** All work performance by the backoffice is in the backoffice_work()
58 ** routine.
59 */
60 #include "config.h"
61 #include "backoffice.h"
62 #include <time.h>
63 #if defined(_WIN32)
@@ -52,26 +71,26 @@
71 /*
72 ** The BKOFCE_LEASE_TIME is the amount of time for which a single backoffice
73 ** processing run is valid. Each backoffice run monopolizes the lease for
74 ** at least this amount of time. Hopefully all backoffice processing is
75 ** finished much faster than this - usually in less than a second. But
76 ** regardless of how long each invocation lasts, successive backoffice runs
77 ** must be spaced out by at least this much time.
78 */
79 #define BKOFCE_LEASE_TIME 60 /* Length of lease validity in seconds */
80
81 #if LOCAL_INTERFACE
82 /*
83 ** An instance of the following object describes a lease on the backoffice
84 ** processing timeslot. This lease is used to help ensure that no more than
85 ** one process is running backoffice at a time.
86 */
87 struct Lease {
88 sqlite3_uint64 idCurrent; /* process ID for the current lease holder */
89 sqlite3_uint64 tmCurrent; /* Expiration of the current lease */
90 sqlite3_uint64 idNext; /* process ID for the next lease holder on queue */
91 sqlite3_uint64 tmNext; /* Expiration of the next lease */
92 };
93 #endif
94
95 /***************************************************************************
96 ** Local state variables
@@ -150,11 +169,11 @@
169 pLease->idCurrent, pLease->tmCurrent,
170 pLease->idNext, pLease->tmNext);
171 }
172
173 /*
174 ** Check to see if the process identified by pid is alive. If
175 ** we cannot prove the the process is dead, return true.
176 */
177 static int backofficeProcessExists(sqlite3_uint64 pid){
178 #if defined(_WIN32)
179 return 1;
@@ -162,11 +181,11 @@
181 return pid>0 && kill((pid_t)pid, 0)==0;
182 #endif
183 }
184
185 /*
186 ** Check to see if the process identified by pid has finished. If
187 ** we cannot prove the the process is still running, return true.
188 */
189 static int backofficeProcessDone(sqlite3_uint64 pid){
190 #if defined(_WIN32)
191 return 1;
@@ -226,11 +245,11 @@
245 backofficeProcessDone(x));
246 }
247 }
248
249 /*
250 ** If backoffice processing is needed set the backofficeDb variable to the
251 ** name of the database file. If no backoffice processing is needed,
252 ** this routine makes no changes to state.
253 */
254 void backoffice_check_if_needed(void){
255 Lease x;
@@ -268,19 +287,19 @@
287 }
288 }
289
290 /* This is the main loop for backoffice processing.
291 **
292 ** If another process is already working as the current backoffice and
293 ** the on-deck backoffice, then this routine returns very quickly
294 ** without doing any work.
295 **
296 ** If no backoffice processes are running at all, this routine becomes
297 ** the main backoffice.
298 **
299 ** If a primary backoffice is running, but a on-deck backoffice is
300 ** needed, this routine becomes that on-desk backoffice.
301 */
302 static void backoffice_thread(void){
303 Lease x;
304 sqlite3_uint64 tmNow;
305 sqlite3_uint64 idSelf;
306

Keyboard Shortcuts

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