/lib/wills.arc

http://github.com/alimoeeny/arc · Unknown · 31 lines · 25 code · 6 blank · 0 comment · 0 complexity · 458443a260bb3139303e9b5306a000e4 MD5 · raw file

  1. ; Simplified interface to plt scheme's will executors. Ignores the fiddly bits
  2. ; about "will executors" and wills not being automatically executed, by using
  3. ; one global will executor and creating a thread to handle wills. Also avoids
  4. ; the problem that if multiple wills are registered for a given value, only one
  5. ; can be run per value per gc cycle, by adding another layer of indirection.
  6. (unless (and bound!will-executor* ($:will-executor? ,will-executor*))
  7. (= will-executor* ($.make-will-executor)))
  8. (unless (and bound!will-table* (isa will-table* 'table))
  9. (= will-table* ($.make-hash-table 'weak)))
  10. (unless (and bound!will-executor-thread*
  11. (isa will-executor-thread* 'thread)
  12. (~dead will-executor-thread*))
  13. (= will-executor-thread*
  14. (thread (while t ($.will-execute will-executor*)))))
  15. (def generic-will (val)
  16. (each f will-table*.val (f x)))
  17. (def will-register (val will)
  18. ; if val is not yet registered with a generic will, do so
  19. ($.hash-table-get will-table* val
  20. (fn () ($.will-register will-executor* val generic-will)))
  21. (push will will-table*.val)
  22. val)
  23. (mac will (val . body)
  24. (w/uniq ign
  25. `(will-register ,val (fn (,ign) ,@body))))