[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/01: Fix 'monitor' macro.
From: |
Andy Wingo |
Subject: |
[Guile-commits] 01/01: Fix 'monitor' macro. |
Date: |
Mon, 27 Jun 2016 07:32:40 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit d5d7e303486012b3173c8df0417c69b01df9baf3
Author: Taylan Ulrich Bayırlı/Kammer <address@hidden>
Date: Sat Jun 25 16:43:36 2016 +0200
Fix 'monitor' macro.
* module/ice-9/threads.scm (monitor-mutex-table)
(monitor-mutex-table-mutex, monitor-mutex-with-id): New variables.
(monitor): Fix it.
---
module/ice-9/threads.scm | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/module/ice-9/threads.scm b/module/ice-9/threads.scm
index 9f9e1bf..14da113 100644
--- a/module/ice-9/threads.scm
+++ b/module/ice-9/threads.scm
@@ -85,9 +85,24 @@
(lambda () (begin e0 e1 ...))
(lambda () (unlock-mutex x)))))
-(define-syntax-rule (monitor first rest ...)
- (with-mutex (make-mutex)
- first rest ...))
+(define monitor-mutex-table (make-hash-table))
+
+(define monitor-mutex-table-mutex (make-mutex))
+
+(define (monitor-mutex-with-id id)
+ (with-mutex monitor-mutex-table-mutex
+ (or (hashq-ref monitor-mutex-table id)
+ (let ((mutex (make-mutex)))
+ (hashq-set! monitor-mutex-table id mutex)
+ mutex))))
+
+(define-syntax monitor
+ (lambda (stx)
+ (syntax-case stx ()
+ ((_ body body* ...)
+ (let ((id (datum->syntax #'body (gensym))))
+ #`(with-mutex (monitor-mutex-with-id '#,id)
+ body body* ...))))))
(define (par-mapper mapper cons)
(lambda (proc . lists)