]> gitweb.factorcode.org Git - factor.git/commitdiff
core-foundation.run-loop: do less work, speeds up yield by 50%.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 1 Aug 2012 17:57:58 +0000 (10:57 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 1 Aug 2012 17:57:58 +0000 (10:57 -0700)
basis/core-foundation/run-loop/run-loop.factor
basis/io/backend/unix/multiplexers/run-loop/run-loop.factor

index ee7e88502155f8b4800ac1df2494f69ce73a7f3d..b0c4d640c1a0cf99609924f7041c12db7ef8c043 100644 (file)
@@ -80,18 +80,32 @@ TUPLE: run-loop fds sources timers ;
 : add-fd-to-run-loop ( fd callback -- )
     [
         <CFFileDescriptor> |CFRelease
+        [ enable-all-callbacks ]
         [ run-loop fds>> push ]
         [ create-fd-source |CFRelease add-source-to-run-loop ]
-        bi
+        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 ]
     [ run-loop timers>> push ]
     [
         CFRunLoopGetMain
         swap CFRunLoopDefaultMode
         CFRunLoopAddTimer
-    ] bi ;
+    ] tri ;
 
 : invalidate-run-loop-timers ( -- )
     run-loop [
@@ -99,18 +113,6 @@ TUPLE: run-loop fds sources timers ;
         V{ } clone
     ] change-timers drop ;
 
-<PRIVATE
-
-: (reset-timer) ( timer timestamp -- )
-    >CFAbsoluteTime CFRunLoopTimerSetNextFireDate ;
-
-: reset-timer ( timer -- )
-    sleep-time
-    [ 1000 /f ] [ 1,000,000 ] if* system-micros +
-    (reset-timer) ;
-
-PRIVATE>
-
 : reset-run-loop ( -- )
     run-loop
     [ timers>> [ reset-timer ] each ]
@@ -118,13 +120,12 @@ PRIVATE>
 
 : timer-callback ( -- callback )
     void { CFRunLoopTimerRef void* } cdecl
-    [ 2drop reset-run-loop yield ] alien-callback ;
+    [ drop reset-timer yield ] alien-callback ;
 
 : init-thread-timer ( -- )
     60 timer-callback <CFTimer> add-timer-to-run-loop ;
 
 : run-one-iteration ( nanos -- handled? )
-    reset-run-loop
     CFRunLoopDefaultMode
     swap [ nanoseconds ] [ 5 minutes ] if* >CFTimeInterval
     t CFRunLoopRunInMode kCFRunLoopRunHandledSource = ;
index ea31292c065027af73c3573a77599fa877c669c0..66a4e14550e1572ff36b56d888326af3c8a1b12d 100644 (file)
@@ -12,9 +12,8 @@ TUPLE: run-loop-mx kqueue-mx ;
 : file-descriptor-callback ( -- callback )
     void { CFFileDescriptorRef CFOptionFlags void* }
     cdecl [
-        3drop
+        2drop enable-all-callbacks
         0 mx get kqueue-mx>> wait-for-events
-        reset-run-loop
         yield
     ] alien-callback ;