GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fsevents: fix race on simultaneous init+close · indutny/libuv@6b059f5

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/unix
    • fsevents.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/unix/fsevents.c‎

Copy file name to clipboardExpand all lines: src/unix/fsevents.c
+15-8Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ typedef struct uv__cf_loop_state_s uv__cf_loop_state_t;
7676
struct uv__cf_loop_signal_s {
7777
QUEUE member;
7878
uv_fs_event_t* handle;
79+
unsigned int closing:1;
7980
};
8081

8182
struct uv__fsevents_event_s {
@@ -98,7 +99,9 @@ struct uv__cf_loop_state_s {
9899
/* Forward declarations */
99100
static void uv__cf_loop_cb(void* arg);
100101
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);
102105

103106
/* Lazy-loaded by uv__fsevents_global_init(). */
104107
static CFArrayRef (*pCFArrayCreate)(CFAllocatorRef,
@@ -383,7 +386,8 @@ static void uv__fsevents_destroy_stream(uv_loop_t* loop) {
383386

384387

385388
/* 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) {
387391
uv__cf_loop_state_t* state;
388392
QUEUE* q;
389393
uv_fs_event_t* curr;
@@ -482,7 +486,7 @@ static void uv__fsevents_reschedule(uv_fs_event_t* handle) {
482486
*
483487
* NOTE: This is coupled with `uv_sem_wait()` in `uv__fsevents_close`
484488
*/
485-
if (!uv__is_active(handle))
489+
if (closing)
486490
uv_sem_post(&state->fsevent_sem);
487491
}
488492

@@ -672,7 +676,7 @@ void uv__fsevents_loop_delete(uv_loop_t* loop) {
672676
if (loop->cf_state == NULL)
673677
return;
674678

675-
if (uv__cf_loop_signal(loop, NULL) != 0)
679+
if (uv__cf_loop_signal(loop, NULL, 0) != 0)
676680
abort();
677681

678682
uv_thread_join(&loop->cf_thread);
@@ -746,15 +750,17 @@ static void uv__cf_loop_cb(void* arg) {
746750
if (s->handle == NULL)
747751
pCFRunLoopStop(state->loop);
748752
else
749-
uv__fsevents_reschedule(s->handle);
753+
uv__fsevents_reschedule(s->handle, s->closing);
750754

751755
uv__free(s);
752756
}
753757
}
754758

755759

756760
/* 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) {
758764
uv__cf_loop_signal_t* item;
759765
uv__cf_loop_state_t* state;
760766

@@ -763,6 +769,7 @@ int uv__cf_loop_signal(uv_loop_t* loop, uv_fs_event_t* handle) {
763769
return -ENOMEM;
764770

765771
item->handle = handle;
772+
item->closing = closing;
766773

767774
uv_mutex_lock(&loop->cf_mutex);
768775
QUEUE_INSERT_TAIL(&loop->cf_signals, &item->member);
@@ -825,7 +832,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) {
825832

826833
/* Reschedule FSEventStream */
827834
assert(handle != NULL);
828-
err = uv__cf_loop_signal(handle->loop, handle);
835+
err = uv__cf_loop_signal(handle->loop, handle, 0);
829836
if (err)
830837
goto fail_loop_signal;
831838

@@ -865,7 +872,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) {
865872

866873
/* Reschedule FSEventStream */
867874
assert(handle != NULL);
868-
err = uv__cf_loop_signal(handle->loop, handle);
875+
err = uv__cf_loop_signal(handle->loop, handle, 1);
869876
if (err)
870877
return -err;
871878

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.