Launcher wait cleanup, don't use kqueue anymore

db4
Slava Pestov 2008-04-05 04:26:58 -05:00
parent b3a41fd796
commit 57268bcc7b
9 changed files with 26 additions and 52 deletions

View File

@ -3,7 +3,7 @@
USING: io io.backend io.timeouts system kernel namespaces USING: io io.backend io.timeouts system kernel namespaces
strings hashtables sequences assocs combinators vocabs.loader strings hashtables sequences assocs combinators vocabs.loader
init threads continuations math io.encodings io.streams.duplex init threads continuations math io.encodings io.streams.duplex
io.nonblocking accessors ; io.nonblocking accessors concurrency.flags ;
IN: io.launcher IN: io.launcher
TUPLE: process < identity-tuple TUPLE: process < identity-tuple
@ -56,14 +56,25 @@ SYMBOL: processes
[ H{ } clone processes set-global ] "io.launcher" add-init-hook [ 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 -- ) : process-started ( process handle -- )
>>handle >>handle
V{ } clone over processes get set-at V{ } clone swap processes get set-at
register-process ; wait-flag get-global raise-flag ;
M: process hashcode* process-handle hashcode* ; M: process hashcode* process-handle hashcode* ;

View File

@ -1,23 +1,8 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
IN: io.unix.bsd IN: io.unix.bsd
USING: io.backend io.unix.backend io.unix.kqueue io.unix.select USING: io.backend io.unix.backend io.unix.select
io.launcher io.unix.launcher namespaces kernel assocs namespaces system ;
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.
M: bsd init-io ( -- ) M: bsd init-io ( -- )
<select-mx> mx set-global <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 ;

View File

@ -1,3 +1,3 @@
USING: io.unix.bsd io.backend system ; USING: io.backend system ;
freebsd set-io-backend freebsd set-io-backend

View File

@ -108,7 +108,7 @@ M: unix (process-stream)
! Inefficient process wait polling, used on Linux and Solaris. ! Inefficient process wait polling, used on Linux and Solaris.
! On BSD and Mac OS X, we use kqueue() which scales better. ! 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 -1 0 <int> tuck WNOHANG waitpid
dup 0 <= [ dup 0 <= [
2drop t 2drop t
@ -119,7 +119,3 @@ M: unix (process-stream)
2drop f 2drop f
] if ] if
] if ; ] if ;
: start-wait-thread ( -- )
[ wait-for-processes [ 250 sleep ] when t ]
"Process reaper" spawn-server drop ;

View File

@ -123,5 +123,3 @@ M: linux init-io ( -- )
[ init-inotify ] bi ; [ init-inotify ] bi ;
linux set-io-backend linux set-io-backend
[ start-wait-thread ] "io.unix.linux" add-init-hook

View File

@ -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 continuations kernel core-foundation.fsevents sequences
namespaces arrays system ; namespaces arrays system ;
IN: io.unix.macosx IN: io.unix.macosx

View File

@ -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 openbsd set-io-backend

View File

@ -1,5 +1,5 @@
USING: io.unix.backend io.unix.files io.unix.sockets io.timeouts USING: io.unix.backend io.unix.files io.unix.sockets io.timeouts
io.unix.launcher io.unix.mmap io.backend combinators namespaces 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 "io.unix." os word-name append require

View File

@ -144,26 +144,10 @@ M: windows kill-process* ( handle -- )
over process-handle dispose-process over process-handle dispose-process
notify-exit ; notify-exit ;
: wait-for-processes ( processes -- ? ) M: windows wait-for-processes ( -- ? )
keys dup processes get keys dup
[ process-handle PROCESS_INFORMATION-hProcess ] map [ process-handle PROCESS_INFORMATION-hProcess ] map
dup length swap >c-void*-array 0 0 dup length swap >c-void*-array 0 0
WaitForMultipleObjects WaitForMultipleObjects
dup HEX: ffffffff = [ win32-error ] when dup HEX: ffffffff = [ win32-error ] when
dup WAIT_TIMEOUT = [ 2drop t ] [ swap nth process-exited f ] if ; 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