From 46e02fa30d45f23fe98aed2ff4233fa0eba26415 Mon Sep 17 00:00:00 2001 From: sheeple Date: Mon, 4 Feb 2008 11:50:02 -0600 Subject: [PATCH] Linux inotify works --- extra/io/monitor/monitor.factor | 4 ++-- extra/io/unix/linux/linux.factor | 27 +++++++++++----------- extra/io/windows/nt/monitor/monitor.factor | 7 +++--- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/extra/io/monitor/monitor.factor b/extra/io/monitor/monitor.factor index 11d1b6ecf9..1d8499b392 100755 --- a/extra/io/monitor/monitor.factor +++ b/extra/io/monitor/monitor.factor @@ -17,7 +17,7 @@ TUPLE: monitor queue closed? ; set-monitor-queue } monitor construct ; -HOOK: fill-queue io-backend ( monitor -- assoc ) +HOOK: fill-queue io-backend ( monitor -- ) : changed-file ( changed path -- ) namespace [ append ] change-at ; @@ -32,7 +32,7 @@ HOOK: io-backend ( path recursive? -- monitor ) : next-change ( monitor -- path changed ) dup check-monitor dup monitor-queue dup assoc-empty? [ - drop dup fill-queue over set-monitor-queue next-change + drop dup fill-queue next-change ] [ nip dequeue-change ] if ; SYMBOL: +add-file+ diff --git a/extra/io/unix/linux/linux.factor b/extra/io/unix/linux/linux.factor index 9751cefe91..1707ac9546 100755 --- a/extra/io/unix/linux/linux.factor +++ b/extra/io/unix/linux/linux.factor @@ -54,21 +54,22 @@ TUPLE: inotify watches ; M: linux-io ( 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 ( -- ) - mx set-global ; ! init-inotify ; + dup mx set-global init-inotify ; T{ linux-io } set-io-backend diff --git a/extra/io/windows/nt/monitor/monitor.factor b/extra/io/windows/nt/monitor/monitor.factor index f2cc4ef92a..d418dff270 100755 --- a/extra/io/windows/nt/monitor/monitor.factor +++ b/extra/io/windows/nt/monitor/monitor.factor @@ -78,6 +78,7 @@ M: windows-nt-io ( path recursive? -- monitor ) dup FILE_NOTIFY_INFORMATION-NextEntryOffset dup zero? [ 3drop ] [ swap (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 ;