/lib/thread-cell.arc

http://github.com/alimoeeny/arc · Unknown · 26 lines · 21 code · 5 blank · 0 comment · 0 complexity · 0d7ade911e129073a01e2b23841c3225 MD5 · raw file

  1. (require "lib/util.arc")
  2. (require "lib/extend.arc")
  3. (def thread-cell ((o init-val))
  4. " Creates a thread-local storage cell with initial value `init-val'.
  5. Mutating a cell in one thread does not affect its value in others.
  6. See also [[thread-cell-get]] [[thread-cell-put]] "
  7. ($.make-thread-cell init-val))
  8. (def thread-cell-get (cell)
  9. " Retrieves `cell's value in the current thread.
  10. See also [[thread-cell-put]] [[thread-cell]] "
  11. ($.thread-cell-ref cell))
  12. (def thread-cell-put (cell val)
  13. " Changes `cell's value in the current thread (and only the current thread).
  14. See also [[thread-cell-get]] [[thread-cell]] "
  15. (($ thread-cell-set!) cell val)
  16. val)
  17. (defcall thread-cell (cell)
  18. (thread-cell-get cell))
  19. (extend sref thread-cell
  20. (fn (ob val . _) (isa ob 'thread-cell))
  21. (fn (ob val . _) (thread-cell-put ob val)))