Git fork

Merge branch 'jh/fsmonitor-darwin-modernize'

Stop using deprecated macOS API in fsmonitor.

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

+25 -14
+1 -3
compat/fsmonitor/fsm-darwin-gcc.h
··· 80 80 void CFRunLoopStop(CFRunLoopRef run_loop); 81 81 CFRunLoopRef CFRunLoopGetCurrent(void); 82 82 extern CFStringRef kCFRunLoopDefaultMode; 83 - void FSEventStreamScheduleWithRunLoop(FSEventStreamRef stream, 84 - CFRunLoopRef run_loop, 85 - CFStringRef run_loop_mode); 83 + void FSEventStreamSetDispatchQueue(FSEventStreamRef stream, dispatch_queue_t q); 86 84 unsigned char FSEventStreamStart(FSEventStreamRef stream); 87 85 void FSEventStreamStop(FSEventStreamRef stream); 88 86 void FSEventStreamInvalidate(FSEventStreamRef stream);
+24 -11
compat/fsmonitor/fsm-listen-darwin.c
··· 1 1 #ifndef __clang__ 2 + #include <dispatch/dispatch.h> 2 3 #include "fsm-darwin-gcc.h" 3 4 #else 4 5 #include <CoreFoundation/CoreFoundation.h> ··· 38 39 39 40 FSEventStreamRef stream; 40 41 41 - CFRunLoopRef rl; 42 + dispatch_queue_t dq; 43 + pthread_cond_t dq_finished; 44 + pthread_mutex_t dq_lock; 42 45 43 46 enum shutdown_style { 44 47 SHUTDOWN_EVENT = 0, ··· 379 382 fsmonitor_batch__free_list(batch); 380 383 string_list_clear(&cookie_list, 0); 381 384 385 + pthread_mutex_lock(&data->dq_lock); 382 386 data->shutdown_style = FORCE_SHUTDOWN; 383 - CFRunLoopStop(data->rl); 387 + pthread_cond_broadcast(&data->dq_finished); 388 + pthread_mutex_unlock(&data->dq_lock); 389 + 384 390 strbuf_release(&tmp); 385 391 return; 386 392 } ··· 441 447 if (!data->stream) 442 448 goto failed; 443 449 444 - /* 445 - * `data->rl` needs to be set inside the listener thread. 446 - */ 447 - 448 450 return 0; 449 451 450 452 failed: ··· 471 473 FSEventStreamRelease(data->stream); 472 474 } 473 475 476 + if (data->dq) 477 + dispatch_release(data->dq); 478 + pthread_cond_destroy(&data->dq_finished); 479 + pthread_mutex_destroy(&data->dq_lock); 480 + 474 481 FREE_AND_NULL(state->listen_data); 475 482 } 476 483 ··· 479 486 struct fsm_listen_data *data; 480 487 481 488 data = state->listen_data; 482 - data->shutdown_style = SHUTDOWN_EVENT; 483 489 484 - CFRunLoopStop(data->rl); 490 + pthread_mutex_lock(&data->dq_lock); 491 + data->shutdown_style = SHUTDOWN_EVENT; 492 + pthread_cond_broadcast(&data->dq_finished); 493 + pthread_mutex_unlock(&data->dq_lock); 485 494 } 486 495 487 496 void fsm_listen__loop(struct fsmonitor_daemon_state *state) ··· 490 499 491 500 data = state->listen_data; 492 501 493 - data->rl = CFRunLoopGetCurrent(); 502 + pthread_mutex_init(&data->dq_lock, NULL); 503 + pthread_cond_init(&data->dq_finished, NULL); 504 + data->dq = dispatch_queue_create("FSMonitor", NULL); 494 505 495 - FSEventStreamScheduleWithRunLoop(data->stream, data->rl, kCFRunLoopDefaultMode); 506 + FSEventStreamSetDispatchQueue(data->stream, data->dq); 496 507 data->stream_scheduled = 1; 497 508 498 509 if (!FSEventStreamStart(data->stream)) { ··· 501 512 } 502 513 data->stream_started = 1; 503 514 504 - CFRunLoopRun(); 515 + pthread_mutex_lock(&data->dq_lock); 516 + pthread_cond_wait(&data->dq_finished, &data->dq_lock); 517 + pthread_mutex_unlock(&data->dq_lock); 505 518 506 519 switch (data->shutdown_style) { 507 520 case FORCE_ERROR_STOP: