xenium
hardware.hpp
1 //
2 // Copyright (c) 2018-2020 Manuel Pöter.
3 // Licensed under the MIT License. See LICENSE file in the project root for full license information.
4 //
5 
6 #ifndef XENIUM_DETAILS_HARDWARE_HPP
7 #define XENIUM_DETAILS_HARDWARE_HPP
8 
9 #include <xenium/detail/port.hpp>
10 
11 #if defined(XENIUM_ARCH_X86)
12  #include <emmintrin.h>
13 #elif defined(XENIUM_ARCH_SPARC)
14  #include <synch.h>
15 #endif
16 
17 namespace xenium::detail {
18 inline void hardware_pause() {
19  // TODO - add pause implementations for ARM + Power
20 #if defined(XENIUM_ARCH_X86)
21  _mm_pause();
22 #elif defined(XENIUM_ARCH_SPARC)
23  smt_pause();
24 #else
25  #warning "No hardware_pause implementation available - falling back to local volatile noop."
26  // this effectively prevents the compiler from optimizing away the whole backoff operation
27  volatile int x = 0;
28  (void)x;
29 #endif
30 }
31 } // namespace xenium::detail
32 #endif