Fix buggy behavior of pthread_setaffinity_np/pthread_getaffinity_np on NetBSD.

This commit is contained in:
levlam 2022-09-17 23:25:42 +03:00
parent e37f3c17af
commit cb70993b90

View File

@ -144,6 +144,9 @@ Status ThreadPthread::set_affinity_mask(id thread_id, uint64 mask) {
if (res) {
return OS_ERROR("Failed to set thread affinity mask");
}
if (get_affinity_mask(thread_id) != mask) {
return Status::Error("Failed to set exact thread affinity mask");
}
return Status::OK();
#else
return Status::Error("Unsupported");
@ -189,6 +192,13 @@ uint64 ThreadPthread::get_affinity_mask(id thread_id) {
mask |= static_cast<uint64>(1) << j;
}
}
if (mask == 0) {
// the mask wasn't set, all CPUs are allowed
auto proc_count = sysconf(_SC_NPROCESSORS_ONLN);
for (int j = 0; j < 64 && j < proc_count; j++) {
mask |= static_cast<uint64>(1) << j;
}
}
return mask;
#else
return 0;