(defun acquire-lock (path) (let ((lock `@path.#lock#`) (start-time (time))) (while (< (- (time) start-time) 30) (catch (if (mkdir lock #o700) (return-from acquire-lock lock)) (file-error (e) (unless (= 17 (errno)) (throw 'file-error e)) (usleep 1000000)))) (error "acquire-lock: unable to acquire ~a" lock))) (defun release-lock (lock) (ignerr (remove-path lock))) (defmacro with-lock (path . body) (let ((lock (gensym))) ^(with-resources ((,lock (acquire-lock ,path) (release-lock ,lock))) ,*body)))