Skip to content

Commit

Permalink
Refs #19436. Add MacOS implementation for setting thread affinity.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Sep 26, 2023
1 parent 1248c67 commit ce02d36
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/cpp/utils/threading/threading_osx.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,19 @@ static void configure_current_thread_scheduler(
}
}

static void configure_current_thread_affinity(
uint32_t affinity_mask)
{
thread_affinity_policy_data_t policy = { m_affinityMask };
pthread_t self_tid = pthread_self();
thread_policy_set(pthread_mach_thread_np(self_tid), THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1);
}

void apply_thread_settings_to_current_thread(
const fastdds::rtps::ThreadSettings& settings)
{
configure_current_thread_scheduler(settings.scheduling_policy, settings.priority);
configure_current_thread_affinity(settings.cpu_mask);
}

} // namespace eprosima

0 comments on commit ce02d36

Please sign in to comment.