2008-12-11 23:48:19 -05:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-12-13 00:57:16 -05:00
|
|
|
USING: kernel arrays namespaces math accessors alien locals
|
2008-12-14 21:03:00 -05:00
|
|
|
destructors system threads io.backend.unix.multiplexers
|
|
|
|
io.backend.unix.multiplexers.kqueue core-foundation
|
2009-10-21 22:10:11 -04:00
|
|
|
core-foundation.run-loop core-foundation.file-descriptors ;
|
|
|
|
FROM: alien.c-types => void void* ;
|
2008-12-14 21:03:00 -05:00
|
|
|
IN: io.backend.unix.multiplexers.run-loop
|
2008-12-11 23:48:19 -05:00
|
|
|
|
2008-12-13 00:57:16 -05:00
|
|
|
TUPLE: run-loop-mx kqueue-mx ;
|
2008-12-11 23:48:19 -05:00
|
|
|
|
2008-12-13 00:57:16 -05:00
|
|
|
: file-descriptor-callback ( -- callback )
|
2009-10-21 22:10:11 -04:00
|
|
|
void { CFFileDescriptorRef CFOptionFlags void* }
|
2008-12-11 23:48:19 -05:00
|
|
|
"cdecl" [
|
|
|
|
3drop
|
|
|
|
0 mx get kqueue-mx>> wait-for-events
|
2008-12-13 00:57:16 -05:00
|
|
|
reset-run-loop
|
2008-12-11 23:48:19 -05:00
|
|
|
yield
|
2008-12-13 00:57:16 -05:00
|
|
|
] alien-callback ;
|
2008-12-11 23:48:19 -05:00
|
|
|
|
|
|
|
: <run-loop-mx> ( -- mx )
|
|
|
|
[
|
|
|
|
<kqueue-mx> |dispose
|
2008-12-13 00:57:16 -05:00
|
|
|
dup fd>> file-descriptor-callback add-fd-to-run-loop
|
|
|
|
run-loop-mx boa
|
2008-12-11 23:48:19 -05:00
|
|
|
] with-destructors ;
|
|
|
|
|
|
|
|
M: run-loop-mx add-input-callback kqueue-mx>> add-input-callback ;
|
|
|
|
M: run-loop-mx add-output-callback kqueue-mx>> add-output-callback ;
|
|
|
|
M: run-loop-mx remove-input-callbacks kqueue-mx>> remove-input-callbacks ;
|
|
|
|
M: run-loop-mx remove-output-callbacks kqueue-mx>> remove-output-callbacks ;
|
|
|
|
|
2008-12-13 00:57:16 -05:00
|
|
|
M: run-loop-mx wait-for-events ( us mx -- )
|
|
|
|
swap run-one-iteration [ 0 swap wait-for-events ] [ drop ] if ;
|