Launcher wait cleanup, don't use kqueue anymore
parent
b3a41fd796
commit
57268bcc7b
|
@ -3,7 +3,7 @@
|
|||
USING: io io.backend io.timeouts system kernel namespaces
|
||||
strings hashtables sequences assocs combinators vocabs.loader
|
||||
init threads continuations math io.encodings io.streams.duplex
|
||||
io.nonblocking accessors ;
|
||||
io.nonblocking accessors concurrency.flags ;
|
||||
IN: io.launcher
|
||||
|
||||
TUPLE: process < identity-tuple
|
||||
|
@ -56,14 +56,25 @@ SYMBOL: processes
|
|||
|
||||
[ H{ } clone processes set-global ] "io.launcher" add-init-hook
|
||||
|
||||
HOOK: register-process io-backend ( process -- )
|
||||
HOOK: wait-for-processes io-backend ( -- ? )
|
||||
|
||||
M: object register-process drop ;
|
||||
SYMBOL: wait-flag
|
||||
|
||||
: wait-loop ( -- )
|
||||
processes get assoc-empty?
|
||||
[ wait-flag get-global lower-flag ]
|
||||
[ wait-for-processes [ 100 sleep ] when ] if ;
|
||||
|
||||
: start-wait-thread ( -- )
|
||||
<flag> wait-flag set-global
|
||||
[ wait-loop t ] "Process wait" spawn-server drop ;
|
||||
|
||||
[ start-wait-thread ] "io.launcher" add-init-hook
|
||||
|
||||
: process-started ( process handle -- )
|
||||
>>handle
|
||||
V{ } clone over processes get set-at
|
||||
register-process ;
|
||||
V{ } clone swap processes get set-at
|
||||
wait-flag get-global raise-flag ;
|
||||
|
||||
M: process hashcode* process-handle hashcode* ;
|
||||
|
||||
|
|
|
@ -1,23 +1,8 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
IN: io.unix.bsd
|
||||
USING: io.backend io.unix.backend io.unix.kqueue io.unix.select
|
||||
io.launcher io.unix.launcher namespaces kernel assocs
|
||||
threads continuations system ;
|
||||
|
||||
! On Mac OS X, we use select() for the top-level
|
||||
! multiplexer, and we hang a kqueue off of it for process exit
|
||||
! notification.
|
||||
|
||||
! kqueue is buggy with files and ptys so we can't use it as the
|
||||
! main multiplexer.
|
||||
USING: io.backend io.unix.backend io.unix.select
|
||||
namespaces system ;
|
||||
|
||||
M: bsd init-io ( -- )
|
||||
<select-mx> mx set-global
|
||||
<kqueue-mx> kqueue-mx set-global
|
||||
kqueue-mx get-global <mx-port> <mx-task> dup io-task-fd
|
||||
2dup mx get-global mx-reads set-at
|
||||
mx get-global mx-writes set-at ;
|
||||
|
||||
M: bsd register-process ( process -- )
|
||||
process-handle kqueue-mx get-global add-pid-task ;
|
||||
<select-mx> mx set-global ;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
USING: io.unix.bsd io.backend system ;
|
||||
USING: io.backend system ;
|
||||
|
||||
freebsd set-io-backend
|
||||
|
|
|
@ -108,7 +108,7 @@ M: unix (process-stream)
|
|||
|
||||
! Inefficient process wait polling, used on Linux and Solaris.
|
||||
! On BSD and Mac OS X, we use kqueue() which scales better.
|
||||
: wait-for-processes ( -- ? )
|
||||
M: unix wait-for-processes ( -- ? )
|
||||
-1 0 <int> tuck WNOHANG waitpid
|
||||
dup 0 <= [
|
||||
2drop t
|
||||
|
@ -119,7 +119,3 @@ M: unix (process-stream)
|
|||
2drop f
|
||||
] if
|
||||
] if ;
|
||||
|
||||
: start-wait-thread ( -- )
|
||||
[ wait-for-processes [ 250 sleep ] when t ]
|
||||
"Process reaper" spawn-server drop ;
|
||||
|
|
|
@ -123,5 +123,3 @@ M: linux init-io ( -- )
|
|||
[ init-inotify ] bi ;
|
||||
|
||||
linux set-io-backend
|
||||
|
||||
[ start-wait-thread ] "io.unix.linux" add-init-hook
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
USING: io.unix.bsd io.backend io.monitors io.monitors.private
|
||||
USING: io.backend io.monitors io.monitors.private
|
||||
continuations kernel core-foundation.fsevents sequences
|
||||
namespaces arrays system ;
|
||||
IN: io.unix.macosx
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
USING: io.unix.bsd io.backend core-foundation.fsevents system ;
|
||||
USING: io.backend core-foundation.fsevents system ;
|
||||
|
||||
openbsd set-io-backend
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
USING: io.unix.backend io.unix.files io.unix.sockets io.timeouts
|
||||
io.unix.launcher io.unix.mmap io.backend combinators namespaces
|
||||
system vocabs.loader sequences words ;
|
||||
system vocabs.loader sequences words init ;
|
||||
|
||||
"io.unix." os word-name append require
|
||||
|
|
|
@ -144,26 +144,10 @@ M: windows kill-process* ( handle -- )
|
|||
over process-handle dispose-process
|
||||
notify-exit ;
|
||||
|
||||
: wait-for-processes ( processes -- ? )
|
||||
keys dup
|
||||
M: windows wait-for-processes ( -- ? )
|
||||
processes get keys dup
|
||||
[ process-handle PROCESS_INFORMATION-hProcess ] map
|
||||
dup length swap >c-void*-array 0 0
|
||||
WaitForMultipleObjects
|
||||
dup HEX: ffffffff = [ win32-error ] when
|
||||
dup WAIT_TIMEOUT = [ 2drop t ] [ swap nth process-exited f ] if ;
|
||||
|
||||
SYMBOL: wait-flag
|
||||
|
||||
: wait-loop ( -- )
|
||||
processes get dup assoc-empty?
|
||||
[ drop wait-flag get-global lower-flag ]
|
||||
[ wait-for-processes [ 100 sleep ] when ] if ;
|
||||
|
||||
: start-wait-thread ( -- )
|
||||
<flag> wait-flag set-global
|
||||
[ wait-loop t ] "Process wait" spawn-server drop ;
|
||||
|
||||
M: windows register-process
|
||||
drop wait-flag get-global raise-flag ;
|
||||
|
||||
[ start-wait-thread ] "io.windows.launcher" add-init-hook
|
||||
|
|
Loading…
Reference in New Issue