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* }
|
2010-03-31 22:20:35 -04:00
|
|
|
cdecl [
|
2012-08-01 19:59:33 -04:00
|
|
|
2drop
|
2012-08-01 19:20:31 -04:00
|
|
|
0 mx get-global kqueue-mx>> wait-for-events
|
2012-08-01 19:59:33 -04:00
|
|
|
enable-all-callbacks
|
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 ;
|
|
|
|
|
2009-11-19 15:18:27 -05:00
|
|
|
M: run-loop-mx wait-for-events ( nanos mx -- )
|
2008-12-13 00:57:16 -05:00
|
|
|
swap run-one-iteration [ 0 swap wait-for-events ] [ drop ] if ;
|