1 ! Copyright (C) 2008 Slava Pestov.
\r
2 ! See http://factorcode.org/license.txt for BSD license.
\r
3 USING: deques threads kernel arrays sequences alarms fry ;
\r
4 IN: concurrency.conditions
\r
6 : notify-1 ( deque -- )
\r
7 dup deque-empty? [ drop ] [ pop-back resume-now ] if ;
\r
9 : notify-all ( deque -- )
\r
10 [ resume-now ] slurp-deque ;
\r
12 : queue-timeout ( queue timeout -- alarm )
\r
13 #! Add an alarm which removes the current thread from the
\r
14 #! queue, and resumes it, passing it a value of t.
\r
16 [ self swap push-front* ] keep '[
\r
18 [ delete-node ] [ drop node-value ] 2bi
\r
23 : wait ( queue timeout status -- )
\r
25 [ queue-timeout [ drop ] ] dip suspend
\r
26 [ "Timeout" throw ] [ cancel-alarm ] if
\r
28 [ drop '[ _ push-front ] ] dip suspend drop
\r