diff options
author | fireice-uk <fireice-uk@users.noreply.github.com> | 2017-10-11 23:53:31 +0100 |
---|---|---|
committer | fireice-uk <fireice-uk@users.noreply.github.com> | 2017-10-11 23:53:31 +0100 |
commit | c897fc04518b2701c7ec556a183406bae0760028 (patch) | |
tree | 3ec79c98586cc676c5e88d83b296489a4a534622 | |
parent | b40f937bf592f3fb303ce51fc073ab6ee9f922d0 (diff) | |
download | xmr-stak-c897fc04518b2701c7ec556a183406bae0760028.zip xmr-stak-c897fc04518b2701c7ec556a183406bae0760028.tar.gz |
cleanup and give a return from set_affinity
-rw-r--r-- | xmrstak/backend/cpu/minethd.cpp | 41 | ||||
-rw-r--r-- | xmrstak/backend/cpu/minethd.hpp | 2 |
2 files changed, 11 insertions, 32 deletions
diff --git a/xmrstak/backend/cpu/minethd.cpp b/xmrstak/backend/cpu/minethd.cpp index 8a65a3b..1267a70 100644 --- a/xmrstak/backend/cpu/minethd.cpp +++ b/xmrstak/backend/cpu/minethd.cpp @@ -50,22 +50,8 @@ #include <thread> #include <bitset> - #ifdef _WIN32 #include <windows.h> - -namespace xmrstak -{ -namespace cpu -{ -void minethd::thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id) -{ - SetThreadAffinityMask(h, 1ULL << cpu_id); -} - -} // namespace cpu -} // namespace xmrstak - #else #include <pthread.h> @@ -75,44 +61,37 @@ void minethd::thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id #define SYSCTL_CORE_COUNT "machdep.cpu.core_count" #elif defined(__FreeBSD__) #include <pthread_np.h> -#endif +#endif //__APPLE__ + +#endif //_WIN32 namespace xmrstak { namespace cpu { -void minethd::thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id) +bool minethd::thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id) { -#if defined(__APPLE__) +#if defined(_WIN32) + return SetThreadAffinityMask(h, 1ULL << cpu_id) != 0; +#elif defined(__APPLE__) thread_port_t mach_thread; thread_affinity_policy_data_t policy = { static_cast<integer_t>(cpu_id) }; mach_thread = pthread_mach_thread_np(h); - thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1); + return thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1) == KERN_SUCCESS; #elif defined(__FreeBSD__) cpuset_t mn; CPU_ZERO(&mn); CPU_SET(cpu_id, &mn); - pthread_setaffinity_np(h, sizeof(cpuset_t), &mn); + return pthread_setaffinity_np(h, sizeof(cpuset_t), &mn) == 0; #else cpu_set_t mn; CPU_ZERO(&mn); CPU_SET(cpu_id, &mn); - pthread_setaffinity_np(h, sizeof(cpu_set_t), &mn); + return pthread_setaffinity_np(h, sizeof(cpu_set_t), &mn) == 0; #endif } -} // namespace cpu -} // namespace xmrstak - -#endif // _WIN32 - - -namespace xmrstak -{ -namespace cpu -{ - minethd::minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch, int64_t affinity) { oWork = pWork; diff --git a/xmrstak/backend/cpu/minethd.hpp b/xmrstak/backend/cpu/minethd.hpp index 58d378e..584fb0d 100644 --- a/xmrstak/backend/cpu/minethd.hpp +++ b/xmrstak/backend/cpu/minethd.hpp @@ -24,7 +24,7 @@ public: typedef void (*cn_hash_fun)(const void*, size_t, void*, cryptonight_ctx*); static cn_hash_fun func_selector(bool bHaveAes, bool bNoPrefetch); - static void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id); + static bool thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id); static cryptonight_ctx* minethd_alloc_ctx(); |