core-foundation.run-loop: cleanup timer-thread code.
parent
ceebc1d6c1
commit
be173c8a43
basis
core-foundation/run-loop
io/backend/unix/multiplexers/run-loop
|
@ -3,8 +3,8 @@
|
||||||
USING: accessors alien alien.c-types alien.syntax
|
USING: accessors alien alien.c-types alien.syntax
|
||||||
core-foundation core-foundation.file-descriptors
|
core-foundation core-foundation.file-descriptors
|
||||||
core-foundation.strings core-foundation.time
|
core-foundation.strings core-foundation.time
|
||||||
core-foundation.timers destructors kernel math sequences threads
|
core-foundation.timers destructors kernel math namespaces
|
||||||
;
|
sequences threads ;
|
||||||
FROM: calendar.unix => system-micros ;
|
FROM: calendar.unix => system-micros ;
|
||||||
IN: core-foundation.run-loop
|
IN: core-foundation.run-loop
|
||||||
|
|
||||||
|
@ -87,26 +87,13 @@ SYMBOL: run-loop
|
||||||
tri
|
tri
|
||||||
] with-destructors ;
|
] with-destructors ;
|
||||||
|
|
||||||
<PRIVATE
|
|
||||||
|
|
||||||
: (reset-timer) ( timer timestamp -- )
|
|
||||||
>CFAbsoluteTime CFRunLoopTimerSetNextFireDate ;
|
|
||||||
|
|
||||||
: reset-timer ( timer -- )
|
|
||||||
sleep-time
|
|
||||||
[ 1000 /f ] [ 1,000,000 ] if* system-micros +
|
|
||||||
(reset-timer) ;
|
|
||||||
|
|
||||||
PRIVATE>
|
|
||||||
|
|
||||||
: add-timer-to-run-loop ( timer -- )
|
: add-timer-to-run-loop ( timer -- )
|
||||||
[ reset-timer ]
|
|
||||||
[ get-run-loop timers>> push ]
|
[ get-run-loop timers>> push ]
|
||||||
[
|
[
|
||||||
CFRunLoopGetMain
|
CFRunLoopGetMain
|
||||||
swap CFRunLoopDefaultMode
|
swap CFRunLoopDefaultMode
|
||||||
CFRunLoopAddTimer
|
CFRunLoopAddTimer
|
||||||
] tri ;
|
] bi ;
|
||||||
|
|
||||||
: invalidate-run-loop-timers ( -- )
|
: invalidate-run-loop-timers ( -- )
|
||||||
get-run-loop [
|
get-run-loop [
|
||||||
|
@ -114,16 +101,20 @@ PRIVATE>
|
||||||
V{ } clone
|
V{ } clone
|
||||||
] change-timers drop ;
|
] change-timers drop ;
|
||||||
|
|
||||||
: reset-run-loop ( -- )
|
SYMBOL: thread-timer
|
||||||
get-run-loop
|
|
||||||
[ timers>> [ reset-timer ] each ]
|
|
||||||
[ fds>> [ enable-all-callbacks ] each ] bi ;
|
|
||||||
|
|
||||||
: timer-callback ( -- callback )
|
: reset-thread-timer ( timer -- )
|
||||||
[ drop reset-timer yield ] CFRunLoopTimerCallBack ;
|
sleep-time
|
||||||
|
[ 1000 /f ] [ 1,000,000 ] if* system-micros +
|
||||||
|
>CFAbsoluteTime CFRunLoopTimerSetNextFireDate ;
|
||||||
|
|
||||||
|
: thread-timer-callback ( -- callback )
|
||||||
|
[ drop reset-thread-timer yield ] CFRunLoopTimerCallBack ;
|
||||||
|
|
||||||
: init-thread-timer ( -- )
|
: init-thread-timer ( -- )
|
||||||
60 timer-callback <CFTimer> add-timer-to-run-loop ;
|
60 thread-timer-callback <CFTimer>
|
||||||
|
[ add-timer-to-run-loop ]
|
||||||
|
[ thread-timer set-global ] bi ;
|
||||||
|
|
||||||
: run-one-iteration ( nanos -- handled? )
|
: run-one-iteration ( nanos -- handled? )
|
||||||
CFRunLoopDefaultMode
|
CFRunLoopDefaultMode
|
||||||
|
|
|
@ -11,9 +11,10 @@ TUPLE: run-loop-mx kqueue-mx ;
|
||||||
|
|
||||||
: file-descriptor-callback ( -- callback )
|
: file-descriptor-callback ( -- callback )
|
||||||
[
|
[
|
||||||
3drop
|
2drop
|
||||||
0 mx get-global kqueue-mx>> wait-for-events
|
0 mx get-global kqueue-mx>> wait-for-events
|
||||||
reset-run-loop
|
enable-all-callbacks
|
||||||
|
thread-timer get-global reset-thread-timer
|
||||||
yield
|
yield
|
||||||
] CFFileDescriptorCallBack ;
|
] CFFileDescriptorCallBack ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue