@@ -76,6 +76,7 @@ typedef struct uv__cf_loop_state_s uv__cf_loop_state_t; |
76 | 76 | struct uv__cf_loop_signal_s { |
77 | 77 | QUEUE member; |
78 | 78 | uv_fs_event_t* handle; |
| 79 | + unsigned int closing:1; |
79 | 80 | }; |
80 | 81 |
|
81 | 82 | struct uv__fsevents_event_s { |
@@ -98,7 +99,9 @@ struct uv__cf_loop_state_s { |
98 | 99 | /* Forward declarations */ |
99 | 100 | static void uv__cf_loop_cb(void* arg); |
100 | 101 | static void* uv__cf_loop_runner(void* arg); |
101 | | -static int uv__cf_loop_signal(uv_loop_t* loop, uv_fs_event_t* handle); |
| 102 | +static int uv__cf_loop_signal(uv_loop_t* loop, |
| 103 | + uv_fs_event_t* handle, |
| 104 | + unsigned int closing); |
102 | 105 |
|
103 | 106 | /* Lazy-loaded by uv__fsevents_global_init(). */ |
104 | 107 | static CFArrayRef (*pCFArrayCreate)(CFAllocatorRef, |
@@ -383,7 +386,8 @@ static void uv__fsevents_destroy_stream(uv_loop_t* loop) { |
383 | 386 |
|
384 | 387 |
|
385 | 388 | /* Runs in CF thread, when there're new fsevent handles to add to stream */ |
386 | | -static void uv__fsevents_reschedule(uv_fs_event_t* handle) { |
| 389 | +static void uv__fsevents_reschedule(uv_fs_event_t* handle, |
| 390 | + unsigned int closing) { |
387 | 391 | uv__cf_loop_state_t* state; |
388 | 392 | QUEUE* q; |
389 | 393 | uv_fs_event_t* curr; |
@@ -482,7 +486,7 @@ static void uv__fsevents_reschedule(uv_fs_event_t* handle) { |
482 | 486 | * |
483 | 487 | * NOTE: This is coupled with `uv_sem_wait()` in `uv__fsevents_close` |
484 | 488 | */ |
485 | | - if (!uv__is_active(handle)) |
| 489 | + if (closing) |
486 | 490 | uv_sem_post(&state->fsevent_sem); |
487 | 491 | } |
488 | 492 |
|
@@ -672,7 +676,7 @@ void uv__fsevents_loop_delete(uv_loop_t* loop) { |
672 | 676 | if (loop->cf_state == NULL) |
673 | 677 | return; |
674 | 678 |
|
675 | | - if (uv__cf_loop_signal(loop, NULL) != 0) |
| 679 | + if (uv__cf_loop_signal(loop, NULL, 0) != 0) |
676 | 680 | abort(); |
677 | 681 |
|
678 | 682 | uv_thread_join(&loop->cf_thread); |
@@ -746,15 +750,17 @@ static void uv__cf_loop_cb(void* arg) { |
746 | 750 | if (s->handle == NULL) |
747 | 751 | pCFRunLoopStop(state->loop); |
748 | 752 | else |
749 | | - uv__fsevents_reschedule(s->handle); |
| 753 | + uv__fsevents_reschedule(s->handle, s->closing); |
750 | 754 |
|
751 | 755 | uv__free(s); |
752 | 756 | } |
753 | 757 | } |
754 | 758 |
|
755 | 759 |
|
756 | 760 | /* Runs in UV loop to notify CF thread */ |
757 | | -int uv__cf_loop_signal(uv_loop_t* loop, uv_fs_event_t* handle) { |
| 761 | +int uv__cf_loop_signal(uv_loop_t* loop, |
| 762 | + uv_fs_event_t* handle, |
| 763 | + unsigned int closing) { |
758 | 764 | uv__cf_loop_signal_t* item; |
759 | 765 | uv__cf_loop_state_t* state; |
760 | 766 |
|
@@ -763,6 +769,7 @@ int uv__cf_loop_signal(uv_loop_t* loop, uv_fs_event_t* handle) { |
763 | 769 | return -ENOMEM; |
764 | 770 |
|
765 | 771 | item->handle = handle; |
| 772 | + item->closing = closing; |
766 | 773 |
|
767 | 774 | uv_mutex_lock(&loop->cf_mutex); |
768 | 775 | QUEUE_INSERT_TAIL(&loop->cf_signals, &item->member); |
@@ -825,7 +832,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) { |
825 | 832 |
|
826 | 833 | /* Reschedule FSEventStream */ |
827 | 834 | assert(handle != NULL); |
828 | | - err = uv__cf_loop_signal(handle->loop, handle); |
| 835 | + err = uv__cf_loop_signal(handle->loop, handle, 0); |
829 | 836 | if (err) |
830 | 837 | goto fail_loop_signal; |
831 | 838 |
|
@@ -865,7 +872,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) { |
865 | 872 |
|
866 | 873 | /* Reschedule FSEventStream */ |
867 | 874 | assert(handle != NULL); |
868 | | - err = uv__cf_loop_signal(handle->loop, handle); |
| 875 | + err = uv__cf_loop_signal(handle->loop, handle, 1); |
869 | 876 | if (err) |
870 | 877 | return -err; |
871 | 878 |
|
|