Skip to content

c/c++ wait-free queue, easy built cross platform.

License

Notifications You must be signed in to change notification settings

sailfish009/wfqueue

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wfqueue logo

wfqueue.h Build Status

c/c++ FIFO wait-free queue, easy built cross platform(no extra dependencies needed)

Guarantee thread safety memory management, and it's all in one header only, as fast as never wait.

All Platform tests

GCC/CLANG/G++/CLANG++ | Build Status

VS x64/x86 | Build status

support MPMC, MPSC, MCSP

API

// Fixed size of queue
wfqueue_t *wfq_create(size_t fixed_size);
int wfq_enq(wfqueue_t *q, void* val);
void* wfq_deq(wfqueue_t *q);
void wfq_destroy(wfqueue_t *q);
size_t wfq_size(wfqueue_t *q);
size_t wfq_capacity(wfqueue_t *q);

Example

if c++

#include "wfqueue.h"


// Fixed size of queue
wfqueue_t *q = wfq_create(fixed_sz); 

// wrap in to thread
new ClassVal *s = new ClassVal;
wfq_enq(q, s); // or malloc if c programming, return 1 if success enqueue

// wrap in to thread
s = (ClassVal*)wfq_deq(q); // return NULL/nullptr if no val consuming

if(s) {
  s->do_op();

  delete s;
}


wfq_destroy(q);

if c

#include "wfqueue.h"

// Fixed size of queue
wfqueue_t *q = wfq_create(fixed_sz); 

// wrap in to thread
ClassVal *s = malloc(sizeof(ClassVal);
wfq_enq(q, s); // or malloc if c programming, return 1 if success enqueue

// wrap in to thread
s = (ClassVal*)wfq_deq(q); // return NULL/nullptr if no val consuming

if(s) {
  s->do_op();

  free(s);
}

wfq_destroy(q);

Build

include header file in your project

Wrap this in your class

example

class MyQueue {
	wfqueue_t *q;
public:
	MyQueue ( size_t sz ) {
		q = wfq_create(sz);
	}
	inline int enq(Xclass *val) {
		return wfq_enq(q, val);
	}

	inline Xclass *deq() {
		return (Xclass*)wfq_deq(q);
	}
	inline size_t getSize() {
		return wfq_size(q);
	}
	~MyQueue() {
		wfq_destroy(q);;
	}
}

You may also like lock free queue FIFO

lfqueue

About

c/c++ wait-free queue, easy built cross platform.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%