Skip to content

Commit

Permalink
Refactoring #4
Browse files Browse the repository at this point in the history
Signed-off-by: pavelkumbrasev <[email protected]>
  • Loading branch information
pavelkumbrasev committed Jan 31, 2023
1 parent b33fae0 commit 1f5cdb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/tbb/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ class arena: public padded<arena_base>
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);
}
Expand Down
7 changes: 6 additions & 1 deletion src/tbb/market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> m_global_concurrency_mode;
std::atomic<bool> m_global_concurrency_mode{false};

//! The index in the array of per priority lists of arenas this object is in.
unsigned priority_level() {
Expand Down Expand Up @@ -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. **/
Expand Down Expand Up @@ -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<tbb_permit_manager_client*>(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);
Expand Down

0 comments on commit 1f5cdb1

Please sign in to comment.