X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fdeadline.lisp;h=d2577dc255735168f356e6156413fbf834a8a4fe;hb=70c40b1892a606163d0f60ac7b20093724e8e5e5;hp=43b4fc9e51ada0f778a494f89a15f93def014c7d;hpb=23e31980c78d174ef9cb775bf28f970890327fea;p=sbcl.git diff --git a/src/code/deadline.lisp b/src/code/deadline.lisp index 43b4fc9..d2577dc 100644 --- a/src/code/deadline.lisp +++ b/src/code/deadline.lisp @@ -43,18 +43,22 @@ not extended. Deadlines are per thread: children are unaffected by their parent's deadlines. Experimental." - (with-unique-names (deadline-seconds deadline) + (with-unique-names (tmp deadline-seconds deadline) ;; We're operating on a millisecond precision, so a single-float ;; is enough, and is an immediate on 64bit platforms. - `(let* ((,deadline-seconds (coerce ,seconds 'single-float)) + `(let* ((,tmp ,seconds) + (,deadline-seconds + (when ,tmp + (coerce ,tmp 'single-float))) (,deadline - (+ (seconds-to-internal-time ,deadline-seconds) - (get-internal-real-time)))) + (when ,deadline-seconds + (+ (seconds-to-internal-time ,deadline-seconds) + (get-internal-real-time))))) (multiple-value-bind (*deadline* *deadline-seconds*) (if ,override (values ,deadline ,deadline-seconds) (let ((old *deadline*)) - (if (and old (< old ,deadline)) + (if (and old (or (not ,deadline) (< old ,deadline))) (values old *deadline-seconds*) (values ,deadline ,deadline-seconds)))) ,@body)))) @@ -117,6 +121,21 @@ seconds.) Otherwise return NIL if the restart is not found." CONDITION, or return NIL if the restart is not found." (try-restart 'cancel-deadline condition)) +(declaim (inline relative-decoded-times)) +(defun relative-decoded-times (abs-sec abs-usec) + #!+sb-doc + "Returns relative decoded times: difference between SEC and USEC and +current real time." + (multiple-value-bind (now-sec now-usec) + (decode-internal-time (get-internal-real-time)) + (let ((rel-sec (- abs-sec now-sec))) + (cond ((> now-usec abs-usec) + (values (max 0 (1- rel-sec)) + (- (+ abs-usec 1000000) now-usec))) + (t + (values (max 0 rel-sec) + (- abs-usec now-usec))))))) + ;;; Returns TIMEOUT-SEC, TIMEOUT-USEC, DEADLINE-SEC, DEADLINE-USEC, SIGNALP ;;; ;;; Takes *DEADLINE* into account: if it occurs before given SECONDS, @@ -172,7 +191,7 @@ it will signal a timeout condition." (decode-internal-time final-timeout) (multiple-value-bind (stop-sec stop-usec) (decode-internal-time final-deadline) - (values to-sec to-usec stop-sec stop-usec signalp))) + (values (max 0 to-sec) (max 0 to-usec) stop-sec stop-usec signalp))) (values nil nil nil nil nil))))))) (!defun-from-collected-cold-init-forms !deadline-cold-init)