From e589da1991dfd4f385695277cd25eb56dafb822b Mon Sep 17 00:00:00 2001 From: mainzelm Date: Wed, 13 Aug 2003 12:46:58 +0000 Subject: [PATCH] Add a counter to each process resource and use it to implement WITH-RESOURCES-ALIGNED by this partial order. --- scsh/resource.scm | 16 +++++++++++++--- scsh/scsh-package.scm | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/scsh/resource.scm b/scsh/resource.scm index 2b9e2d2..14feda0 100644 --- a/scsh/resource.scm +++ b/scsh/resource.scm @@ -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)) diff --git a/scsh/scsh-package.scm b/scsh/scsh-package.scm index 99d657d..0335d2b 100644 --- a/scsh/scsh-package.scm +++ b/scsh/scsh-package.scm @@ -38,7 +38,7 @@ define-record-types handle locks - scsh-utilities) + sort) (files resource)) (define-structure weak-tables weak-tables-interface