• Docs >
  • Program Listing for File cpu_utils.hpp
Shortcuts

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(&current_thread);
  ripple_cpu_set(thread_id, &current_thread);
  if (!sched_setaffinity(0, sizeof(current_thread), &current_thread)) {
    return true;
  }
#endif // __linux__
  return false;
}

} // namespace ripple

#endif // RIPPLE_ARCH_CPU_UTILS_HPP

Docs

Access comprehensive developer documentation for Ripple

View Docs

Tutorials

Get tutorials to help with understand all features

View Tutorials

Examples

Find examples to help get started

View Examples