Adding call-with-locked-file utility.

This commit is contained in:
Alex Shinn 2014-03-21 11:29:41 +09:00
parent 061f7f57f5
commit 9f518e56c4
2 changed files with 10 additions and 0 deletions

View file

@ -106,6 +106,15 @@
thunk
(lambda () (change-directory pwd)))))
;;> Calls \var{proc} on a read/write opened file descriptor for
;;> \var{path}, locked with \scheme{file-lock}, and automatically
;;> removes the lock when \var{proc} returns the first time.
(define (call-with-locked-file path proc)
(let ((fd (open path open/read-write)))
(file-lock fd lock/exclusive)
(exception-protect (proc fd) (file-lock fd lock/unlock))))
;;> Returns the \scheme{status} object for the given \var{file},
;;> which should be a string indicating the path or a file
;;> descriptor.

View file

@ -31,6 +31,7 @@
open/create open/exclusive open/truncate
open/append open/non-block
file-lock file-truncate
call-with-locked-file
lock/shared lock/exclusive lock/non-blocking lock/unlock
is-a-tty?)
(import (chibi) (chibi string))