Fossil SCM
Improvements to comments. No code changes.
Commit
1b54dd79bfc98862cb5745f458c0f7536efafd0aed9746a40b2c478cb00d7a6c
Parent
af7d67c6a25f5af…
1 file changed
+31
-12
+31
-12
| --- src/backoffice.c | ||
| +++ src/backoffice.c | ||
| @@ -35,10 +35,29 @@ | ||
| 35 | 35 | ** Backoffice processes should die off after doing whatever work they need |
| 36 | 36 | ** to do. In this way, we avoid having lots of idle processes in the |
| 37 | 37 | ** process table, doing nothing on rarely accessed repositories, and |
| 38 | 38 | ** if the Fossil binary is updated on a system, the backoffice processes |
| 39 | 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. | |
| 40 | 59 | */ |
| 41 | 60 | #include "config.h" |
| 42 | 61 | #include "backoffice.h" |
| 43 | 62 | #include <time.h> |
| 44 | 63 | #if defined(_WIN32) |
| @@ -52,26 +71,26 @@ | ||
| 52 | 71 | /* |
| 53 | 72 | ** The BKOFCE_LEASE_TIME is the amount of time for which a single backoffice |
| 54 | 73 | ** processing run is valid. Each backoffice run monopolizes the lease for |
| 55 | 74 | ** at least this amount of time. Hopefully all backoffice processing is |
| 56 | 75 | ** 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 | |
| 58 | 77 | ** must be spaced out by at least this much time. |
| 59 | 78 | */ |
| 60 | -#define BKOFCE_LEASE_TIME 60 /* Length of lease validity */ | |
| 79 | +#define BKOFCE_LEASE_TIME 60 /* Length of lease validity in seconds */ | |
| 61 | 80 | |
| 62 | 81 | #if LOCAL_INTERFACE |
| 63 | 82 | /* |
| 64 | 83 | ** An instance of the following object describes a lease on the backoffice |
| 65 | 84 | ** 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. | |
| 67 | 86 | */ |
| 68 | 87 | 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 */ | |
| 73 | 92 | }; |
| 74 | 93 | #endif |
| 75 | 94 | |
| 76 | 95 | /*************************************************************************** |
| 77 | 96 | ** Local state variables |
| @@ -150,11 +169,11 @@ | ||
| 150 | 169 | pLease->idCurrent, pLease->tmCurrent, |
| 151 | 170 | pLease->idNext, pLease->tmNext); |
| 152 | 171 | } |
| 153 | 172 | |
| 154 | 173 | /* |
| 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 | |
| 156 | 175 | ** we cannot prove the the process is dead, return true. |
| 157 | 176 | */ |
| 158 | 177 | static int backofficeProcessExists(sqlite3_uint64 pid){ |
| 159 | 178 | #if defined(_WIN32) |
| 160 | 179 | return 1; |
| @@ -162,11 +181,11 @@ | ||
| 162 | 181 | return pid>0 && kill((pid_t)pid, 0)==0; |
| 163 | 182 | #endif |
| 164 | 183 | } |
| 165 | 184 | |
| 166 | 185 | /* |
| 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 | |
| 168 | 187 | ** we cannot prove the the process is still running, return true. |
| 169 | 188 | */ |
| 170 | 189 | static int backofficeProcessDone(sqlite3_uint64 pid){ |
| 171 | 190 | #if defined(_WIN32) |
| 172 | 191 | return 1; |
| @@ -226,11 +245,11 @@ | ||
| 226 | 245 | backofficeProcessDone(x)); |
| 227 | 246 | } |
| 228 | 247 | } |
| 229 | 248 | |
| 230 | 249 | /* |
| 231 | -** If backoffice processing is needed set the backofficeDb value to the | |
| 250 | +** If backoffice processing is needed set the backofficeDb variable to the | |
| 232 | 251 | ** name of the database file. If no backoffice processing is needed, |
| 233 | 252 | ** this routine makes no changes to state. |
| 234 | 253 | */ |
| 235 | 254 | void backoffice_check_if_needed(void){ |
| 236 | 255 | Lease x; |
| @@ -268,19 +287,19 @@ | ||
| 268 | 287 | } |
| 269 | 288 | } |
| 270 | 289 | |
| 271 | 290 | /* This is the main loop for backoffice processing. |
| 272 | 291 | ** |
| 273 | -** If others process is already working as the current backoffice and | |
| 292 | +** If another process is already working as the current backoffice and | |
| 274 | 293 | ** the on-deck backoffice, then this routine returns very quickly |
| 275 | 294 | ** without doing any work. |
| 276 | 295 | ** |
| 277 | 296 | ** If no backoffice processes are running at all, this routine becomes |
| 278 | 297 | ** the main backoffice. |
| 279 | 298 | ** |
| 280 | 299 | ** 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. | |
| 282 | 301 | */ |
| 283 | 302 | static void backoffice_thread(void){ |
| 284 | 303 | Lease x; |
| 285 | 304 | sqlite3_uint64 tmNow; |
| 286 | 305 | sqlite3_uint64 idSelf; |
| 287 | 306 |
| --- 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 |