diff --git a/src/unix/fsevents.c b/src/unix/fsevents.c index 8f582c41cad..249dd049159 100644 --- a/src/unix/fsevents.c +++ b/src/unix/fsevents.c @@ -76,6 +76,7 @@ typedef struct uv__cf_loop_state_s uv__cf_loop_state_t; struct uv__cf_loop_signal_s { QUEUE member; uv_fs_event_t* handle; + unsigned int closing:1; }; struct uv__fsevents_event_s { @@ -98,7 +99,9 @@ struct uv__cf_loop_state_s { /* Forward declarations */ static void uv__cf_loop_cb(void* arg); static void* uv__cf_loop_runner(void* arg); -static int uv__cf_loop_signal(uv_loop_t* loop, uv_fs_event_t* handle); +static int uv__cf_loop_signal(uv_loop_t* loop, + uv_fs_event_t* handle, + unsigned int closing); /* Lazy-loaded by uv__fsevents_global_init(). */ static CFArrayRef (*pCFArrayCreate)(CFAllocatorRef, @@ -383,7 +386,8 @@ static void uv__fsevents_destroy_stream(uv_loop_t* loop) { /* Runs in CF thread, when there're new fsevent handles to add to stream */ -static void uv__fsevents_reschedule(uv_fs_event_t* handle) { +static void uv__fsevents_reschedule(uv_fs_event_t* handle, + unsigned int closing) { uv__cf_loop_state_t* state; QUEUE* q; uv_fs_event_t* curr; @@ -482,7 +486,7 @@ static void uv__fsevents_reschedule(uv_fs_event_t* handle) { * * NOTE: This is coupled with `uv_sem_wait()` in `uv__fsevents_close` */ - if (!uv__is_active(handle)) + if (closing) uv_sem_post(&state->fsevent_sem); } @@ -672,7 +676,7 @@ void uv__fsevents_loop_delete(uv_loop_t* loop) { if (loop->cf_state == NULL) return; - if (uv__cf_loop_signal(loop, NULL) != 0) + if (uv__cf_loop_signal(loop, NULL, 0) != 0) abort(); uv_thread_join(&loop->cf_thread); @@ -746,7 +750,7 @@ static void uv__cf_loop_cb(void* arg) { if (s->handle == NULL) pCFRunLoopStop(state->loop); else - uv__fsevents_reschedule(s->handle); + uv__fsevents_reschedule(s->handle, s->closing); uv__free(s); } @@ -754,7 +758,9 @@ static void uv__cf_loop_cb(void* arg) { /* Runs in UV loop to notify CF thread */ -int uv__cf_loop_signal(uv_loop_t* loop, uv_fs_event_t* handle) { +int uv__cf_loop_signal(uv_loop_t* loop, + uv_fs_event_t* handle, + unsigned int closing) { uv__cf_loop_signal_t* item; uv__cf_loop_state_t* state; @@ -763,6 +769,7 @@ int uv__cf_loop_signal(uv_loop_t* loop, uv_fs_event_t* handle) { return -ENOMEM; item->handle = handle; + item->closing = closing; uv_mutex_lock(&loop->cf_mutex); QUEUE_INSERT_TAIL(&loop->cf_signals, &item->member); @@ -825,7 +832,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) { /* Reschedule FSEventStream */ assert(handle != NULL); - err = uv__cf_loop_signal(handle->loop, handle); + err = uv__cf_loop_signal(handle->loop, handle, 0); if (err) goto fail_loop_signal; @@ -865,7 +872,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) { /* Reschedule FSEventStream */ assert(handle != NULL); - err = uv__cf_loop_signal(handle->loop, handle); + err = uv__cf_loop_signal(handle->loop, handle, 1); if (err) return -err;