1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-18 03:06:17 +02:00

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 commit is contained in:
Junio C Hamano 2022-12-19 11:46:14 +09:00
commit 636de956c4
2 changed files with 25 additions and 14 deletions

View File

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

View File

@ -1,4 +1,5 @@
#ifndef __clang__
#include <dispatch/dispatch.h>
#include "fsm-darwin-gcc.h"
#else
#include <CoreFoundation/CoreFoundation.h>
@ -38,7 +39,9 @@ struct fsm_listen_data
FSEventStreamRef stream;
CFRunLoopRef rl;
dispatch_queue_t dq;
pthread_cond_t dq_finished;
pthread_mutex_t dq_lock;
enum shutdown_style {
SHUTDOWN_EVENT = 0,
@ -379,8 +382,11 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef,
fsmonitor_batch__free_list(batch);
string_list_clear(&cookie_list, 0);
pthread_mutex_lock(&data->dq_lock);
data->shutdown_style = FORCE_SHUTDOWN;
CFRunLoopStop(data->rl);
pthread_cond_broadcast(&data->dq_finished);
pthread_mutex_unlock(&data->dq_lock);
strbuf_release(&tmp);
return;
}
@ -441,10 +447,6 @@ int fsm_listen__ctor(struct fsmonitor_daemon_state *state)
if (!data->stream)
goto failed;
/*
* `data->rl` needs to be set inside the listener thread.
*/
return 0;
failed:
@ -471,6 +473,11 @@ void fsm_listen__dtor(struct fsmonitor_daemon_state *state)
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);
}
@ -479,9 +486,11 @@ void fsm_listen__stop_async(struct fsmonitor_daemon_state *state)
struct fsm_listen_data *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)
@ -490,9 +499,11 @@ void fsm_listen__loop(struct fsmonitor_daemon_state *state)
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;
if (!FSEventStreamStart(data->stream)) {
@ -501,7 +512,9 @@ void fsm_listen__loop(struct fsmonitor_daemon_state *state)
}
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) {
case FORCE_ERROR_STOP: