Implementing lock free MPMC queue
This commit is contained in:
18
platform.h
18
platform.h
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <immintrin.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -100,19 +101,18 @@ static double timer_stop(HiResTimer *t) {
|
||||
// ============================================================
|
||||
|
||||
typedef struct {
|
||||
FileEntry **items;
|
||||
atomic_size_t seq;
|
||||
FileEntry *data;
|
||||
} MPMCSlot;
|
||||
|
||||
typedef struct {
|
||||
size_t capacity;
|
||||
size_t head;
|
||||
size_t tail;
|
||||
size_t count;
|
||||
size_t mask;
|
||||
|
||||
int producers_active;
|
||||
|
||||
CRITICAL_SECTION cs;
|
||||
CONDITION_VARIABLE not_empty;
|
||||
CONDITION_VARIABLE not_full;
|
||||
MPMCSlot *slots;
|
||||
|
||||
atomic_size_t head;
|
||||
atomic_size_t tail;
|
||||
} MPMCQueue;
|
||||
|
||||
static MPMCQueue g_file_queue;
|
||||
|
||||
Reference in New Issue
Block a user