time.scm 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ;; Rendezvous that happen at a specified time
  2. (define (at-real-time-rv time)
  3. (make-time-rv (lambda () time)))
  4. (define (after-time-rv time-difference)
  5. (make-time-rv (lambda () (+ (real-time) time-difference))))
  6. (define (make-time-rv compute-time)
  7. (make-base
  8. (lambda ()
  9. (let ((time (compute-time)))
  10. (if (> (real-time) time)
  11. (make-enabled 0
  12. (lambda (queue)
  13. (unspecific)))
  14. (make-blocked
  15. (lambda (trans-id cleanup-proc wrap-proc)
  16. (register-dozer!
  17. time
  18. ;; alive?
  19. (lambda ()
  20. (not (trans-id-cancelled? trans-id)))
  21. ;; wakeup
  22. ;; It doesn't matter if this is repeated due to a
  23. ;; failed commit or due to a race. A stillborn commit
  24. ;; will result in a no-op, and trans-ids can deal with
  25. ;; a premature set.
  26. (lambda ()
  27. (with-new-proposal (lose)
  28. (let ((thread-queue (make-queue)))
  29. (cleanup-proc thread-queue)
  30. (trans-id-set-value! trans-id
  31. (cons (unspecific)
  32. wrap-proc))
  33. (enqueue! thread-queue
  34. (trans-id-thread-cell trans-id))
  35. ;; we can't lose because we're running in the
  36. ;; root scheduler
  37. (maybe-commit-and-make-ready thread-queue))))))))))))