diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h b/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h @@ -15,7 +15,7 @@ #define SANITIZER_THREAD_REGISTRY_H #include "sanitizer_common.h" -#include "sanitizer_hashmap.h" +#include "sanitizer_dense_map.h" #include "sanitizer_list.h" #include "sanitizer_mutex.h" @@ -148,7 +148,7 @@ InternalMmapVector threads_; IntrusiveList dead_threads_; IntrusiveList invalid_threads_; - HashMap live_; + DenseMap live_; void QuarantinePush(ThreadContextBase *tctx); ThreadContextBase *QuarantinePop(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cpp @@ -166,7 +166,7 @@ // Ensure that user_id is unique. If it's not the case we are screwed. // Ignoring this situation may lead to very hard to debug false // positives later (e.g. if we join a wrong thread). - CHECK(live_.Insert(user_id, tid)); + CHECK(live_.insert({user_id, tid}).second); } tctx->SetCreated(user_id, total_threads_++, detached, parent_tid, arg); @@ -227,9 +227,8 @@ void ThreadRegistry::SetThreadNameByUserId(uptr user_id, const char *name) { ThreadRegistryLock l(this); - u32 tid; - if (live_.Find(user_id, &tid)) - threads_[tid]->SetName(name); + if (const auto *tid = live_.find(user_id)) + threads_[tid->second]->SetName(name); } void ThreadRegistry::DetachThread(u32 tid, void *arg) { @@ -243,7 +242,7 @@ tctx->OnDetached(arg); if (tctx->status == ThreadStatusFinished) { if (tctx->user_id) - live_.Remove(tctx->user_id); + live_.erase(tctx->user_id); tctx->SetDead(); QuarantinePush(tctx); } else { @@ -264,7 +263,7 @@ } if ((destroyed = tctx->GetDestroyed())) { if (tctx->user_id) - live_.Remove(tctx->user_id); + live_.erase(tctx->user_id); tctx->SetJoined(arg); QuarantinePush(tctx); } @@ -298,7 +297,7 @@ tctx->SetFinished(); if (dead) { if (tctx->user_id) - live_.Remove(tctx->user_id); + live_.erase(tctx->user_id); tctx->SetDead(); QuarantinePush(tctx); } @@ -343,7 +342,10 @@ u32 ThreadRegistry::ConsumeThreadUserId(uptr user_id) { ThreadRegistryLock l(this); u32 tid; - CHECK(live_.Remove(user_id, &tid)); + auto *t = live_.find(user_id); + CHECK(t); + tid = t->second; + live_.erase(t); auto *tctx = threads_[tid]; CHECK_EQ(tctx->user_id, user_id); tctx->user_id = 0; @@ -358,7 +360,7 @@ CHECK_NE(tctx->status, ThreadStatusDead); CHECK_EQ(tctx->user_id, 0); tctx->user_id = user_id; - CHECK(live_.Insert(user_id, tctx->tid)); + CHECK(live_.insert({user_id, tctx->tid}).second); } } // namespace __sanitizer