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
: 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
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 )
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 ;
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
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 ;