From: Tobias C. R. <tc...@fr...> - 2010-04-19 18:31:50
|
"Tobias C. Rittweiler" <tc...@fr...> writes: > In the later case, we'd have to change SLEEP internally to use absolute > rather than relative times. At the moment SLEEP uses `nanosleep'; I read > that for the absolute time behaviour one would have to use > `clock_nanosleep'. Both are due to POSIX.1-2001 according to my > manpages. `clock_nanosleep' is a library function in librt. I hence decided to roll it all in Lisp: (declaim (type (or null single-float) sb-impl::*deadline-seconds*)) (defun sleep* (seconds) (let ((seconds (coerce seconds 'single-float))) (declare (single-float seconds)) (declare (optimize speed)) (prog ((deadline-seconds sb-impl::*deadline-seconds*) (stop-time (+ (sb-impl::seconds-to-internal-time seconds) (get-internal-real-time)))) :retry (cond ((not deadline-seconds) (sleep seconds)) ((> deadline-seconds seconds) (sleep seconds)) (t (sleep deadline-seconds) (sb-sys:signal-deadline) (setf seconds (/ (float (- stop-time (get-internal-real-time)) 1f0) (float internal-time-units-per-second 1f0))) (when (plusp seconds) (setq deadline-seconds sb-impl::*deadline-seconds*) (go :retry))))))) The (SETF SECONDS ...) complains about ; note: doing float to pointer coercion (cost 13) to SECONDS Can anyone enlighten me on why it needs to box that float? -T. |