(time time-segment-time)
(queue time-segment-queue))
+;; @@: This seems to be the same as srfi-18's seconds->time procedure?
+;; Maybe double check and switch to that? (Thanks amz3!)
+
+(define (time-from-float-or-fraction time)
+ "Produce a (sec . usec) pair from TIME, a float or fraction"
+ (let* ((mixed-whole (floor time))
+ (mixed-rest (- time mixed-whole)) ; float or fraction component
+ (sec mixed-whole)
+ (usec (floor (* 1000000 mixed-rest))))
+ (cons (inexact->exact sec) (inexact->exact usec))))
+
(define (time-segment-right-format time)
"Ensure TIME is in the right format.
(((? integer? s) . (? integer? u)) time)
;; time was just an integer (just the second)
((? integer? _) (cons time 0))
+ ((or (? rational? _) (? inexact? _))
+ (time-from-float-or-fraction time))
(_ (throw 'invalid-time "Invalid time" time))))
(define* (make-time-segment time #:optional (queue (make-q)))
(sec time-delta-sec)
(usec time-delta-usec))
-(define* (make-time-delta sec #:optional (usec 0))
+(define* (make-time-delta time)
"Make a <time-delta> of SEC seconds and USEC microseconds.
This is used primarily so the agenda can recognize RUN-REQUEST objects
-which are meant "
- (make-time-delta-intern sec usec))
+which are meant to delay computation"
+ (match (time-segment-right-format time)
+ ((sec . usec)
+ (make-time-delta-intern sec usec))))
(define tdelta make-time-delta)
"Subtract TIME2 from TIME1"
(time-carry-correct
(cons (- (car time1) (car time2))
- (- (cdr time2) (cdr time2)))))
+ (- (cdr time1) (cdr time2)))))
(define (time-plus time1 time2)
"Add TIME1 and TIME2"
(time-carry-correct
(cons (+ (car time1) (car time2))
- (+ (cdr time2) (cdr time2)))))
+ (+ (cdr time1) (cdr time2)))))
(define-record-type <schedule>
;; TODO: support usecond wait time too
(match (get-wait-time)
((sec . usec)
- (select (hash-keys (agenda-read-port-map agenda))
- (hash-keys (agenda-write-port-map agenda))
- (hash-keys (agenda-except-port-map agenda))
- sec usec))))
+ (catch 'system-error
+ (lambda ()
+ (select (hash-keys (agenda-read-port-map agenda))
+ (hash-keys (agenda-write-port-map agenda))
+ (hash-keys (agenda-except-port-map agenda))
+ sec usec))
+ (lambda (key . rest-args)
+ (match rest-args
+ ((_ _ _ (EINTR))
+ '(() () ()))
+ (_ (error "Unhandled error in select!" key rest-args))))))))
(define (get-procs-to-run)
(define (ports->procs ports port-map)
(lambda (initial-procs)