diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-12-17 00:03:50 +0300 |
---|---|---|
committer | Shelley Vohr <shelley.vohr@gmail.com> | 2020-02-17 21:53:51 +0300 |
commit | 53e566bc50a8624394ff255059f4b6b2b3305068 (patch) | |
tree | 632397dd2811999eec4f8e873010d2cd40a153b6 /src/env.cc | |
parent | 7ecf8424298df11232b5cdfc19f70379c77256ec (diff) |
src: better encapsulate native immediate list
Refactor for clarity and reusability. Make it more obvious that the
list is a FIFO queue.
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.cc')
-rw-r--r-- | src/env.cc | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/env.cc b/src/env.cc index 8ed6150c720..a4defc2528c 100644 --- a/src/env.cc +++ b/src/env.cc @@ -666,14 +666,14 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) { "RunAndClearNativeImmediates", this); size_t ref_count = 0; size_t count = 0; - std::unique_ptr<NativeImmediateCallback> head; - head.swap(native_immediate_callbacks_head_); - native_immediate_callbacks_tail_ = nullptr; + + NativeImmediateQueue queue; + queue.ConcatMove(std::move(native_immediates_)); auto drain_list = [&]() { TryCatchScope try_catch(this); - for (; head; head = head->get_next()) { - DebugSealHandleScope seal_handle_scope(isolate()); + DebugSealHandleScope seal_handle_scope(isolate()); + while (std::unique_ptr<NativeImmediateCallback> head = queue.Shift()) { count++; if (head->is_refed()) ref_count++; @@ -685,15 +685,12 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) { if (!try_catch.HasTerminated() && can_call_into_js()) errors::TriggerUncaughtException(isolate(), try_catch); - // We are done with the current callback. Move one iteration along, - // as if we had completed successfully. - head = head->get_next(); return true; } } return false; }; - while (head && drain_list()) {} + while (queue.size() > 0 && drain_list()) {} DCHECK_GE(immediate_info()->count(), count); immediate_info()->count_dec(count); |