Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-01-16 19:54:27 +0300
committerAnna Henningsen <anna@addaleax.net>2020-01-22 01:51:36 +0300
commitc78c2771da6bf5ffc64008d37548eb87abe81ad1 (patch)
treea07b857982ef3da08082c1f53c014bc2b2bf95f1 /src/node_worker.h
parentde2c68c7dd17a217a818ea881e433034006fdb4b (diff)
src: add interrupts to Environments/Workers
Allow doing what V8’s `v8::Isolate::RequestInterrupt()` does for V8. This also works when there is no JS code currently executing. PR-URL: https://github.com/nodejs/node/pull/31386 Refs: https://github.com/openjs-foundation/summit/pull/240 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_worker.h')
-rw-r--r--src/node_worker.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/node_worker.h b/src/node_worker.h
index 632644202a5..6db7b258ebd 100644
--- a/src/node_worker.h
+++ b/src/node_worker.h
@@ -43,6 +43,9 @@ class Worker : public AsyncWrap {
tracker->TrackField("parent_port", parent_port_);
}
+ template <typename Fn>
+ inline bool RequestInterrupt(Fn&& cb);
+
SET_MEMORY_INFO_NAME(Worker)
SET_SELF_SIZE(Worker)
@@ -123,6 +126,14 @@ class Worker : public AsyncWrap {
friend class WorkerThreadData;
};
+template <typename Fn>
+bool Worker::RequestInterrupt(Fn&& cb) {
+ Mutex::ScopedLock lock(mutex_);
+ if (env_ == nullptr) return false;
+ env_->RequestInterrupt(std::move(cb));
+ return true;
+}
+
} // namespace worker
} // namespace node