File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 10
10
#include < atomic> // `std::atomic`
11
11
#include < cstddef> // `std::max_align_t`
12
12
#include < cassert> // `assert`
13
+ #include < new> // `std::hardware_destructive_interference_size`
13
14
14
15
#define FORK_UNION_VERSION_MAJOR 0
15
16
#define FORK_UNION_VERSION_MINOR 3
39
40
40
41
namespace ashvardanian {
41
42
43
+ /* *
44
+ * @brief Defines variable alignment to avoid false sharing.
45
+ * @see https://en.cppreference.com/w/cpp/thread/hardware_destructive_interference_size
46
+ */
47
+ #if defined(__cpp_lib_hardware_interference_size)
48
+ static constexpr std::size_t default_alignment_k = std::hardware_destructive_interference_size;
49
+ #else
50
+ static constexpr std::size_t default_alignment_k = alignof (std::max_align_t );
51
+ #endif
52
+
42
53
/* *
43
54
* @brief Minimalistic STL-based non-resizable thread-pool for simultaneous blocking tasks.
44
55
*
@@ -57,7 +68,7 @@ namespace ashvardanian {
57
68
* use the "acquire-release" model, and some going further to "relaxed" model.
58
69
* @see https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering
59
70
*/
60
- template <typename allocator_type_ = std::allocator<std::byte>, std::size_t alignment_ = alignof (std:: max_align_t ) >
71
+ template <typename allocator_type_ = std::allocator<std::byte>, std::size_t alignment_ = default_alignment_k >
61
72
class fork_union {
62
73
public:
63
74
using allocator_t = allocator_type_;
You can’t perform that action at this time.
0 commit comments