X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=loopy.scm;h=c78197a5c1c090f9132636b71ce5c69f3f9d4258;hb=a92d497f62a50199799da48b9653903060f6d9be;hp=ee1bc8121319943f49271b47b17e495ac92821de;hpb=3d1cf1e79073cdd9c0ecb09ee9e4f7dd29dc4149;p=8sync.git diff --git a/loopy.scm b/loopy.scm index ee1bc81..c78197a 100644 --- a/loopy.scm +++ b/loopy.scm @@ -174,12 +174,12 @@ Will produce (0 . 0) instead of a negative number, if needed." (define (time-minus time1 time2) (time-carry-correct (cons (- (car time1) (car time2)) - (- (car time2) (cdr time2))))) + (- (cdr time2) (cdr time2))))) (define (time-plus time1 time2) (time-carry-correct (cons (+ (car time1) (car time2)) - (+ (car time2) (cdr time2))))) + (+ (cdr time2) (cdr time2))))) (define-record-type @@ -356,11 +356,11 @@ Will produce (0 . 0) instead of a negative number, if needed." (cons 0 0)) (soonest-time ; ie, the agenda is non-empty (let* ((current-time (agenda-time agenda))) - (if (time<= (pk 'soonest-time soonest-time) (pk 'current-time current-time)) + (if (time<= soonest-time current-time) ;; Well there's something due so let's select ;; (this avoids a (possible?) race condition chance) (cons 0 0) - (pk 'time-minus (time-minus soonest-time current-time))))) + (time-minus soonest-time current-time)))) (else (cons #f #f))))) (define (do-select) @@ -432,17 +432,20 @@ Will produce (0 . 0) instead of a negative number, if needed." (agenda-run-once agenda)))) (if (and stop-condition (stop-condition agenda)) 'done - (let* ((new-time (get-time)) - (agenda - (handle-ports - ;; Adjust the agenda's time just in time - ;; We do this here rather than in agenda-run-once to make - ;; agenda-run-once's behavior fairly predictable - (set-field agenda (agenda-time) new-time)))) + (let* ((agenda + ;; We have to update the time after ports handled, too + ;; because it may have changed after a select + (set-field + (handle-ports + ;; Adjust the agenda's time just in time + ;; We do this here rather than in agenda-run-once to make + ;; agenda-run-once's behavior fairly predictable + (set-field agenda (agenda-time) (get-time))) + (agenda-time) (get-time)))) ;; Update the agenda's current queue based on ;; currently applicable time segments (add-segments-contents-to-queue! - (schedule-extract-until! (agenda-schedule agenda) new-time) + (schedule-extract-until! (agenda-schedule agenda) (agenda-time agenda)) (agenda-queue agenda)) (loop agenda))))))