aboutsummaryrefslogtreecommitdiff
path: root/src/node_platform.cc
AgeCommit message (Collapse)Author
2017-11-21src: implement v8::TaskRunner API in NodePlatformAnna Henningsen
V8 is switching APIs for scheduling tasks. Implement the new APIs. Fixes: https://github.com/nodejs/node-v8/issues/24 Refs: https://github.com/v8/v8/commit/c690f54d9580243c53f7d892fcff1ce6bae4bfc0 PR-URL: https://github.com/nodejs/node/pull/17134 Fixes: https://github.com/nodejs/node-v8/issues/24 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-11-19src: use unique_ptr for scheduled delayed tasksFranziska Hinkelmann
Use std::unique_ptr for delayed tasks in the scheduled delayed tasks vector. This makes it clear that the vector has ownership of the delayed tasks and is responsible for deleting them. Use a custom deleter for the pointers because libuv needs to close the handle and then delete the data. Provide the handle when creating the pointer instead of invoking the special delete action everytime an element is removed from the vector. PR-URL: https://github.com/nodejs/node/pull/17083 Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-11-14src: use unique_ptr in platform implementationFranziska Hinkelmann
Replace raw pointers in task queues with std::unique_ptr. This makes ownership obvious. PR-URL: https://github.com/nodejs/node/pull/16970 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2017-11-12src: cancel pending delayed platform tasks on exitAnna Henningsen
Worker threads need an event loop without active libuv handles in order to shut down. One source of handles that was previously not accounted for were delayed V8 tasks; these create timers that would be standing in the way of clearing the event loop. To solve this, keep track of the scheduled tasks in a list and close their timer handles before the corresponding isolate/loop is removed from the platform. It is not clear from the V8 documentation what the expectation is with respect to pending background tasks at the end of the isolate lifetime; however, an alternative approach of executing these scheduled tasks when flushing them led to an infinite loop of tasks scheduling each other; so it seems safe to assume that the behaviour implemented in this patch is at least acceptable. Original-PR-URL: https://github.com/ayojs/ayo/pull/120 Original-Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> PR-URL: https://github.com/nodejs/node/pull/16700 Reviewed-By: James M Snell <jasnell@gmail.com>
2017-11-12src: prepare v8 platform for multi-isolate supportAnna Henningsen
This splits the task queue used for asynchronous tasks scheduled by V8 in per-isolate queues, so that multiple threads can be supported. Original-PR-URL: https://github.com/ayojs/ayo/pull/89 Original-Reviewed-By: Timothy Gu <timothygu99@gmail.com> PR-URL: https://github.com/nodejs/node/pull/16700 Reviewed-By: James M Snell <jasnell@gmail.com>
2017-10-01src: fixup node_platform blocking task drainAnna Henningsen
https://github.com/nodejs/node/pull/15428 was supposed to account for upcoming changes in V8 upstream, but while addressing review comments a bug was introduced; `DrainBackgroundTasks()` should always at least perform one blocking drain on the background task queue. PR-URL: https://github.com/nodejs/node/pull/15639 Refs: https://github.com/nodejs/node/pull/15428 Refs: f27b5e4bdaafc73a830a0451ee3c641b8bcd08fe Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-09-21src: prepare platform for upstream V8 changesAnna Henningsen
V8 platform tasks may schedule other tasks (both background and foreground), and may perform asynchronous operations like resolving Promises. To address that: - Run the task queue drain call inside a callback scope. This makes sure asynchronous operations inside it, like resolving promises, lead to the microtask queue and any subsequent operations not being silently forgotten. - Move the task queue drain call before `EmitBeforeExit()` and only run `EmitBeforeExit()` if there is no new event loop work. - Account for possible new foreground tasks scheduled by background tasks in `DrainBackgroundTasks()`. PR-URL: https://github.com/nodejs/node/pull/15428 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matthew Loring <mattloring@google.com>
2017-08-17src: Node implementation of v8::PlatformMatt Loring
Node.js currently uses the V8 implementation of the DefaultPlatform which schedules VM tasks on a V8 managed thread pool. Since the Node.js event loop is not aware of these tasks, the Node.js process may exit while there are outstanding VM tasks. This will become problematic once asynchronous wasm compilation lands in V8. This PR introduces a Node.js specific implementation of the v8::Platform on top of libuv so that the event loop is aware of outstanding VM tasks. PR-URL: https://github.com/nodejs/node/pull/14001 Fixes: https://github.com/nodejs/node/issues/3665 Fixes: https://github.com/nodejs/node/issues/8496 Fixes: https://github.com/nodejs/node/issues/12980 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de>