1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2025-07-02 14:04:15 +00:00

Fix infinite loop in set_cpu_affinity() on macOS

Fix #178
This commit is contained in:
The Tumultuous Unicorn Of Darkness 2023-01-01 14:20:44 +01:00
parent e8d31149a8
commit 3b0a1f7e5b
No known key found for this signature in database
GPG key ID: 1E55EE2EFF18BC1A

View file

@ -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