Improving the lock free mpmc queue

Making the queue growable
Add padding to avoir false sharing
Add sleep() and SwitchToThread() to limit spinning
This commit is contained in:
2026-03-07 01:40:31 +01:00
parent 86ad30788a
commit 4967591ff8
4 changed files with 83 additions and 17 deletions

View File

@@ -103,16 +103,22 @@ static double timer_stop(HiResTimer *t) {
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;
MPMCSlot *slots;
atomic_size_t committed;
size_t commit_step;
atomic_size_t head;
atomic_size_t tail;
MPMCSlot *slots;
} MPMCQueue;
static MPMCQueue g_file_queue;