mirror of
https://github.com/electron/electron.git
synced 2026-01-27 00:09:09 -05:00
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: loc <andy@slack-corp.com> Co-authored-by: Robo <hop2deep@gmail.com> Co-authored-by: Jeremy Apthorp <nornagon@nornagon.net>
60 lines
2.6 KiB
Diff
60 lines
2.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Shelley Vohr <shelley.vohr@gmail.com>
|
|
Date: Mon, 30 Jul 2018 10:34:54 -0700
|
|
Subject: feat: add uv_loop watcher_queue code
|
|
|
|
Electron's Node Integration works by listening to Node's backend file descriptor in a separate thread; when an event is ready the backend file descriptor will trigger a new event for it, and the main thread will then iterate the libuv loop. For certain operations (ex. adding a timeout task) the backend file descriptor isn't informed, & as a result the main thread doesn't know it needs to iterate the libuv loop so the timeout task will never execute until something else trigger a new event. This commit should be removed when https://github.com/libuv/libuv/pull/1921 is merged
|
|
|
|
diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h
|
|
index 626cebabd8c9ea13410a61286e902e0b0986257b..7f1ea84a768baa0d22351456600fef20c7f3f310 100644
|
|
--- a/deps/uv/include/uv.h
|
|
+++ b/deps/uv/include/uv.h
|
|
@@ -1740,6 +1740,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];
|
|
diff --git a/deps/uv/src/unix/core.c b/deps/uv/src/unix/core.c
|
|
index 04999dce36d19383fc574a6c061b7b4d0c46f6dc..f8c523cde05fcf440423e1865920b75ad9e633a2 100644
|
|
--- a/deps/uv/src/unix/core.c
|
|
+++ b/deps/uv/src/unix/core.c
|
|
@@ -899,8 +899,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;
|
|
@@ -936,8 +939,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);
|
|
+ }
|
|
}
|
|
|
|
|
|
@@ -954,6 +960,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);
|
|
}
|
|
|
|
|