From 1f5cdb1fff53d5c5ce3e963cb0b73c81d0c194d7 Mon Sep 17 00:00:00 2001 From: pavelkumbrasev Date: Fri, 28 Jan 2022 11:34:52 +0300 Subject: [PATCH] Refactoring #4 Signed-off-by: pavelkumbrasev --- src/tbb/arena.h | 4 ++++ src/tbb/market.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tbb/arena.h b/src/tbb/arena.h index 964f449702..9c934ce28b 100644 --- a/src/tbb/arena.h +++ b/src/tbb/arena.h @@ -422,6 +422,10 @@ class arena: public padded return my_num_workers_requested; } + void set_client(permit_manager_client* c) { + my_client = c; + } + unsigned references() { return my_references.load(std::memory_order_acquire); } diff --git a/src/tbb/market.cpp b/src/tbb/market.cpp index 86ced5318c..eac3acd245 100644 --- a/src/tbb/market.cpp +++ b/src/tbb/market.cpp @@ -42,7 +42,7 @@ struct tbb_permit_manager_client : public permit_manager_client, public d1::intr } // arena needs an extra worker despite a global limit - std::atomic m_global_concurrency_mode; + std::atomic m_global_concurrency_mode{false}; //! The index in the array of per priority lists of arenas this object is in. unsigned priority_level() { @@ -72,6 +72,10 @@ struct tbb_permit_manager_client : public permit_manager_client, public d1::intr void set_top_priority(bool b) { return m_is_top_priority.store(b, std::memory_order_relaxed); } + + void bind_with_arena() { + m_arena.set_client(this); + } }; /** This method must be invoked under my_arenas_list_mutex. **/ @@ -361,6 +365,7 @@ arena* market::create_arena ( int num_slots, int num_reserved_slots, unsigned ar market &m = global_market( /*is_public=*/true, num_slots-num_reserved_slots, stack_size ); arena& a = arena::allocate_arena( m, num_slots, num_reserved_slots, arena_priority_level, m.my_arenas_aba_epoch.load(std::memory_order_relaxed) ); tbb_permit_manager_client* c = static_cast(m.create_client(a, nullptr)); + c->bind_with_arena(); // Add newly created arena into the existing market's list. arenas_list_mutex_type::scoped_lock lock(m.my_arenas_list_mutex); m.insert_arena_into_list(*c);