Add a counter to each process resource and use it to implement WITH-RESOURCES-ALIGNED by this partial order.

This commit is contained in:
mainzelm 2003-08-13 12:46:58 +00:00
parent 8eb6a07ec3
commit e589da1991
2 changed files with 14 additions and 4 deletions

View File

@ -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))

View File

@ -38,7 +38,7 @@
define-record-types
handle
locks
scsh-utilities)
sort)
(files resource))
(define-structure weak-tables weak-tables-interface