]> gitweb.factorcode.org Git - factor.git/commitdiff
core-foundation.run-loop: cleanup timer-thread code.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 17 Jan 2015 22:16:24 +0000 (14:16 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 17 Jan 2015 22:16:24 +0000 (14:16 -0800)
basis/core-foundation/run-loop/run-loop.factor
basis/io/backend/unix/multiplexers/run-loop/run-loop.factor

index c4931418655dee8004032e18241d69be58e8a83c..dcd815fdd4c9038b3c8a545fa1017df5d0566fe3 100644 (file)
@@ -3,8 +3,8 @@
 USING: accessors alien alien.c-types alien.syntax
 core-foundation core-foundation.file-descriptors
 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 ;
 IN: core-foundation.run-loop
 
@@ -87,26 +87,13 @@ SYMBOL: run-loop
         tri
     ] 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 -- )
-    [ reset-timer ]
     [ get-run-loop timers>> push ]
     [
         CFRunLoopGetMain
         swap CFRunLoopDefaultMode
         CFRunLoopAddTimer
-    ] tri ;
+    ] bi ;
 
 : invalidate-run-loop-timers ( -- )
     get-run-loop [
@@ -114,16 +101,20 @@ PRIVATE>
         V{ } clone
     ] change-timers drop ;
 
-: reset-run-loop ( -- )
-    get-run-loop
-    [ timers>> [ reset-timer ] each ]
-    [ fds>> [ enable-all-callbacks ] each ] bi ;
+SYMBOL: thread-timer
+
+: reset-thread-timer ( timer -- )
+    sleep-time
+    [ 1000 /f ] [ 1,000,000 ] if* system-micros +
+    >CFAbsoluteTime CFRunLoopTimerSetNextFireDate ;
 
-: timer-callback ( -- callback )
-    [ drop reset-timer yield ] CFRunLoopTimerCallBack ;
+: thread-timer-callback ( -- callback )
+    [ drop reset-thread-timer yield ] CFRunLoopTimerCallBack ;
 
 : 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? )
     CFRunLoopDefaultMode
index 51405b203c3eba8d561d785cb8073a9655ba3729..007d3c67625decdac56f2d776b7d831ec5214934 100644 (file)
@@ -11,9 +11,10 @@ TUPLE: run-loop-mx kqueue-mx ;
 
 : file-descriptor-callback ( -- callback )
     [
-        3drop
+        2drop
         0 mx get-global kqueue-mx>> wait-for-events
-        reset-run-loop
+        enable-all-callbacks
+        thread-timer get-global reset-thread-timer
         yield
     ] CFFileDescriptorCallBack ;