PageRenderTime 14ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 7(unless (and bound!will-executor* ($:will-executor? ,will-executor*))
 8  (= will-executor* ($.make-will-executor)))
 9
10(unless (and bound!will-table* (isa will-table* 'table))
11  (= will-table* ($.make-hash-table 'weak)))
12
13(unless (and bound!will-executor-thread*
14             (isa will-executor-thread* 'thread)
15             (~dead will-executor-thread*))
16  (= will-executor-thread*
17     (thread (while t ($.will-execute will-executor*)))))
18
19(def generic-will (val)
20  (each f will-table*.val (f x)))
21
22(def will-register (val will)
23  ; if val is not yet registered with a generic will, do so
24  ($.hash-table-get will-table* val
25                    (fn () ($.will-register will-executor* val generic-will)))
26  (push will will-table*.val)
27  val)
28
29(mac will (val . body)
30  (w/uniq ign
31    `(will-register ,val (fn (,ign) ,@body))))