std1.0.0-beta-7 SafeC docs

std :: sync::mpsc

Struct std::MpscQueue

#include <std/sync/mpsc.h> source

generic<T> struct MpscQueue {
    ?&heap T buffer;
    unsigned long cap;
    unsigned long head;
    unsigned long tail;
    unsigned long count;
    struct Spinlock lock;
}

Fields

§?&heap T buffersource
§unsigned long capsource

capacity in elements

§unsigned long headsource

consumer reads here

§unsigned long tailsource

producers write here

§unsigned long countsource

pending element count

§struct Spinlock locksource

guards head/tail/count and the buffer contents

Methods

§static struct MpscQueue<T> new(unsigned long cap)source · definition

Heap-allocates its own buffer. 'cap' need not be a power of two (unlike LFQueue) — the spinlock already serializes index updates. A failed allocation yields a queue with cap 0 (every enqueue reports full).

§int enqueue(T val)source · definition

1 on success, 0 if full

§?T dequeue()source · definition

null if empty

§int is_empty() constsource · definition
§int is_full() constsource · definition
§unsigned long length() constsource · definition
§void drop()source · definition

frees the buffer

§void destroy() consumesource · definition

= drop()