summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Lassieur <clement@lassieur.org>2018-07-27 08:28:12 +0200
committerClément Lassieur <clement@lassieur.org>2018-07-27 21:20:52 +0200
commit70d85c0c642be0b5aaca567857ba416a1f4cee8c (patch)
tree4a47b0ca47a15073362ab11d3c08a25c1421e67f
parent6f8dc0b6169fa43a340377e3a95a0352cfc2148a (diff)
downloadcuirass-70d85c0c642be0b5aaca567857ba416a1f4cee8c.tar
cuirass-70d85c0c642be0b5aaca567857ba416a1f4cee8c.tar.gz
utils: Prevent critical section clients to talk to each other.
* src/cuirass/utils.scm (make-critical-section): Put the modified message to the REPLY channel that was part of the initial message. (call-with-critical-section): Create a REPLY channel, add it to the sent message, get the modified message from that channel. Co-authored-by: Ludovic Courtès <ludo@gnu.org>
-rw-r--r--src/cuirass/utils.scm9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/cuirass/utils.scm b/src/cuirass/utils.scm
index 6629bc1..9e9ac36 100644
--- a/src/cuirass/utils.scm
+++ b/src/cuirass/utils.scm
@@ -106,16 +106,17 @@ dedicated fiber."
(lambda ()
(let loop ()
(match (get-message channel)
- ((? procedure? proc)
- (put-message channel (apply proc args))))
+ (((? channel? reply) . (? procedure? proc))
+ (put-message reply (apply proc args))))
(loop))))
channel))
(define (call-with-critical-section channel proc)
"Call PROC in the critical section corresponding to CHANNEL. Return the
result of PROC."
- (put-message channel proc)
- (get-message channel))
+ (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.