aboutsummaryrefslogtreecommitdiff
path: root/src/watcher.zig
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-06-25 20:16:25 -0300
committerGravatar GitHub <noreply@github.com> 2023-06-25 16:16:25 -0700
commit3ed28f2828a29129a1791b7a4f6935d842d6493c (patch)
treec23b6e76e32bf9c2f30070af72593aa16289dc86 /src/watcher.zig
parentfcf9f0a7eeb3d462d5c6c2110ecdf5a4460c1736 (diff)
downloadbun-3ed28f2828a29129a1791b7a4f6935d842d6493c.tar.gz
bun-3ed28f2828a29129a1791b7a4f6935d842d6493c.tar.zst
bun-3ed28f2828a29129a1791b7a4f6935d842d6493c.zip
[fs.watch] fix reference/deinit (#3396)
* fix js reference * fix close oops * refactor + hasPendingActivity * fmt * fix race conditions * fixup * add test calling close on error event * fix close inside close + test * cleanup
Diffstat (limited to 'src/watcher.zig')
-rw-r--r--src/watcher.zig20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/watcher.zig b/src/watcher.zig
index 044770dc4..e3b3600ad 100644
--- a/src/watcher.zig
+++ b/src/watcher.zig
@@ -519,7 +519,7 @@ pub fn NewWatcher(comptime ContextType: type) type {
var changelist_array: [128]KEvent = std.mem.zeroes([128]KEvent);
var changelist = &changelist_array;
- while (this.running) {
+ while (true) {
defer Output.flush();
var count_ = std.os.system.kevent(
@@ -576,10 +576,12 @@ pub fn NewWatcher(comptime ContextType: type) type {
defer this.mutex.unlock();
if (this.running) {
this.ctx.onFileUpdate(watchevents, this.changed_filepaths[0..watchevents.len], this.watchlist);
+ } else {
+ break;
}
}
} else if (Environment.isLinux) {
- restart: while (this.running) {
+ restart: while (true) {
defer Output.flush();
var events = try INotify.read();
@@ -588,14 +590,14 @@ pub fn NewWatcher(comptime ContextType: type) type {
// TODO: is this thread safe?
var remaining_events = events.len;
- var name_off: u8 = 0;
- var temp_name_list: [128]?[:0]u8 = undefined;
- var temp_name_off: u8 = 0;
-
const eventlist_index = this.watchlist.items(.eventlist_index);
while (remaining_events > 0) {
- const slice = events[0..@min(remaining_events, this.watch_events.len)];
+ var name_off: u8 = 0;
+ var temp_name_list: [128]?[:0]u8 = undefined;
+ var temp_name_off: u8 = 0;
+
+ const slice = events[0..@min(128, remaining_events, this.watch_events.len)];
var watchevents = this.watch_events[0..slice.len];
var watch_event_id: u32 = 0;
for (slice) |event| {
@@ -647,8 +649,10 @@ pub fn NewWatcher(comptime ContextType: type) type {
defer this.mutex.unlock();
if (this.running) {
this.ctx.onFileUpdate(all_events[0 .. last_event_index + 1], this.changed_filepaths[0 .. name_off + 1], this.watchlist);
- remaining_events -= slice.len;
+ } else {
+ break;
}
+ remaining_events -= slice.len;
}
}
}