Add a counter to each process resource and use it to implement WITH-RESOURCES-ALIGNED by this partial order.
This commit is contained in:
parent
8eb6a07ec3
commit
e589da1991
|
@ -1,12 +1,22 @@
|
|||
(define *resource-counter* 0)
|
||||
|
||||
(define-record-type resource :resource
|
||||
(make-resource align! lock)
|
||||
(really-make-resource count align! lock)
|
||||
resource?
|
||||
(count resource-count)
|
||||
(align! resource-align!)
|
||||
(lock resource-lock))
|
||||
|
||||
(define (make-resource align! lock)
|
||||
(set! *resource-counter* (+ *resource-counter* 1))
|
||||
(really-make-resource *resource-counter* align! lock))
|
||||
|
||||
(define (with-resources-aligned resources thunk)
|
||||
(let ((locks (map resource-lock resources)))
|
||||
(apply obtain-all-or-none locks)
|
||||
(let ((locks (map resource-lock
|
||||
(sort-list resources (lambda (r1 r2)
|
||||
(< (resource-count r1)
|
||||
(resource-count r2)))))))
|
||||
(for-each obtain-lock locks)
|
||||
(for-each
|
||||
(lambda (align!) (align!))
|
||||
(map resource-align! resources))
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
define-record-types
|
||||
handle
|
||||
locks
|
||||
scsh-utilities)
|
||||
sort)
|
||||
(files resource))
|
||||
|
||||
(define-structure weak-tables weak-tables-interface
|
||||
|
|
Loading…
Reference in New Issue