time.scm 1.3 KB

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