diff --git a/src/roctracer/registration_table.h b/src/roctracer/registration_table.h index f9f6efd478..7ead61aed4 100644 --- a/src/roctracer/registration_table.h +++ b/src/roctracer/registration_table.h @@ -54,9 +54,15 @@ struct False { // Generic callbacks table template class RegistrationTable { public: + struct table_element_t { + std::atomic enabled{false}; + mutable std::shared_mutex mutex; + T data; + }; + template void Register(uint32_t operation_id, Args... args) { assert(operation_id < N && "operation_id is out of range"); - auto& entry = table_[operation_id]; + table_element_t& entry = table_.at(operation_id); std::unique_lock lock(entry.mutex); if (!entry.enabled.exchange(true, std::memory_order_relaxed)) registered_count_.fetch_add(1, std::memory_order_relaxed); @@ -65,7 +71,7 @@ template class Regi void Unregister(uint32_t operation_id) { assert(operation_id < N && "id is out of range"); - auto& entry = table_[operation_id]; + table_element_t& entry = table_.at(operation_id); std::unique_lock lock(entry.mutex); if (entry.enabled.exchange(false, std::memory_order_relaxed)) registered_count_.fetch_sub(1, std::memory_order_relaxed); @@ -73,7 +79,7 @@ template class Regi std::optional Get(uint32_t operation_id) const { assert(operation_id < N && "id is out of range"); - auto& entry = table_[operation_id]; + const table_element_t& entry = table_.at(operation_id); if (!entry.enabled.load(std::memory_order_relaxed) || IsStopped{}()) return std::nullopt; std::shared_lock lock(entry.mutex); return entry.enabled.load(std::memory_order_relaxed) ? std::make_optional(entry.data) @@ -84,11 +90,7 @@ template class Regi private: std::atomic registered_count_{0}; - struct { - std::atomic enabled{false}; - mutable std::shared_mutex mutex; - T data; - } table_[N]{}; + std::array table_{}; }; #if IGNORE_GCC_ARRAY_BOUNDS_ERROR