SummaryRefsLogTreeCommitDiffStats
path: root/src/mcron
diff options
context:
space:
mode:
authorMathieu Lirzin <mthl@gnu.org>2018-03-24 14:03:54 +0100
committerMathieu Lirzin <mthl@gnu.org>2018-03-24 14:03:54 +0100
commit526ce502e5b7bce1e3577696b2c41564f7248920 (patch)
tree9d00520d17f296c3a7544bb11281e1c5f6f3fb19 /src/mcron
parentd63db1ce4e8b30459bd3e67da619531f2741f9bf (diff)
downloadmcron-526ce502e5b7bce1e3577696b2c41564f7248920.tar.gz
mcron-526ce502e5b7bce1e3577696b2c41564f7248920.tar.bz2
mcron-526ce502e5b7bce1e3577696b2c41564f7248920.zip
base: Box 'number-children'
* src/mcron/base.scm (number-children): Box it using SRFI-111 to be explicit about the mutability of this object. (update-number-children!): New procedure. (run-job, child-cleanup): Use it. * tests/base.scm ("update-number-children!: 1+") ("number-children: init", "update-number-children!: 1-"): New tests.
Diffstat (limited to 'src/mcron')
-rw-r--r--src/mcron/base.scm21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/mcron/base.scm b/src/mcron/base.scm
index 2f1c060..17ddd5c 100644
--- a/src/mcron/base.scm
+++ b/src/mcron/base.scm
@@ -32,6 +32,7 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-2)
#:use-module (srfi srfi-9)
+ #:use-module (srfi srfi-111)
#:export (add-job
remove-user-jobs
display-schedule
@@ -157,10 +158,18 @@ unusable."
jobs))))
(display-schedule (- count 1) port #:schedule schedule)))
-;; For proper housekeeping, it is necessary to keep a record of the number of
-;; child processes we fork off to run the jobs.
+;;;
+;;; Running jobs
+;;;
+
+(define number-children
+ ;; For proper housekeeping, it is necessary to keep a record of the number
+ ;; of child processes we fork off to run the jobs.
+ (box 0))
-(define number-children 0)
+(define (update-number-children! proc)
+ ;; Apply PROC to the value stored in 'number-children'.
+ (set-box! number-children (proc (unbox number-children))))
(define (run-job job)
"Run JOB in a separate process. The process is run as JOB user with the
@@ -178,16 +187,16 @@ next value."
(λ ()
(primitive-exit 0)))
(begin ;parent
- (set! number-children (+ number-children 1))
+ (update-number-children! 1+)
(job:next-time-set! job ((job:next-time-function job)
(current-time))))))
(define (child-cleanup)
;; Give any zombie children a chance to die, and decrease the number known
;; to exist.
- (unless (or (<= number-children 0)
+ (unless (or (<= (unbox number-children) 0)
(= (car (waitpid WAIT_ANY WNOHANG)) 0))
- (set! number-children (- number-children 1))
+ (update-number-children! 1-)
(child-cleanup)))
(define* (run-job-loop #:optional fd-list #:key (schedule %global-schedule))