Use make-preserved-thread-fluid for the process resources.

Fixed indentation.
This commit is contained in:
mainzelm 2001-12-05 08:34:37 +00:00
parent 8bba3a13e1
commit 3620d702f0
1 changed files with 86 additions and 85 deletions

View File

@ -142,7 +142,8 @@
;;; (thread-set-resource ('X -> unspec))
(define-syntax make-process-resource
(syntax-rules ()
(syntax-rules
()
((make-process-resource
initialize-resource
thread-read-resource thread-set-resource! thread-change-resource
@ -155,25 +156,25 @@
(define (initialize-resource)
(set! *resource-cache* (process-read-resource))
(set! $resource ;;; TODO The old thread-fluid will remain
(make-thread-fluid
(make-preserved-thread-fluid
(process-read-resource)))
(set! resource-lock (make-lock)))
(define (cache-value)
*resource-cache*)
;;; Actually do the syscall and update the cache
;;; assumes the resource lock obtained
;; Actually do the syscall and update the cache
;; assumes the resource lock obtained
(define (change-and-cache dir)
(process-set-resource dir)
(set! *resource-cache* (process-read-resource)))
;;; Dynamic-wind is not the right thing to take care of the lock;
;;; it would release the lock on every context switch.
;;; With-lock releases the lock on a condition, using call/cc will
;;; skrew things up
;; Dynamic-wind is not the right thing to take care of the lock;
;; it would release the lock on every context switch.
;; With-lock releases the lock on a condition, using call/cc will
;; skrew things up
;;; The thread-specific resource: A thread fluid
;; The thread-specific resource: A thread fluid
(define $resource 'empty-resource-value)
@ -207,17 +208,17 @@
(change-and-cache dir)
(thread-set-resource! (cache-value)))))
;;; For thunks that don't raise exceptions or throw to continuations,
;;; this is overkill & probably a little heavyweight for frequent use.
;;; But it is general.
;;;
;;; A less-general, more lightweight hack could be done just for
;;; syscalls. We could probably dump the DYNAMIC-WINDs and build the
;;; rest of the pattern into one of the syscall-defining macros, or
;;; something.
;;; Olin adds the following: the efficient way to do things is not
;;; with a dynamic wind or a lock. Just turn off interrupts, sync the
;;; resource, do the syscall, turn them back on.
;; For thunks that don't raise exceptions or throw to continuations,
;; this is overkill & probably a little heavyweight for frequent use.
;; But it is general.
;;
;; A less-general, more lightweight hack could be done just for
;; syscalls. We could probably dump the DYNAMIC-WINDs and build the
;; rest of the pattern into one of the syscall-defining macros, or
;; something.
;; Olin adds the following: the efficient way to do things is not
;; with a dynamic wind or a lock. Just turn off interrupts, sync the
;; resource, do the syscall, turn them back on.
(define (with-resource-aligned* thunk)
(dynamic-wind (lambda ()
@ -226,9 +227,9 @@
thunk
values))
;;; example syscall
;;; (define (exported-delete-file fname)
;;;; (with-cwd-aligned (really-delete-file fname)))
;; example syscall
;; (define (exported-delete-file fname)
;; (with-cwd-aligned (really-delete-file fname)))
(define resource-reinitializer