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. (cherry picked from commit e609f70ad0ade0f54316c1417082d85010e79e7e)
This commit is contained in:
Родитель
bb409d26f2
Коммит
731a239b69
|
@ -1539,6 +1539,8 @@ union uv_any_req {
|
|||
struct uv_loop_s {
|
||||
/* User data - use this for whatever. */
|
||||
void* data;
|
||||
/* Callback when loop's watcher queue updates. */
|
||||
void (*on_watcher_queue_updated)(uv_loop_t*);
|
||||
/* Loop reference counting. */
|
||||
unsigned int active_handles;
|
||||
void* handle_queue[2];
|
||||
|
|
|
@ -863,8 +863,11 @@ void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
|
|||
return;
|
||||
#endif
|
||||
|
||||
if (QUEUE_EMPTY(&w->watcher_queue))
|
||||
if (QUEUE_EMPTY(&w->watcher_queue)) {
|
||||
QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
|
||||
if (loop->on_watcher_queue_updated)
|
||||
loop->on_watcher_queue_updated(loop);
|
||||
}
|
||||
|
||||
if (loop->watchers[w->fd] == NULL) {
|
||||
loop->watchers[w->fd] = w;
|
||||
|
@ -900,8 +903,11 @@ void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
|
|||
w->events = 0;
|
||||
}
|
||||
}
|
||||
else if (QUEUE_EMPTY(&w->watcher_queue))
|
||||
else if (QUEUE_EMPTY(&w->watcher_queue)) {
|
||||
QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
|
||||
if (loop->on_watcher_queue_updated)
|
||||
loop->on_watcher_queue_updated(loop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -917,6 +923,8 @@ void uv__io_close(uv_loop_t* loop, uv__io_t* w) {
|
|||
void uv__io_feed(uv_loop_t* loop, uv__io_t* w) {
|
||||
if (QUEUE_EMPTY(&w->pending_queue))
|
||||
QUEUE_INSERT_TAIL(&loop->pending_queue, &w->pending_queue);
|
||||
if (loop->on_watcher_queue_updated)
|
||||
loop->on_watcher_queue_updated(loop);
|
||||
}
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче