std1.0.0-beta-7 SafeC docs

std :: sync::lockfree

Struct std::LFQueue

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

generic<T> struct LFQueue {
    []T buffer;
    unsigned long cap;
    long long head;
    long long tail;
    int owned;
}

Fields

§[]T buffersource

the slots (empty after destroy or a failed new)

§unsigned long capsource

power of two, <= buffer.len

§long long headsource

elements ever enqueued (producer, atomic)

§long long tailsource

elements ever dequeued (consumer, atomic)

§int ownedsource

1 if LFQueue::new allocated the buffer

Methods

§static struct LFQueue<T> over([]T buffer)source · definition

Uses a caller-provided buffer (which must outlive the queue); its length is rounded DOWN to a power of two for the capacity.

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

Allocates its own buffer; cap is rounded UP to a power of two. 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 if LFQueue::new allocated it

§void destroy() consumesource · definition

= drop()