PageRenderTime 37ms CodeModel.GetById 35ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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