mirror of
https://github.com/anrieff/libcpuid
synced 2025-07-02 14:04:15 +00:00
parent
e8d31149a8
commit
3b0a1f7e5b
1 changed files with 4 additions and 0 deletions
|
@ -177,6 +177,10 @@ static bool set_cpu_affinity(logical_cpu_t logical_cpu)
|
||||||
{
|
{
|
||||||
thread_affinity_policy_data_t ap;
|
thread_affinity_policy_data_t ap;
|
||||||
ap.affinity_tag = logical_cpu + 1;
|
ap.affinity_tag = logical_cpu + 1;
|
||||||
|
/* Note: thread_policy_set() always returns KERN_SUCCESS even if the target logical CPU does not exist
|
||||||
|
Refer to #178 */
|
||||||
|
if (logical_cpu >= get_total_cpus())
|
||||||
|
return false;
|
||||||
return thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY, (thread_policy_t) &ap, THREAD_AFFINITY_POLICY_COUNT) == KERN_SUCCESS;
|
return thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY, (thread_policy_t) &ap, THREAD_AFFINITY_POLICY_COUNT) == KERN_SUCCESS;
|
||||||
}
|
}
|
||||||
#define SET_CPU_AFFINITY
|
#define SET_CPU_AFFINITY
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue