]> gitweb.factorcode.org Git - factor.git/commitdiff
Use kqueue on Mac OS X instead of select
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 9 Dec 2008 23:49:03 +0000 (17:49 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 9 Dec 2008 23:49:03 +0000 (17:49 -0600)
basis/io/unix/backend/backend.factor
basis/io/unix/kqueue/kqueue.factor
basis/io/unix/macosx/macosx.factor
basis/unix/kqueue/kqueue.factor

index 85363c8404c7274acd79f05f5b641ae9c7753593..1666d60c83fee70f2678fc02e37efe6f9b0d7e60 100644 (file)
@@ -64,10 +64,10 @@ M: mx remove-output-callbacks writes>> delete-at* drop ;
 GENERIC: wait-for-events ( ms mx -- )
 
 : input-available ( fd mx -- )
-    remove-input-callbacks [ resume ] each ;
+    reads>> delete-at* drop [ resume ] each ;
 
 : output-available ( fd mx -- )
-    remove-output-callbacks [ resume ] each ;
+    writes>> delete-at* drop [ resume ] each ;
 
 M: fd cancel-operation ( fd -- )
     dup disposed>> [ drop ] [
index 6b687a8afb06a7eb9e8e9c7933d81df254e756c9..b4e2b7af6fb017be664c9285806415d5561cfd4a 100644 (file)
@@ -2,10 +2,10 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.c-types combinators io.unix.backend
 kernel math.bitwise sequences struct-arrays unix unix.kqueue
-unix.time ;
+unix.time assocs ;
 IN: io.unix.kqueue
 
-TUPLE: kqueue-mx < mx events monitors ;
+TUPLE: kqueue-mx < mx events ;
 
 : max-events ( -- n )
     #! We read up to 256 events at a time. This is an arbitrary
@@ -14,7 +14,6 @@ TUPLE: kqueue-mx < mx events monitors ;
 
 : <kqueue-mx> ( -- mx )
     kqueue-mx new-mx
-        H{ } clone >>monitors
         kqueue dup io-error >>fd
         max-events "kevent" <struct-array> >>events ;
 
@@ -35,30 +34,25 @@ M: kqueue-mx add-input-callback ( thread fd mx -- )
 
 M: kqueue-mx add-output-callback ( thread fd mx -- )
     [ call-next-method ] [
-        [ EVFILT_WRITE EV_DELETE make-kevent ] dip
+        [ EVFILT_WRITE { EV_ADD EV_ONESHOT } flags make-kevent ] dip
         register-kevent
     ] 2bi ;
 
-: cancel-input-callbacks ( fd mx -- seq )
-    [
-        [ EVFILT_READ EV_DELETE make-kevent ] dip
-        register-kevent
-    ] [ remove-input-callbacks ] 2bi ;
-
-: cancel-output-callbacks ( fd mx -- seq )
-    [
-        [ EVFILT_WRITE EV_DELETE make-kevent ] dip
-        register-kevent
-    ] [ remove-output-callbacks ] 2bi ;
+M: kqueue-mx remove-input-callbacks ( fd mx -- seq )
+    2dup reads>> key? [
+        [ call-next-method ] [
+            [ EVFILT_READ EV_DELETE make-kevent ] dip
+            register-kevent
+        ] 2bi
+    ] [ 2drop f ] if ;
 
-M: fd cancel-operation ( fd -- )
-    dup disposed>> [ drop ] [
-        fd>>
-        mx get-global
-        [ cancel-input-callbacks [ t swap resume-with ] each ]
-        [ cancel-output-callbacks [ t swap resume-with ] each ]
-        2bi
-    ] if ;
+M: kqueue-mx remove-output-callbacks ( fd mx -- seq )
+    2dup writes>> key? [
+        [
+            [ EVFILT_WRITE EV_DELETE make-kevent ] dip
+            register-kevent
+        ] [ call-next-method ] 2bi
+    ] [ 2drop f ] if ;
 
 : wait-kevent ( mx timespec -- n )
     [
index 77140b81c95725e89490040d95233012e555cb27..ef52b676fb60d53070c9c0a80e034f53dc59cc83 100644 (file)
@@ -1,6 +1,10 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 IN: io.unix.macosx
-USING: io.unix.bsd io.backend system ;
+USING: io.unix.backend io.unix.bsd io.unix.kqueue io.backend
+namespaces system ;
+
+M: macosx init-io ( -- )
+    <kqueue-mx> mx set-global ;
 
 macosx set-io-backend
index 83c3bb5232c50cdbb76b3c3a61daf30baf670601..d7623df8be0954b85446de497a84fb144f04101e 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax system sequences vocabs.loader words ;
+USING: alien.syntax system sequences vocabs.loader words
+accessors ;
 IN: unix.kqueue
 
 << "unix.kqueue." os name>> append require >>