Slava Pestov 2005-05-04 00:09:04 +00:00
parent af639e3e67
commit 8bca326561
5 changed files with 13 additions and 33 deletions

View File

@ -120,8 +120,8 @@ t [
"/library/ui/editors.factor" "/library/ui/editors.factor"
"/library/ui/menus.factor" "/library/ui/menus.factor"
"/library/ui/presentations.factor" "/library/ui/presentations.factor"
"/library/ui/tiles.factor"
"/library/ui/panes.factor" "/library/ui/panes.factor"
"/library/ui/tiles.factor"
"/library/ui/dialogs.factor" "/library/ui/dialogs.factor"
"/library/ui/inspector.factor" "/library/ui/inspector.factor"
"/library/ui/init-world.factor" "/library/ui/init-world.factor"

View File

@ -1,18 +0,0 @@
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: threads USING: errors io-internals kernel lists ;
: in-thread ( quot -- )
#! Execute a quotation in a co-operative thread. The
#! quotation begins executing immediately, and execution
#! after the 'in-thread' call in the original thread
#! resumes when the quotation yields, either due to blocking
#! I/O or an explicit call to 'yield'.
[
schedule-thread
! Clear stacks since we never go up from this point
[ ] set-catchstack
{ } set-callstack
try
stop
] callcc0 drop ;

View File

@ -2,8 +2,7 @@
! Copyright (C) 2005 Mackenzie Straight. ! Copyright (C) 2005 Mackenzie Straight.
! See http://factor.sf.net/license.txt for BSD license. ! See http://factor.sf.net/license.txt for BSD license.
IN: threads IN: threads
USING: errors io-internals kernel kernel-internals lists USING: errors kernel kernel-internals lists namespaces ;
namespaces ;
! Core of the multitasker. Used by io-internals.factor and ! Core of the multitasker. Used by io-internals.factor and
! in-thread.factor. ! in-thread.factor.

View File

@ -1,8 +1,9 @@
! Copyright (C) 2005 Slava Pestov. ! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license. ! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets IN: gadgets
USING: alien errors generic kernel lists math memory namespaces USING: alien errors generic kernel lists math
prettyprint sdl sequences stdio strings threads ; memory namespaces prettyprint sdl sequences stdio strings
threads ;
! The world gadget is the top level gadget that all (visible) ! The world gadget is the top level gadget that all (visible)
! gadgets are contained in. The current world is stored in the ! gadgets are contained in. The current world is stored in the
@ -43,10 +44,12 @@ DEFER: handle-event
drop f drop f
] ifte ; ] ifte ;
: next-event ( -- event ) <event> dup SDL_PollEvent ;
: run-world ( -- ) : run-world ( -- )
#! Keep polling for events until there are no more events in #! Keep polling for events until there are no more events in
#! the queue; then block for the next event. #! the queue; then block for the next event.
<event> dup SDL_PollEvent [ next-event [
[ handle-event ] in-thread drop run-world [ handle-event ] in-thread drop run-world
] [ ] [
drop world get world-step [ yield run-world ] when drop world get world-step [ yield run-world ] when

View File

@ -355,6 +355,9 @@ M: writer stream-close ( stream -- )
: <fd-stream> ( infd outfd flush? -- stream ) : <fd-stream> ( infd outfd flush? -- stream )
>r >r <reader> r> <writer> r> <duplex-stream> ; >r >r <reader> r> <writer> r> <duplex-stream> ;
: idle-io-task ( -- )
[ schedule-thread 10 io-multiplex ] callcc0 idle-io-task ;
USE: stdio USE: stdio
: init-io ( -- ) : init-io ( -- )
@ -363,12 +366,5 @@ USE: stdio
global [ global [
<namespace> io-tasks set <namespace> io-tasks set
0 1 t <fd-stream> stdio set 0 1 t <fd-stream> stdio set
] bind ; ] bind
[ idle-io-task ] in-thread ;
IN: threads
: stop ( -- )
#! If there is a quotation in the run queue, call it,
#! otherwise wait for I/O.
pending-io? [ 10 io-multiplex ] when
next-thread [ call ] [ -1 io-multiplex stop ] ifte* ;