safe-write (sbcl/linux)
Автор: LinkFly - 2011-09-04T15:37:48.000000+04:00
(defparameter *safe-write-sleep* 0.01)
(defun safe-write (pathname string &aux stream)
(setf stream (open pathname :direction :output :if-does-not-exist :create :if-exists :append))
(unwind-protect
(loop
until (block try-lock
(handler-bind ((error (lambda (condition)
(if (= sb-posix:eagain
(sb-posix:syscall-errno condition))
(return-from try-lock)
(error condition)))))
(sb-posix:lockf stream sb-posix:f-tlock 0)
(princ string stream)
(close stream)))
do (sleep *safe-write-sleep*))
(close stream)))
(defun safe-write (pathname string &aux stream)
(setf stream (open pathname :direction :output :if-does-not-exist :create :if-exists :append))
(unwind-protect
(loop
until (block try-lock
(handler-bind ((error (lambda (condition)
(if (= sb-posix:eagain
(sb-posix:syscall-errno condition))
(return-from try-lock)
(error condition)))))
(sb-posix:lockf stream sb-posix:f-tlock 0)
(princ string stream)
(close stream)))
do (sleep *safe-write-sleep*))
(close stream)))