From 997813680db107a75dae889f73bc3da5ce00806f Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Thu, 11 Aug 2011 09:28:01 -0500 Subject: [PATCH] change the #:get-lock-file argument of call-with-file-lock/timeout to #:lock-file --- collects/racket/file.rkt | 12 +++------ .../scribblings/reference/filesystem.scrbl | 25 +++++++++---------- .../unit-tests/typecheck-tests.rkt | 2 +- collects/typed-scheme/base-env/base-env.rkt | 2 +- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/collects/racket/file.rkt b/collects/racket/file.rkt index bc6380e70e..942d25c98b 100644 --- a/collects/racket/file.rkt +++ b/collects/racket/file.rkt @@ -175,7 +175,7 @@ [else 'exists])) (define (call-with-file-lock/timeout fn kind thunk failure-thunk - #:get-lock-file [get-lock-file (λ () (make-lock-file-name fn))] + #:lock-file [lock-file #f] #:delay [delay 0.01] #:max-delay [max-delay 0.2]) @@ -187,18 +187,14 @@ (raise-type-error 'call-with-file-lock/timeout "procedure (arity 0)" thunk)) (unless (and (procedure? thunk) (= (procedure-arity thunk) 0)) (raise-type-error 'call-with-file-lock/timeout "procedure (arity 0)" failure-thunk)) - (unless (or (path-string? get-lock-file) - (and (procedure? get-lock-file) (= (procedure-arity get-lock-file) 0))) - (raise-type-error 'call-with-file-lock/timeout "procedure (arity 0) returning a path-string? or path-string?" get-lock-file)) + (unless (path-string? lock-file) + (raise-type-error 'call-with-file-lock/timeout "path-string? or #f" lock-file)) (unless (and (real? delay) (not (negative? delay))) (raise-type-error 'call-with-file-lock/timeout "non-negative real" delay)) (unless (and (real? max-delay) (not (negative? max-delay))) (raise-type-error 'call-with-file-lock/timeout "non-negative real" max-delay)) - (define real-lock-file - (if (procedure? get-lock-file) (get-lock-file) get-lock-file)) - (unless (path-string? real-lock-file) - (raise-type-error 'call-with-file-lock/timeout "procedure (arity 0) returning a path-string? or path-string?" get-lock-file)) + (define real-lock-file (or lock-file (make-lock-file-name fn))) (let loop ([delay delay]) (call-with-file-lock kind diff --git a/collects/scribblings/reference/filesystem.scrbl b/collects/scribblings/reference/filesystem.scrbl index 8a872e2ea8..d12b1c99e5 100644 --- a/collects/scribblings/reference/filesystem.scrbl +++ b/collects/scribblings/reference/filesystem.scrbl @@ -1056,30 +1056,29 @@ with the given @racket[lock-there], instead.} [kind (or/c 'shared 'exclusive)] [thunk (-> any)] [failure-thunk (-> any)] - [#:get-lock-file get-lock-file (or/c path-string? (-> path-string?)) (make-lock-filename filename)] + [#:lock-file lock-file (or/c #f path-string?) #f] [#:delay delay (and/c real? (not/c negative?)) 0.01] [#:max-delay max-delay (and/c real? (not/c negative?)) 0.2]) any]{ -Obtains a lock for the filename returned from @racket[(get-lock-file)] and then -calls @racket[thunk]. When @racket[thunk] returns, +Obtains a lock for the filename @racket[lock-file] and then +calls @racket[thunk]. The @racket[filename] argument specifies +a file path prefix that is only used +to generate the lock filename when @racket[lock-file] is @racket[#f]. +Specifically, when @racket[lock-file] is @racket[#f], then +@racket[call-with-file-lock/timeout] uses @racket[make-lock-file-name] to build the +lock filename. + +When @racket[thunk] returns, @racket[call-with-file-lock] releases the lock, returning the result of @racket[thunk]. The @racket[call-with-file-lock/timeout] function will retry -after @racket[#:delay] seconds and continue retrying with exponential backoff -until delay reaches @racket[#:max-delay]. If +after @racket[delay] seconds and continue retrying with exponential backoff +until delay reaches @racket[max-delay]. If @racket[call-with-file-lock/timeout] fails to obtain the lock, @racket[failure-thunk] is called in tail position. The @racket[kind] argument specifies whether the lock is @racket['shared] or @racket['exclusive] in the sense of @racket[port-try-file-lock?]. -The @racket[filename] argument specifies a file path prefix that is only used -to generate the lock filename, when @racket[#:get-lock-file] is not present. -The @racket[call-with-file-lock/timeout] function uses a separate lock file to -prevent race conditions on @racket[filename], when @racket[filename] has not yet -been created. On the Windows platfom, the @racket[call-with-file-lock/timeout] -function uses a separate lock file (@racket["_LOCKfilename"]), because a lock -on @racket[filename] would interfere with replacing @racket[filename] via -@racket[rename-file-or-directory]. } @examples[ diff --git a/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt b/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt index d49ec88f12..73c93a54d7 100644 --- a/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt +++ b/collects/tests/typed-scheme/unit-tests/typecheck-tests.rkt @@ -1162,7 +1162,7 @@ (t:-> -Pathlike ManyUniv)) (tc-e (call-with-file-lock/timeout #f 'exclusive (lambda () 'res) (lambda () 'err) - #:get-lock-file (lambda () "lock") + #:lock-file "lock" #:delay .01 #:max-delay .2) (one-of/c 'res 'err)) diff --git a/collects/typed-scheme/base-env/base-env.rkt b/collects/typed-scheme/base-env/base-env.rkt index c31ff602ac..d75da74712 100644 --- a/collects/typed-scheme/base-env/base-env.rkt +++ b/collects/typed-scheme/base-env/base-env.rkt @@ -835,7 +835,7 @@ (one-of/c 'shared 'exclusive) (-> a) (-> a) - #:get-lock-file (-> -Pathlike) #f + #:lock-file (-opt -Pathlike) #f #:delay -Real #f #:max-delay -Real #f a))]