MCPcopy Create free account
hub / github.com/Niko1221/Strata / pin_current_thread

Function pin_current_thread

engine/src/kernels/cpu/pool.cpp:730–754  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

728} // namespace
729
730ThreadAffinity pin_current_thread(int core) {
731 if (core < 0) return {};
732#if defined(_WIN32)
733 ThreadAffinity previous;
734 ULONG target = 0;
735 if (!detail::get_thread_cpu_sets(previous.cpu_sets) || !detail::cpu_set_for_core(core, target) ||
736 !SetThreadSelectedCpuSets(GetCurrentThread(), &target, 1)) {
737 std::fprintf(stderr, "strata cpu pool: host CPU Set selection for processor %d failed: %lu; previous placement kept\n",
738 core, (unsigned long) GetLastError());
739 return {};
740 }
741 previous.valid = true;
742 return previous;
743#else
744 ThreadAffinity previous;
745 int error = detail::get_thread_affinity(previous.mask);
746 if (error == 0) error = detail::pin_thread_to_cpu(core);
747 if (error != 0) {
748 std::fprintf(stderr, "strata cpu pool: host affinity for CPU %d failed: %d; previous affinity kept\n", core, error);
749 return {};
750 }
751 previous.valid = true;
752 return previous;
753#endif
754}
755
756void restore_thread_affinity(const ThreadAffinity& previous) {
757 if (!previous.valid) return;

Callers 15

round_trip_full_maskFunction · 0.70
round_trip_sparse_nestedFunction · 0.70
round_trip_high_cpuFunction · 0.70
negative_cpu_is_noopFunction · 0.70
host_round_tripsFunction · 0.70
inherited_defaultFunction · 0.70
mainFunction · 0.70
initMethod · 0.50
loopMethod · 0.50
startMethod · 0.50

Calls 4

get_thread_cpu_setsFunction · 0.70
cpu_set_for_coreFunction · 0.70
get_thread_affinityFunction · 0.70
pin_thread_to_cpuFunction · 0.70

Tested by 9

round_trip_full_maskFunction · 0.56
round_trip_sparse_nestedFunction · 0.56
round_trip_high_cpuFunction · 0.56
negative_cpu_is_noopFunction · 0.56
host_round_tripsFunction · 0.56
inherited_defaultFunction · 0.56
mainFunction · 0.56
test_liveFunction · 0.40