Skip to content

Commit 74a7cdb

Browse files
addaleaxcodebytere
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. 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 53e566b commit 74a7cdb

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
}
@@ -784,7 +776,6 @@ void Environment::CreateImmediate(Fn&& cb, bool ref) {
784776
auto callback = std::make_unique<NativeImmediateCallbackImpl<Fn>>(
785777
std::move(cb), ref);
786778
native_immediates_.Push(std::move(callback));
787-
immediate_info()->count_inc(1);
788779
}
789780

790781
template <typename Fn>

src/env.cc

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

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

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

695-
DCHECK_GE(immediate_info()->count(), count);
696-
immediate_info()->count_dec(count);
697693
immediate_info()->ref_count_dec(ref_count);
694+
695+
if (immediate_info()->ref_count() == 0)
696+
ToggleImmediateRef(false);
698697
}
699698

700699

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

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

789785
env->RunAndClearNativeImmediates();
790786

791-
if (!env->can_call_into_js())
787+
if (env->immediate_info()->count() == 0 || !env->can_call_into_js())
792788
return;
793789

794790
do {

src/env.h

-2
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,6 @@ class ImmediateInfo : public MemoryRetainer {
736736
inline uint32_t count() const;
737737
inline uint32_t ref_count() const;
738738
inline bool has_outstanding() const;
739-
inline void count_inc(uint32_t increment);
740-
inline void count_dec(uint32_t decrement);
741739
inline void ref_count_inc(uint32_t increment);
742740
inline void ref_count_dec(uint32_t decrement);
743741

0 commit comments

Comments
 (0)