USING: arrays hashtables heaps kernel kernel.private math
namespaces sequences vectors continuations continuations.private
dlists assocs system combinators init boxes accessors
-math.order deques strings quotations ;
+math.order deques strings quotations fry ;
IN: threads
SYMBOL: initial-thread
<PRIVATE
: schedule-sleep ( thread dt -- )
- >r check-registered dup r> sleep-queue heap-push*
+ [ check-registered dup ] dip sleep-queue heap-push*
>>sleep-entry drop ;
: expire-sleep? ( heap -- ? )
: suspend ( quot state -- obj )
[
- >r
- >r self swap call
- r> self (>>state)
- r> self continuation>> >box
+ [ [ self swap call ] dip self (>>state) ] dip
+ self continuation>> >box
next
] callcc1 2nip ; inline
GENERIC: sleep-until ( time/f -- )
M: integer sleep-until
- [ schedule-sleep ] curry "sleep" suspend drop ;
+ '[ _ schedule-sleep ] "sleep" suspend drop ;
M: f sleep-until
drop [ drop ] "interrupt" suspend drop ;
<thread> [ (spawn) ] keep ;
: spawn-server ( quot name -- thread )
- >r [ loop ] curry r> spawn ;
+ [ '[ _ loop ] ] dip spawn ;
: in-thread ( quot -- )
- >r datastack r>
- [ >r set-datastack r> call ] 2curry
+ [ datastack ] dip
+ '[ _ set-datastack _ call ]
"Thread" spawn drop ;
GENERIC: error-in-thread ( error thread -- )