- "Signal a DEADLINE-TIMEOUT condition. Implementors of blocking functions
-are responsible for calling this when a deadline is reached."
- (signal-timeout 'deadline-timeout :seconds *deadline-seconds*))
+ "Signal a DEADLINE-TIMEOUT condition, and associate a DEFER-DEADLINE
+restart with it. Implementors of blocking functions are responsible
+for calling this when a deadline is reached."
+ ;; Make sure we don't signal the same deadline twice. LET is not good
+ ;; enough: we might catch the same deadline again while unwinding.
+ (when *deadline*
+ (setf *deadline* nil))
+ (with-interrupts
+ (restart-case
+ (error 'deadline-timeout :seconds *deadline-seconds*)
+ (defer-deadline (&optional (seconds *deadline-seconds*))
+ :report "Defer the deadline for SECONDS more."
+ (let* ((new-deadline-seconds (coerce seconds 'single-float))
+ (new-deadline (+ (seconds-to-internal-time new-deadline-seconds)
+ (get-internal-real-time))))
+ (setf *deadline* new-deadline
+ *deadline-seconds* new-deadline-seconds)))))
+ nil)
+
+(defun defer-deadline (seconds &optional condition)
+ "Find the DEFER-DEADLINE restart associated with CONDITION, and
+calls it with SECONDS as argument (deferring the deadline by that many
+seconds.) Continues from the indicated restart, or returns NIL if the
+restart is not found."
+ (try-restart 'defer-deadline condition seconds))