From 70d85c0c642be0b5aaca567857ba416a1f4cee8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Lassieur?= Date: Fri, 27 Jul 2018 08:28:12 +0200 Subject: utils: Prevent critical section clients to talk to each other. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- src/cuirass/utils.scm | 9 +++++---- 1 file 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. -- cgit v1.2.3