diff options
author | Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com> | 2016-06-25 16:43:36 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2016-06-27 09:32:30 +0200 |
commit | d5d7e303486012b3173c8df0417c69b01df9baf3 (patch) | |
tree | 7d3318aa399e23c4f439767473ff6b08d6e0d3db | |
parent | 3e719e0a35cf383d4f7fa3823494f01e244135e9 (diff) | |
download | guile-d5d7e303486012b3173c8df0417c69b01df9baf3.tar.gz |
Fix 'monitor' macro.
* module/ice-9/threads.scm (monitor-mutex-table)
(monitor-mutex-table-mutex, monitor-mutex-with-id): New variables.
(monitor): Fix it.
-rw-r--r-- | module/ice-9/threads.scm | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/module/ice-9/threads.scm b/module/ice-9/threads.scm index 9f9e1bf8e..14da11339 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) |