Skip to content

Commit e2f575f

Browse files
committed
Merge branch 'td/fsmonitor-darwin-cookie-flush' into seen
The 'fsmonitor' daemon on macOS has been updated to flush pending FSEvents before waiting for the cookie file, to avoid premature timeouts on busy systems. * td/fsmonitor-darwin-cookie-flush: fsmonitor: flush pending FSEvents before cookie wait
2 parents b75dbd9 + 08b12d9 commit e2f575f

6 files changed

Lines changed: 23 additions & 0 deletions

File tree

builtin/fsmonitor--daemon.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ static enum fsmonitor_cookie_item_result with_lock__wait_for_cookie(
206206
close(fd);
207207
unlink(cookie_pathname.buf);
208208

209+
/* The listener callback takes main_lock, so this must not block. */
210+
fsm_listen__flush_async(state);
211+
209212
/*
210213
* Wait for the listener thread to observe the cookie file.
211214
* Time out after a short interval so that the client

compat/fsmonitor/fsm-darwin-gcc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ CFRunLoopRef CFRunLoopGetCurrent(void);
8282
extern CFStringRef kCFRunLoopDefaultMode;
8383
void FSEventStreamSetDispatchQueue(FSEventStreamRef stream, dispatch_queue_t q);
8484
unsigned char FSEventStreamStart(FSEventStreamRef stream);
85+
FSEventStreamEventId FSEventStreamFlushAsync(FSEventStreamRef stream);
8586
void FSEventStreamStop(FSEventStreamRef stream);
8687
void FSEventStreamInvalidate(FSEventStreamRef stream);
8788
void FSEventStreamRelease(FSEventStreamRef stream);

compat/fsmonitor/fsm-listen-darwin.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ void fsm_listen__stop_async(struct fsmonitor_daemon_state *state)
496496
pthread_mutex_unlock(&data->dq_lock);
497497
}
498498

499+
void fsm_listen__flush_async(struct fsmonitor_daemon_state *state)
500+
{
501+
FSEventStreamFlushAsync(state->listen_data->stream);
502+
}
503+
499504
void fsm_listen__loop(struct fsmonitor_daemon_state *state)
500505
{
501506
struct fsm_listen_data *data;

compat/fsmonitor/fsm-listen-linux.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ void fsm_listen__stop_async(struct fsmonitor_daemon_state *state)
493493
state->listen_data->shutdown = SHUTDOWN_STOP;
494494
}
495495

496+
void fsm_listen__flush_async(struct fsmonitor_daemon_state *state UNUSED)
497+
{
498+
}
499+
496500
/*
497501
* Process a single inotify event and queue for publication.
498502
*/

compat/fsmonitor/fsm-listen-win32.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ void fsm_listen__stop_async(struct fsmonitor_daemon_state *state)
290290
SetEvent(state->listen_data->hListener[LISTENER_SHUTDOWN]);
291291
}
292292

293+
void fsm_listen__flush_async(struct fsmonitor_daemon_state *state UNUSED)
294+
{
295+
}
296+
293297
static struct one_watch *create_watch(const char *path)
294298
{
295299
struct one_watch *watch = NULL;

compat/fsmonitor/fsm-listen.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ void fsm_listen__dtor(struct fsmonitor_daemon_state *state);
3838
*/
3939
void fsm_listen__loop(struct fsmonitor_daemon_state *state);
4040

41+
/*
42+
* Prompt the listener to deliver queued filesystem events, if supported.
43+
* This does not wait for the events to be processed.
44+
*/
45+
void fsm_listen__flush_async(struct fsmonitor_daemon_state *state);
46+
4147
/*
4248
* Gently request that the fsmonitor listener thread shutdown.
4349
* It does not wait for it to stop. The caller should do a JOIN

0 commit comments

Comments
 (0)