[TESTED] patched for basic tests, moved fan-out buffer to the stack, all basic tests are runnable

This commit is contained in:
2026-01-04 13:21:17 -05:00
parent 103903be8e
commit dd3d6be073
3 changed files with 303 additions and 9 deletions

View File

@@ -9,7 +9,6 @@
#include <limits>
#include <new>
#include <utility>
#include <vector>
namespace THWeaver {
@@ -147,7 +146,7 @@ public:
FanInFabric &operator=(FanInFabric &&) = delete;
void init() noexcept {
for (int i = 0; i < IN_THREAD_CNT; ++i)
for (std::size_t i = 0; i < IN_THREAD_CNT; ++i)
in_queues[i].init();
hint.store(0);
dl.init();
@@ -336,7 +335,7 @@ private:
uint8_t first;
uint8_t last;
void init() noexcept {
for (int i = 0; i < IN_THREAD_CNT; ++i) {
for (std::size_t i = 0; i < IN_THREAD_CNT; ++i) {
next[i] = (i + 1) % IN_THREAD_CNT;
prev[i] =
(i + IN_THREAD_CNT - 1) % IN_THREAD_CNT;
@@ -385,6 +384,7 @@ template <typename MessageType, std::size_t consumer_qsize_expt,
std::size_t BUFFER_SIZE, std::size_t reclaim_qsize_expt,
std::size_t OUT_THREAD_CNT>
class FanOutFabric {
public:
using BitmapType = uint64_t;
using RefCountType = uint32_t;
using IndexType = uint16_t;
@@ -462,12 +462,11 @@ class FanOutFabric {
};
void init() noexcept {
for (int i = 0; i < OUT_THREAD_CNT; ++i) {
for (std::size_t i = 0; i < OUT_THREAD_CNT; ++i) {
reclaim_queues[i].init();
consumer_queues[i].init();
}
reclaim_hint.store(0, std::memory_order_release);
buffer.resize(BUFFER_SIZE);
fs.init();
reclaim_rot = 0;
}
@@ -539,7 +538,7 @@ class FanOutFabric {
for (std::size_t i = 0; i < OUT_THREAD_CNT; ++i) {
if ((policy & (BitmapType(1) << i)) &&
consumer_queues[i].send(slot) !=
consumer_queues[i].send(std::move(slot)) !=
EndpointQueueSendResult::Ok)
++failed_cnt;
else
@@ -655,7 +654,7 @@ class FanOutFabric {
static_assert(thread_id < OUT_THREAD_CNT,
"Thread ID out of bounds");
auto res = reclaim_queues[thread_id].send(slot);
auto res = reclaim_queues[thread_id].send(std::move(slot));
if (res == EndpointQueueSendResult::Ok) {
reclaim_hint.fetch_or(BitmapType(1) << thread_id,
std::memory_order_relaxed);
@@ -676,12 +675,12 @@ private:
std::atomic<RefCountType> count;
MessageType payload;
};
std::vector<BufferSlot> buffer;
std::array<BufferSlot, BUFFER_SIZE> buffer;
struct alignas(CLS) FreeStack {
std::array<IndexType, BUFFER_SIZE> free;
int top;
void init() {
for (int i = 0; i < BUFFER_SIZE; ++i)
for (std::size_t i = 0; i < BUFFER_SIZE; ++i)
free[i] = i;
top = BUFFER_SIZE;
}