[tsan] Only init AdaptiveDelay if enabled (#181757)

In #178836, while refactoring from a virtual class design to a
non-virtual design, the logic ended up such that AdaptiveDelayImpl was
always constructed, even if the adaptive delay feature was not enabled.
Adaptive delay itself was always disabled if the flag was off, this just
prevents the ctor from running at all.

@dvyukov
This commit is contained in:
Chris Cotter 2026-02-17 01:57:38 -05:00 committed by GitHub
parent fb41009de5
commit f978a7d023
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -260,11 +260,7 @@ struct AdaptiveDelayImpl {
DelaySpec atomic_delay_;
DelaySpec sync_delay_;
void Init() {
InitTls();
AdaptiveDelay::is_adaptive_delay_enabled = flags()->enable_adaptive_delay;
}
void Init() { InitTls(); }
void InitTls() {
TLS()->bucket_start_ns_ = NanoTime();
@ -414,7 +410,13 @@ AdaptiveDelayImpl& GetImpl() {
bool AdaptiveDelay::is_adaptive_delay_enabled;
void AdaptiveDelay::InitImpl() { GetImpl().Init(); }
void AdaptiveDelay::InitImpl() {
AdaptiveDelay::is_adaptive_delay_enabled = flags()->enable_adaptive_delay;
if (!AdaptiveDelay::is_adaptive_delay_enabled)
return;
GetImpl().Init();
}
void AdaptiveDelay::SyncOpImpl() { GetImpl().SyncOp(); }
void AdaptiveDelay::AtomicOpFenceImpl(int mo) { GetImpl().AtomicOpFence(mo); }

View File

@ -82,8 +82,6 @@ struct AdaptiveDelay {
static void BeforeChildThreadRunsImpl();
static bool is_adaptive_delay_enabled;
friend struct AdaptiveDelayImpl;
};
// The runtime defines cur_thread() to retrieve TLS thread state, and it