diff --git a/include/realtime_tools/realtime_helpers.hpp b/include/realtime_tools/realtime_helpers.hpp index b0790924..2bcea158 100644 --- a/include/realtime_tools/realtime_helpers.hpp +++ b/include/realtime_tools/realtime_helpers.hpp @@ -31,6 +31,7 @@ #include #include +#include #include namespace realtime_tools diff --git a/src/realtime_helpers.cpp b/src/realtime_helpers.cpp index 866acc34..8359710d 100644 --- a/src/realtime_helpers.cpp +++ b/src/realtime_helpers.cpp @@ -115,13 +115,16 @@ bool lock_memory(std::string & message) #endif } -std::pair set_thread_affinity(pthread_t thread, int core) -{ - std::string message; #ifdef _WIN32 - message = "Thread affinity is not supported on Windows."; +std::pair set_thread_affinity(HANDLE thread, int core) +{ + std::string message = "Thread affinity is not supported on Windows."; return std::make_pair(false, message); +} #else +std::pair set_thread_affinity(pthread_t thread, int core) +{ + std::string message; auto set_affinity_result_message = [](int result, std::string & msg) -> bool { if (result == 0) { msg = "Thread affinity set successfully!"; @@ -176,8 +179,8 @@ std::pair set_thread_affinity(pthread_t thread, int core) " cores. Parsed core number should be between 0 and " + std::to_string(number_of_cores - 1); return std::make_pair(false, message); -#endif } +#endif std::pair set_thread_affinity(std::thread & thread, int core) { @@ -190,7 +193,11 @@ std::pair set_thread_affinity(std::thread & thread, int core) std::pair set_current_thread_affinity(int core) { +#ifdef _WIN32 + return set_thread_affinity(GetCurrentThread(), core); +#else return set_thread_affinity(pthread_self(), core); +#endif } int64_t get_number_of_available_processors()