]> gitweb.factorcode.org Git - factor.git/commitdiff
Linux inotify works
authorsheeple <sheeple@joy.internal.stack-effects.com>
Mon, 4 Feb 2008 17:50:02 +0000 (11:50 -0600)
committersheeple <sheeple@joy.internal.stack-effects.com>
Mon, 4 Feb 2008 17:50:02 +0000 (11:50 -0600)
extra/io/monitor/monitor.factor
extra/io/unix/linux/linux.factor
extra/io/windows/nt/monitor/monitor.factor

index 11d1b6ecf98a3959e2eb2fc06867dc0c86bb6d6f..1d8499b392bebd7f6d7bde8a1fb2a64339d16af2 100755 (executable)
@@ -17,7 +17,7 @@ TUPLE: monitor queue closed? ;
         set-monitor-queue\r
     } monitor construct ;\r
 \r
-HOOK: fill-queue io-backend ( monitor -- assoc )\r
+HOOK: fill-queue io-backend ( monitor -- )\r
 \r
 : changed-file ( changed path -- )\r
     namespace [ append ] change-at ;\r
@@ -32,7 +32,7 @@ HOOK: <monitor> io-backend ( path recursive? -- monitor )
 : next-change ( monitor -- path changed )\r
     dup check-monitor\r
     dup monitor-queue dup assoc-empty? [\r
-        drop dup fill-queue over set-monitor-queue next-change\r
+        drop dup fill-queue next-change\r
     ] [ nip dequeue-change ] if ;\r
 \r
 SYMBOL: +add-file+\r
index 9751cefe91b1675d06888a0194896c35fa6b5717..1707ac95469011f5dff331b8990c31701f454583 100755 (executable)
@@ -54,21 +54,22 @@ TUPLE: inotify watches ;
 M: linux-io <monitor> ( path recursive? -- monitor )
     drop IN_CHANGE_EVENTS add-watch ;
 
-: notify-callback ( assoc monitor -- )
-    linux-monitor-callback dup
-    [ schedule-thread-with ] [ 2drop ] if ;
+: notify-callback ( monitor -- )
+    dup linux-monitor-callback
+    f rot set-linux-monitor-callback
+    [ schedule-thread ] when* ;
 
-M: linux-io fill-queue ( monitor -- assoc )
+M: linux-io fill-queue ( monitor -- )
     dup linux-monitor-callback [
         "Cannot wait for changes on the same file from multiple threads" throw
     ] when
-    [ swap set-linux-monitor-callback stop ] callcc1
-    swap check-monitor ;
+    [ swap set-linux-monitor-callback stop ] callcc0
+    check-monitor ;
 
 M: linux-monitor dispose ( monitor -- )
     dup check-monitor
     t over set-monitor-closed?
-    H{ } over notify-callback
+    dup notify-callback
     remove-watch ;
 
 : ?flag ( n mask symbol -- n )
@@ -106,13 +107,13 @@ M: linux-monitor dispose ( monitor -- )
     inotify-event-len "inotify-event" heap-size +
     swap >r + r> ;
 
-: wd>queue ( wd -- queue )
-    inotify-event-wd wd>monitor monitor-queue ;
-
 : parse-file-notifications ( i buffer -- )
     2dup events-exhausted? [ 2drop ] [
-        2dup inotify-event@ dup inotify-event-wd wd>queue
-        [ parse-file-notify changed-file ] bind
+        2dup inotify-event@ dup inotify-event-wd wd>monitor [
+            monitor-queue [
+                parse-file-notify changed-file
+            ] bind
+        ] keep notify-callback
         next-event parse-file-notifications
     ] if ;
 
@@ -135,7 +136,7 @@ M: inotify-task do-io-task ( task -- )
     io-task-port read-notifications f ;
 
 M: linux-io init-io ( -- )
-    <select-mx> mx set-global ; ! init-inotify ;
+    <select-mx> dup mx set-global init-inotify ;
 
 T{ linux-io } set-io-backend
 
index f2cc4ef92a81eaa5cbf72523c00b87dab2b7bff8..d418dff2701a5c90939b192ae1935ab9dd45e0da 100755 (executable)
@@ -78,6 +78,7 @@ M: windows-nt-io <monitor> ( path recursive? -- monitor )
     dup FILE_NOTIFY_INFORMATION-NextEntryOffset dup zero?
     [ 3drop ] [ swap <displaced-alien> (changed-files) ] if ;
 
-M: windows-nt-io fill-queue ( monitor -- assoc )
-    dup win32-monitor-path over buffer-ptr rot read-changes
-    [ zero? [ 2drop ] [ (changed-files) ] if ] H{ } make-assoc ;
+M: windows-nt-io fill-queue ( monitor -- )
+    dup win32-monitor-path over buffer-ptr pick read-changes
+    [ zero? [ 2drop ] [ (changed-files) ] if ] H{ } make-assoc
+    swap set-monitor-queue ;