Linux inotify works

db4
sheeple 2008-02-04 11:50:02 -06:00
parent b7f1e84eef
commit 46e02fa30d
3 changed files with 20 additions and 18 deletions

View File

@ -17,7 +17,7 @@ TUPLE: monitor queue closed? ;
set-monitor-queue set-monitor-queue
} monitor construct ; } monitor construct ;
HOOK: fill-queue io-backend ( monitor -- assoc ) HOOK: fill-queue io-backend ( monitor -- )
: changed-file ( changed path -- ) : changed-file ( changed path -- )
namespace [ append ] change-at ; namespace [ append ] change-at ;
@ -32,7 +32,7 @@ HOOK: <monitor> io-backend ( path recursive? -- monitor )
: next-change ( monitor -- path changed ) : next-change ( monitor -- path changed )
dup check-monitor dup check-monitor
dup monitor-queue dup assoc-empty? [ 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 ; ] [ nip dequeue-change ] if ;
SYMBOL: +add-file+ SYMBOL: +add-file+

View File

@ -54,21 +54,22 @@ TUPLE: inotify watches ;
M: linux-io <monitor> ( path recursive? -- monitor ) M: linux-io <monitor> ( path recursive? -- monitor )
drop IN_CHANGE_EVENTS add-watch ; drop IN_CHANGE_EVENTS add-watch ;
: notify-callback ( assoc monitor -- ) : notify-callback ( monitor -- )
linux-monitor-callback dup dup linux-monitor-callback
[ schedule-thread-with ] [ 2drop ] if ; 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 [ dup linux-monitor-callback [
"Cannot wait for changes on the same file from multiple threads" throw "Cannot wait for changes on the same file from multiple threads" throw
] when ] when
[ swap set-linux-monitor-callback stop ] callcc1 [ swap set-linux-monitor-callback stop ] callcc0
swap check-monitor ; check-monitor ;
M: linux-monitor dispose ( monitor -- ) M: linux-monitor dispose ( monitor -- )
dup check-monitor dup check-monitor
t over set-monitor-closed? t over set-monitor-closed?
H{ } over notify-callback dup notify-callback
remove-watch ; remove-watch ;
: ?flag ( n mask symbol -- n ) : ?flag ( n mask symbol -- n )
@ -106,13 +107,13 @@ M: linux-monitor dispose ( monitor -- )
inotify-event-len "inotify-event" heap-size + inotify-event-len "inotify-event" heap-size +
swap >r + r> ; swap >r + r> ;
: wd>queue ( wd -- queue )
inotify-event-wd wd>monitor monitor-queue ;
: parse-file-notifications ( i buffer -- ) : parse-file-notifications ( i buffer -- )
2dup events-exhausted? [ 2drop ] [ 2dup events-exhausted? [ 2drop ] [
2dup inotify-event@ dup inotify-event-wd wd>queue 2dup inotify-event@ dup inotify-event-wd wd>monitor [
[ parse-file-notify changed-file ] bind monitor-queue [
parse-file-notify changed-file
] bind
] keep notify-callback
next-event parse-file-notifications next-event parse-file-notifications
] if ; ] if ;
@ -135,7 +136,7 @@ M: inotify-task do-io-task ( task -- )
io-task-port read-notifications f ; io-task-port read-notifications f ;
M: linux-io init-io ( -- ) 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 T{ linux-io } set-io-backend

View File

@ -78,6 +78,7 @@ M: windows-nt-io <monitor> ( path recursive? -- monitor )
dup FILE_NOTIFY_INFORMATION-NextEntryOffset dup zero? dup FILE_NOTIFY_INFORMATION-NextEntryOffset dup zero?
[ 3drop ] [ swap <displaced-alien> (changed-files) ] if ; [ 3drop ] [ swap <displaced-alien> (changed-files) ] if ;
M: windows-nt-io fill-queue ( monitor -- assoc ) M: windows-nt-io fill-queue ( monitor -- )
dup win32-monitor-path over buffer-ptr rot read-changes dup win32-monitor-path over buffer-ptr pick read-changes
[ zero? [ 2drop ] [ (changed-files) ] if ] H{ } make-assoc ; [ zero? [ 2drop ] [ (changed-files) ] if ] H{ } make-assoc
swap set-monitor-queue ;