summaryrefslogtreecommitdiff
path: root/src/cuirass/utils.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-01-24 18:25:47 +0000
committerChristopher Baines <mail@cbaines.net>2020-01-25 22:32:09 +0000
commit0d23a6d374340f3f9a3b035f960abd39447e11c3 (patch)
treedb7f97dcb1f60ce43781c737a8f53afcbf9db933 /src/cuirass/utils.scm
parentfa412cdb5985ec4199f89510d8d8cde9b7664e2d (diff)
downloadcuirass-0d23a6d374340f3f9a3b035f960abd39447e11c3.tar
cuirass-0d23a6d374340f3f9a3b035f960abd39447e11c3.tar.gz
utils: Change critical section terminology to worker threads.
As far as I'm aware, it's necessary to use a separate thread for interacting with SQLite as one of the threads used for fibers will be blocked while the SQLite query is running. This doesn't mean all queries have to be executed one at a time though, providing the queries are executed outside the threads used by fibers, and a single connection isn't used in multiple threads. These changes start to move in this direction, first by just changing the terminology. * src/cuirass/base.scm (clear-build-queue, cancel-old-builds): Change with-db-critical-section to with-db-worker-thread. * src/cuirass/database.scm (with-db-critical-section): Rename syntax rule to with-db-worker-thread. (db-add-input, db-add-checkout, db-add-specification, db-remove-specification, db-get-inputs, db-get-specification, db-add-evaluation, db-set-evaluations-done, db-set-evaluation-done, db-add-derivation-output, db-add-build, db-update-build-status!, db-get-output, db-get-outputs, db-get-builds-by-search, db-get-builds, db-get-build derivation-or-id, db-add-event, db-get-events, db-delete-events-with-ids-<=-to, db-get-pending-derivations, db-get-checkouts, db-get-evaluations, db-get-evaluations-build-summary, db-get-evaluations-id-max, db-get-evaluation-summary, db-get-builds-query-min, db-get-builds-query-max, db-get-builds-min, db-get-builds-max, db-get-evaluation-specification): Change from using with-db-critical-section to with-db-worker-thread. (with-database): Change syntax rule to use make-worker-thread-channel, renaming from make-critical-section. * src/cuirass/utils.scm (%critical-section-args): Rename parameter to %worker-thread-args. (make-critical-section): Rename to make-worker-thread-channel, and adjust parameter and docstring. (call-with-critical-section): Rename to call-with-worker-thread and adjust parameter. (with-critical-section): Rename to with-worker-thread, and adjust to call call-with-worker-thread. * tests/database.scm (db-init): Use make-worker-thread-channel rather than make-critical-section. * tests/http.scm (db-init): Use make-worker-thread-channel rather than make-critical-section.
Diffstat (limited to 'src/cuirass/utils.scm')
-rw-r--r--src/cuirass/utils.scm38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/cuirass/utils.scm b/src/cuirass/utils.scm
index fe74b69..514899e 100644
--- a/src/cuirass/utils.scm
+++ b/src/cuirass/utils.scm
@@ -35,9 +35,9 @@
define-enumeration
unwind-protect
- make-critical-section
- call-with-critical-section
- with-critical-section
+ make-worker-thread-channel
+ call-with-worker-thread
+ with-worker-thread
%non-blocking
non-blocking
@@ -96,21 +96,17 @@ delimited continuations and fibers."
(conclusion)
(apply throw args)))))
-(define %critical-section-args
+(define %worker-thread-args
(make-parameter #f))
-(define (make-critical-section . args)
- "Return a channel used to implement a critical section. That channel can
-then be passed to 'join-critical-section', which will ensure sequential
-ordering. ARGS are the arguments of the critical section.
-
-Critical sections are implemented by passing the procedure to execute to a
-dedicated thread."
+(define (make-worker-thread-channel . args)
+ "Return a channel used to offload work to a dedicated thread. ARGS are the
+arguments of the worker thread procedure."
(parameterize (((@@ (fibers internal) current-fiber) #f))
(let ((channel (make-channel)))
(call-with-new-thread
(lambda ()
- (parameterize ((%critical-section-args args))
+ (parameterize ((%worker-thread-args args))
(let loop ()
(match (get-message channel)
(((? channel? reply) . (? procedure? proc))
@@ -118,21 +114,21 @@ dedicated thread."
(loop)))))
channel)))
-(define (call-with-critical-section channel proc)
- "Send PROC to the critical section through CHANNEL. Return the result of
-PROC. If already in the critical section, call PROC immediately."
- (let ((args (%critical-section-args)))
+(define (call-with-worker-thread channel proc)
+ "Send PROC to the worker thread through CHANNEL. Return the result of PROC.
+If already in the worker thread, call PROC immediately."
+ (let ((args (%worker-thread-args)))
(if args
(apply proc args)
(let ((reply (make-channel)))
(put-message channel (cons reply proc))
(get-message reply)))))
-(define-syntax-rule (with-critical-section channel (vars ...) exp ...)
- "Evaluate EXP... in the critical section corresponding to CHANNEL.
-VARS... are bound to the arguments of the critical section."
- (call-with-critical-section channel
- (lambda (vars ...) exp ...)))
+(define-syntax-rule (with-worker-thread channel (vars ...) exp ...)
+ "Evaluate EXP... in the worker thread corresponding to CHANNEL.
+VARS... are bound to the arguments of the worker thread."
+ (call-with-worker-thread channel
+ (lambda (vars ...) exp ...)))
(define (%non-blocking thunk)
(parameterize (((@@ (fibers internal) current-fiber) #f))