Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 97c6e17

Browse files
committed
Add on_watcher_queue_updated callback for loop.
This callback is called when loop's watcher queue changes, when polling kqueue in new thread, we need to get notified when there are new events needed to be watched.
1 parent 289649a commit 97c6e17

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

deps/uv/include/uv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,8 @@ union uv_any_req {
14361436
struct uv_loop_s {
14371437
/* User data - use this for whatever. */
14381438
void* data;
1439+
/* Callback when loop's watcher queue updates. */
1440+
void (*on_watcher_queue_updated)(uv_loop_t*);
14391441
/* Loop reference counting. */
14401442
unsigned int active_handles;
14411443
void* handle_queue[2];

deps/uv/src/unix/core.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,11 @@ void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
823823
}
824824
#endif
825825

826-
if (QUEUE_EMPTY(&w->watcher_queue))
826+
if (QUEUE_EMPTY(&w->watcher_queue)) {
827827
QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
828+
if (loop->on_watcher_queue_updated)
829+
loop->on_watcher_queue_updated(loop);
830+
}
828831

829832
if (loop->watchers[w->fd] == NULL) {
830833
loop->watchers[w->fd] = w;
@@ -860,8 +863,11 @@ void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
860863
w->events = 0;
861864
}
862865
}
863-
else if (QUEUE_EMPTY(&w->watcher_queue))
866+
else if (QUEUE_EMPTY(&w->watcher_queue)) {
864867
QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
868+
if (loop->on_watcher_queue_updated)
869+
loop->on_watcher_queue_updated(loop);
870+
}
865871
}
866872

867873

@@ -877,6 +883,8 @@ void uv__io_close(uv_loop_t* loop, uv__io_t* w) {
877883
void uv__io_feed(uv_loop_t* loop, uv__io_t* w) {
878884
if (QUEUE_EMPTY(&w->pending_queue))
879885
QUEUE_INSERT_TAIL(&loop->pending_queue, &w->pending_queue);
886+
if (loop->on_watcher_queue_updated)
887+
loop->on_watcher_queue_updated(loop);
880888
}
881889

882890

0 commit comments

Comments
 (0)