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
path: root/src/env.h
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-01-15 21:48:37 +0300
committerShelley Vohr <shelley.vohr@gmail.com>2020-02-17 21:54:09 +0300
commit600e96ec049a8985d17d2b0318e15f63db0c036b (patch)
treede80fe412c59877479f6e49ea0a492455c28ebaf /src/env.h
parent74a7cdbe05feee981eabfa13675a14a49773adff (diff)
src: add a threadsafe variant of SetImmediate()
Add a variant of `SetImmediate()` that can be called from any thread. This allows removing the `AsyncRequest` abstraction and replaces it with a more generic mechanism. 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/env.h')
-rw-r--r--src/env.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/env.h b/src/env.h
index ed8e955ec25..cd1b8e95170 100644
--- a/src/env.h
+++ b/src/env.h
@@ -1196,6 +1196,9 @@ class Environment : public MemoryRetainer {
inline void SetImmediate(Fn&& cb);
template <typename Fn>
inline void SetUnrefImmediate(Fn&& cb);
+ template <typename Fn>
+ // This behaves like SetImmediate() but can be called from any thread.
+ inline void SetImmediateThreadsafe(Fn&& cb);
// This needs to be available for the JS-land setImmediate().
void ToggleImmediateRef(bool ref);
@@ -1281,7 +1284,7 @@ class Environment : public MemoryRetainer {
uv_idle_t immediate_idle_handle_;
uv_prepare_t idle_prepare_handle_;
uv_check_t idle_check_handle_;
- uv_async_t cleanup_finalization_groups_async_;
+ uv_async_t task_queues_async_;
bool profiler_idle_notifier_started_ = false;
AsyncHooks async_hooks_;
@@ -1433,12 +1436,18 @@ class Environment : public MemoryRetainer {
// 'other' afterwards.
inline void ConcatMove(NativeImmediateQueue&& other);
+ // size() is atomic and may be called from any thread.
+ inline size_t size() const;
+
private:
+ std::atomic<size_t> size_ {0};
std::unique_ptr<NativeImmediateCallback> head_;
NativeImmediateCallback* tail_ = nullptr;
};
NativeImmediateQueue native_immediates_;
+ Mutex native_immediates_threadsafe_mutex_;
+ NativeImmediateQueue native_immediates_threadsafe_;
void RunAndClearNativeImmediates(bool only_refed = false);
static void CheckImmediate(uv_check_t* handle);