Making the LF MPMC queue generic and isolating it's code in a separate header file

This commit is contained in:
2026-03-09 01:14:24 +01:00
parent 75c2592bfe
commit b2f444af00
3 changed files with 204 additions and 190 deletions

View File

@@ -3,6 +3,7 @@
#include "arena.h"
#include "base.h"
#include "lf_mpmc.h"
#include "arena.c"
// ----------------------------- Config -------------------------------------
@@ -44,32 +45,7 @@ static double timer_stop(HiResTimer *t) {
(double)g_qpc_freq.QuadPart;
}
// ============================================================
// Simple lock free MPMC Queue
// ============================================================
typedef struct {
atomic_size_t seq;
FileEntry *data;
char pad[64 - sizeof(atomic_size_t) - sizeof(FileEntry *)];
} MPMCSlot;
typedef struct {
atomic_size_t head;
char pad1[64];
atomic_size_t tail;
char pad2[64];
size_t capacity;
size_t mask;
atomic_size_t committed;
size_t commit_step;
atomic_flag commit_lock;
MPMCSlot *slots;
} MPMCQueue;
// MPMC Queue
static MPMCQueue g_file_queue;
typedef struct {