]> gitweb.factorcode.org Git - factor.git/blob - basis/io/thread/thread.factor
8c069f440c2e6ab016ee414c0cbf731105f86d53
[factor.git] / basis / io / thread / thread.factor
1 ! Copyright (C) 2008, 2011 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: continuations init io.backend kernel namespaces threads ;
4 IN: io.thread
5
6 ! The Cocoa and Gtk UI backend stops the I/O thread and takes
7 ! over completely.
8 SYMBOL: io-thread-running?
9
10 TUPLE: io-thread < thread ;
11
12 : <io-thread> ( -- thread )
13     [
14         [ io-thread-running? get-global ]
15         [ sleep-time io-multiplex yield ]
16         while
17     ]
18     "I/O wait"
19     io-thread new-thread ;
20
21 M: io-thread error-in-thread die drop rethrow ;
22
23 : start-io-thread ( -- )
24     t io-thread-running? set-global
25     <io-thread> (spawn) ;
26
27 : stop-io-thread ( -- )
28     f io-thread-running? set-global ;
29
30 [ start-io-thread ] "io.thread" add-startup-hook