Skip to content

Commit aafb224

Browse files
addaleaxMylesBorins
authored andcommitted
src: exclude C++ SetImmediate() from count
There is no real reason to manage a count manually, given that checking whether there are C++ callbacks is a single pointer comparison. This makes it easier to add other kinds of native C++ callbacks that are managed in a similar way. Backport-PR-URL: #32301 PR-URL: #31386 Refs: openjs-foundation/summit#240 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 5df9698 commit aafb224

File tree

3 files changed

+4
-19
lines changed

3 files changed

+4
-19
lines changed

src/env-inl.h

-9
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,6 @@ inline bool ImmediateInfo::has_outstanding() const {
242242
return fields_[kHasOutstanding] == 1;
243243
}
244244

245-
inline void ImmediateInfo::count_inc(uint32_t increment) {
246-
fields_[kCount] += increment;
247-
}
248-
249-
inline void ImmediateInfo::count_dec(uint32_t decrement) {
250-
fields_[kCount] -= decrement;
251-
}
252-
253245
inline void ImmediateInfo::ref_count_inc(uint32_t increment) {
254246
fields_[kRefCount] += increment;
255247
}
@@ -771,7 +763,6 @@ void Environment::CreateImmediate(Fn&& cb, bool ref) {
771763
auto callback = std::make_unique<NativeImmediateCallbackImpl<Fn>>(
772764
std::move(cb), ref);
773765
native_immediates_.Push(std::move(callback));
774-
immediate_info()->count_inc(1);
775766
}
776767

777768
template <typename Fn>

src/env.cc

+4-8
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,6 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
664664
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
665665
"RunAndClearNativeImmediates", this);
666666
size_t ref_count = 0;
667-
size_t count = 0;
668667

669668
NativeImmediateQueue queue;
670669
queue.ConcatMove(std::move(native_immediates_));
@@ -673,7 +672,6 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
673672
TryCatchScope try_catch(this);
674673
DebugSealHandleScope seal_handle_scope(isolate());
675674
while (std::unique_ptr<NativeImmediateCallback> head = queue.Shift()) {
676-
count++;
677675
if (head->is_refed())
678676
ref_count++;
679677

@@ -691,9 +689,10 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
691689
};
692690
while (queue.size() > 0 && drain_list()) {}
693691

694-
DCHECK_GE(immediate_info()->count(), count);
695-
immediate_info()->count_dec(count);
696692
immediate_info()->ref_count_dec(ref_count);
693+
694+
if (immediate_info()->ref_count() == 0)
695+
ToggleImmediateRef(false);
697696
}
698697

699698

@@ -779,15 +778,12 @@ void Environment::CheckImmediate(uv_check_t* handle) {
779778
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
780779
"CheckImmediate", env);
781780

782-
if (env->immediate_info()->count() == 0)
783-
return;
784-
785781
HandleScope scope(env->isolate());
786782
Context::Scope context_scope(env->context());
787783

788784
env->RunAndClearNativeImmediates();
789785

790-
if (!env->can_call_into_js())
786+
if (env->immediate_info()->count() == 0 || !env->can_call_into_js())
791787
return;
792788

793789
do {

src/env.h

-2
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,6 @@ class ImmediateInfo : public MemoryRetainer {
734734
inline uint32_t count() const;
735735
inline uint32_t ref_count() const;
736736
inline bool has_outstanding() const;
737-
inline void count_inc(uint32_t increment);
738-
inline void count_dec(uint32_t decrement);
739737
inline void ref_count_inc(uint32_t increment);
740738
inline void ref_count_dec(uint32_t decrement);
741739

0 commit comments

Comments
 (0)