Merge branch 'jh/fsmonitor-darwin-modernize'

Stop using deprecated macOS API in fsmonitor.

* jh/fsmonitor-darwin-modernize:
  fsmonitor: eliminate call to deprecated FSEventStream function

This backport to `maint-2.39` is needed to be able to build on
`macos-13`, which we need to update to as we restore the CI health of
that branch.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
next
Johannes Schindelin 2024-03-27 17:04:43 +01:00
commit bddc176e79
2 changed files with 25 additions and 14 deletions

View File

@ -80,9 +80,7 @@ void CFRunLoopRun(void);
void CFRunLoopStop(CFRunLoopRef run_loop); void CFRunLoopStop(CFRunLoopRef run_loop);
CFRunLoopRef CFRunLoopGetCurrent(void); CFRunLoopRef CFRunLoopGetCurrent(void);
extern CFStringRef kCFRunLoopDefaultMode; extern CFStringRef kCFRunLoopDefaultMode;
void FSEventStreamScheduleWithRunLoop(FSEventStreamRef stream, void FSEventStreamSetDispatchQueue(FSEventStreamRef stream, dispatch_queue_t q);
CFRunLoopRef run_loop,
CFStringRef run_loop_mode);
unsigned char FSEventStreamStart(FSEventStreamRef stream); unsigned char FSEventStreamStart(FSEventStreamRef stream);
void FSEventStreamStop(FSEventStreamRef stream); void FSEventStreamStop(FSEventStreamRef stream);
void FSEventStreamInvalidate(FSEventStreamRef stream); void FSEventStreamInvalidate(FSEventStreamRef stream);

View File

@ -1,4 +1,5 @@
#ifndef __clang__ #ifndef __clang__
#include <dispatch/dispatch.h>
#include "fsm-darwin-gcc.h" #include "fsm-darwin-gcc.h"
#else #else
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
@ -38,7 +39,9 @@ struct fsm_listen_data


FSEventStreamRef stream; FSEventStreamRef stream;


CFRunLoopRef rl; dispatch_queue_t dq;
pthread_cond_t dq_finished;
pthread_mutex_t dq_lock;


enum shutdown_style { enum shutdown_style {
SHUTDOWN_EVENT = 0, SHUTDOWN_EVENT = 0,
@ -379,8 +382,11 @@ force_shutdown:
fsmonitor_batch__free_list(batch); fsmonitor_batch__free_list(batch);
string_list_clear(&cookie_list, 0); string_list_clear(&cookie_list, 0);


pthread_mutex_lock(&data->dq_lock);
data->shutdown_style = FORCE_SHUTDOWN; data->shutdown_style = FORCE_SHUTDOWN;
CFRunLoopStop(data->rl); pthread_cond_broadcast(&data->dq_finished);
pthread_mutex_unlock(&data->dq_lock);

strbuf_release(&tmp); strbuf_release(&tmp);
return; return;
} }
@ -441,10 +447,6 @@ int fsm_listen__ctor(struct fsmonitor_daemon_state *state)
if (!data->stream) if (!data->stream)
goto failed; goto failed;


/*
* `data->rl` needs to be set inside the listener thread.
*/

return 0; return 0;


failed: failed:
@ -471,6 +473,11 @@ void fsm_listen__dtor(struct fsmonitor_daemon_state *state)
FSEventStreamRelease(data->stream); FSEventStreamRelease(data->stream);
} }


if (data->dq)
dispatch_release(data->dq);
pthread_cond_destroy(&data->dq_finished);
pthread_mutex_destroy(&data->dq_lock);

FREE_AND_NULL(state->listen_data); FREE_AND_NULL(state->listen_data);
} }


@ -479,9 +486,11 @@ void fsm_listen__stop_async(struct fsmonitor_daemon_state *state)
struct fsm_listen_data *data; struct fsm_listen_data *data;


data = state->listen_data; data = state->listen_data;
data->shutdown_style = SHUTDOWN_EVENT;


CFRunLoopStop(data->rl); pthread_mutex_lock(&data->dq_lock);
data->shutdown_style = SHUTDOWN_EVENT;
pthread_cond_broadcast(&data->dq_finished);
pthread_mutex_unlock(&data->dq_lock);
} }


void fsm_listen__loop(struct fsmonitor_daemon_state *state) void fsm_listen__loop(struct fsmonitor_daemon_state *state)
@ -490,9 +499,11 @@ void fsm_listen__loop(struct fsmonitor_daemon_state *state)


data = state->listen_data; data = state->listen_data;


data->rl = CFRunLoopGetCurrent(); pthread_mutex_init(&data->dq_lock, NULL);
pthread_cond_init(&data->dq_finished, NULL);
data->dq = dispatch_queue_create("FSMonitor", NULL);


FSEventStreamScheduleWithRunLoop(data->stream, data->rl, kCFRunLoopDefaultMode); FSEventStreamSetDispatchQueue(data->stream, data->dq);
data->stream_scheduled = 1; data->stream_scheduled = 1;


if (!FSEventStreamStart(data->stream)) { if (!FSEventStreamStart(data->stream)) {
@ -501,7 +512,9 @@ void fsm_listen__loop(struct fsmonitor_daemon_state *state)
} }
data->stream_started = 1; data->stream_started = 1;


CFRunLoopRun(); pthread_mutex_lock(&data->dq_lock);
pthread_cond_wait(&data->dq_finished, &data->dq_lock);
pthread_mutex_unlock(&data->dq_lock);


switch (data->shutdown_style) { switch (data->shutdown_style) {
case FORCE_ERROR_STOP: case FORCE_ERROR_STOP: