forked from amir/filehasher
plat_sem_destroy(&q->items_sem);
This commit is contained in:
14
lf_mpmc.h
14
lf_mpmc.h
@@ -23,6 +23,9 @@ static void cpu_pause(void) {
|
||||
_mm_pause();
|
||||
#endif
|
||||
}
|
||||
|
||||
typedef struct plat_sem plat_sem;
|
||||
|
||||
typedef struct CACHE_ALIGN {
|
||||
atomic_size_t seq;
|
||||
void *data;
|
||||
@@ -40,7 +43,7 @@ typedef struct {
|
||||
size_t commit_step;
|
||||
atomic_flag commit_lock;
|
||||
|
||||
HANDLE items_sem;
|
||||
plat_sem items_sem;
|
||||
|
||||
MPMCSlot *slots;
|
||||
} MPMCQueue;
|
||||
@@ -87,7 +90,7 @@ static void mpmc_init(MPMCQueue *q, size_t max_capacity) {
|
||||
atomic_init(&q->head, 0);
|
||||
atomic_init(&q->tail, 0);
|
||||
|
||||
q->items_sem = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
|
||||
plat_sem_init(&q->items_sem, 0);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
@@ -176,7 +179,7 @@ static void mpmc_push(MPMCQueue *q, void *item) {
|
||||
|
||||
atomic_store_explicit(&slot->seq, pos + 1, memory_order_release);
|
||||
|
||||
ReleaseSemaphore(q->items_sem, 1, NULL);
|
||||
plat_sem_post(&q->items_sem, 1);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
@@ -184,7 +187,7 @@ static void mpmc_push(MPMCQueue *q, void *item) {
|
||||
/* ----------------------------------------------------------- */
|
||||
static void *mpmc_pop(MPMCQueue *q) {
|
||||
|
||||
WaitForSingleObject(q->items_sem, INFINITE);
|
||||
plat_sem_wait(&q->items_sem);
|
||||
|
||||
MPMCSlot *slot;
|
||||
size_t pos;
|
||||
@@ -249,8 +252,7 @@ static void mpmc_finish(MPMCQueue *q) {
|
||||
q->slots = NULL;
|
||||
}
|
||||
|
||||
if (q->items_sem)
|
||||
CloseHandle(q->items_sem);
|
||||
plat_sem_destroy(&q->items_sem);
|
||||
|
||||
q->capacity = 0;
|
||||
q->mask = 0;
|
||||
|
||||
Reference in New Issue
Block a user