7
7
#include < random>
8
8
#include < new>
9
9
#include < optional>
10
+ #include < ostream>
10
11
11
12
#include " atomic_bitset.h"
12
13
13
- #include < iostream>
14
-
15
14
#define LOG_WINDOW_MOVE 0
16
15
17
- constexpr size_t CACHE_SIZE =
18
- #if __cpp_lib_hardware_interference_size >= 201603
19
- std::hardware_constructive_interference_size;
20
- #else
21
- 64 ;
22
- #endif // __cpp_lib_hardware_interference_size
16
+ #if LOG_WINDOW_MOVE
17
+ #include < iostream>
18
+ #endif
23
19
24
- template <typename T, size_t BLOCKS_PER_WINDOW_RAW = 8 , size_t CELLS_PER_BLOCK = CACHE_SIZE / sizeof (T) - 1 , typename BITSET_TYPE = uint8_t >
20
+ template <typename T, size_t BLOCKS_PER_WINDOW_RAW = 1 , size_t CELLS_PER_BLOCK = 7 , typename BITSET_TYPE = uint8_t >
25
21
class relaxed_fifo {
26
22
private:
27
23
static constexpr size_t make_po2 (size_t size) {
@@ -45,7 +41,7 @@ class relaxed_fifo {
45
41
static_assert (sizeof (T) == 8);
46
42
static_assert (sizeof (std::atomic<T>) == 8);
47
43
48
- struct alignas ( 8 ) header_t {
44
+ struct header_t {
49
45
// 16 bits epoch, 16 bits read started index, 16 bits read finished index, 16 bits write index
50
46
std::atomic_uint64_t epoch_and_indices;
51
47
};
@@ -65,8 +61,8 @@ class relaxed_fifo {
65
61
static_assert (sizeof (block_t ) == CELLS_PER_BLOCK * sizeof(T) + sizeof(header_t ));
66
62
67
63
struct window_t {
68
- alignas (128 ) atomic_bitset<BLOCKS_PER_WINDOW, BITSET_TYPE> filled_set;
69
- alignas (128 ) block_t blocks[BLOCKS_PER_WINDOW];
64
+ alignas (std::hardware_destructive_interference_size ) atomic_bitset<BLOCKS_PER_WINDOW, BITSET_TYPE> filled_set;
65
+ alignas (std::hardware_destructive_interference_size ) block_t blocks[BLOCKS_PER_WINDOW];
70
66
};
71
67
72
68
std::unique_ptr<window_t []> buffer;
@@ -75,8 +71,8 @@ class relaxed_fifo {
75
71
return buffer[index & window_count_mod_mask];
76
72
}
77
73
78
- alignas (128 ) std::atomic_uint64_t read_window;
79
- alignas (128 ) std::atomic_uint64_t write_window;
74
+ alignas (std::hardware_destructive_interference_size ) std::atomic_uint64_t read_window;
75
+ alignas (std::hardware_destructive_interference_size ) std::atomic_uint64_t write_window;
80
76
81
77
public:
82
78
// TODO: Remove unused parameter!!
@@ -98,16 +94,17 @@ class relaxed_fifo {
98
94
}
99
95
}
100
96
101
- void debug_print () {
102
- std::cout << " Printing relaxed_fifo:\n "
97
+ std::ostream& operator <<(std::ostream& os) const {
98
+ os << " Printing relaxed_fifo:\n "
103
99
<< " Read: " << read_window << " ; Write: " << write_window << ' \n ' ;
104
100
for (size_t i = 0 ; i < window_count; i++) {
105
101
for (size_t j = 0 ; j < BLOCKS_PER_WINDOW; j++) {
106
102
uint64_t val = buffer[i].blocks [j].header .epoch_and_indices ;
107
- std::cout << (val >> 48 ) << " " << ((val >> 32 ) & 0xffff ) << " " << ((val >> 16 ) & 0xffff ) << " " << (val & 0xffff ) << " | " ;
103
+ os << (val >> 48 ) << " " << ((val >> 32 ) & 0xffff ) << " " << ((val >> 16 ) & 0xffff ) << " " << (val & 0xffff ) << " | " ;
108
104
}
109
- std::cout << " \n ======================\n " ;
105
+ os << " \n ======================\n " ;
110
106
}
107
+ return os;
111
108
}
112
109
113
110
class handle {
0 commit comments