Program Listing for File cpu_utils.hpp¶
↰ Return to documentation for file (include/ripple/arch/cpu_utils.hpp
)
#ifndef RIPPLE_ARCH_CPU_UTILS_HPP
#define RIPPLE_ARCH_CPU_UTILS_HPP
#include <ripple/utility/portability.hpp>
#include <cstdint>
#if defined(__linux__)
#include <sched.h>
#if defined(__CPU_ISSET)
#define ripple_cpu_set __CPU_SET
#define ripple_cpu_zero __CPU_ZERO
#define ripple_cpu_is_set __CPU_ISSET
#else
#define ripple_cpu_set CPU_SET
#define ripple_cpu_zero CPU_ZERO
#define ripple_cpu_is_set CPU_ISSET
#endif // __CPU_ISSET
#endif // __linux__
namespace ripple {
inline auto set_affinity(uint32_t thread_id) noexcept -> bool {
#if defined(__linux__)
cpu_set_t current_thread;
ripple_cpu_zero(¤t_thread);
ripple_cpu_set(thread_id, ¤t_thread);
if (!sched_setaffinity(0, sizeof(current_thread), ¤t_thread)) {
return true;
}
#endif // __linux__
return false;
}
} // namespace ripple
#endif // RIPPLE_ARCH_CPU_UTILS_HPP