fairness  v1.0.0
A collection of advanced syncronization mechanisms.
Loading...
Searching...
No Matches
wait_pool.hpp
Go to the documentation of this file.
1
14/*
15The meaning of this is the following:
16The standard lib implementators in all implementations I have seen uses an array of 128 bytes memory regions to avoid false sharing,
17then they translate an address (ADDR >> 2 % 16) to an index to the array to determine where to perform the syscall wait.
18So given the implementation I say: if we use the std lib implementation then there is no need to 128 byte aligned waiting flags
19if the user instead decide to use my customizable wait implementation then we must use waitingFlag which avoid false sharing.
20*/
21
22#ifndef BOOST_FAIRNESS_WAIT_POOL_HPP
23#define BOOST_FAIRNESS_WAIT_POOL_HPP
24
25#include <atomic>
26#include <array>
28
30
31 static constexpr uint32_t wait_flag = 0;
32 static constexpr uint32_t proceed_flag = 1;
33
35 alignas(BOOST_FAIRNESS_HARDWARE_DESTRUCTIVE_SIZE) std::atomic<uint32_t> waitMem{};
36 //char padding_[BOOST_FAIRNESS_HARDWARE_DESTRUCTIVE_SIZE - sizeof(waitMem)];
37
38 inline void store(uint32_t const waitStatus){
39 waitMem.store(waitStatus);
40 }
41
42 };
43
44 template <size_t N>
45 class WaitPool {
46 public:
47 WaitPool() = default;
48
49 std::atomic<uint32_t>& operator[](size_t n) {
50#ifdef BOOST_FAIRNESS_USE_STD_WAIT_NOTIFY
51 return waitMems_[n];
52#else
53 return waitMems_[n].waitMem;
54#endif
55 }
56
57 inline void reset_(Priority_t p){
58 for (Priority_t i = 0; i < N; ++i)
59 waitMems_[i].store(wait_flag);
60 waitMems_[p].store(proceed_flag);
61 }
62
63 private:
64#ifdef BOOST_FAIRNESS_USE_STD_WAIT_NOTIFY
65 std::array<std::atomic<uint32_t>, N> waitMems_{};
66#else
67 std::array<waitingFlag, N> waitMems_{};
68#endif
69 };
70
71}
72#endif // BOOST_FAIRNESS_WAIT_POOL_HPP
Definition wait_pool.hpp:45
std::atomic< uint32_t > & operator[](size_t n)
Definition wait_pool.hpp:49
void reset_(Priority_t p)
Definition wait_pool.hpp:57
This file contains configurations about boost and 128bit cpu support. TODO.
#define BOOST_FAIRNESS_HARDWARE_DESTRUCTIVE_SIZE
Size to be aligned to avoid false sharing
Definition config.hpp:85
Definition coherent_priority_lock.hpp:25
uint8_t Priority_t
Definition priority_t.hpp:17
Definition wait_pool.hpp:34
void store(uint32_t const waitStatus)
Definition wait_pool.hpp:38
std::atomic< uint32_t > waitMem
Definition wait_pool.hpp:35