diff --git a/source/native-plugins/zynaddsubfx/Containers/MultiPseudoStack.cpp b/source/native-plugins/zynaddsubfx/Containers/MultiPseudoStack.cpp new file mode 100644 index 000000000..763e3c199 --- /dev/null +++ b/source/native-plugins/zynaddsubfx/Containers/MultiPseudoStack.cpp @@ -0,0 +1,100 @@ +#include "MultiPseudoStack.h" +#include +#include + +#define INVALID ((int32_t)0xffffffff) +#define MAX ((int32_t)0x7fffffff) +QueueListItem::QueueListItem(void) + :memory(0), size(0) +{ +} + +LockFreeQueue::LockFreeQueue(qli_t *data_, int n) + :data(data_), elms(n), next_r(0), next_w(0), avail(0) +{ + tag = new std::atomic[n]; + for(int i=0; i +#include + +//XXX rename this thing +typedef struct QueueListItem qli_t; +struct QueueListItem +{ + QueueListItem(void); + char *memory; + uint32_t size; +}; + + +//Many reader many writer +class LockFreeQueue +{ + qli_t *const data; + const int elms; + std::atomic *tag; + std::atomic next_r; + std::atomic next_w; + std::atomic avail; + public: + LockFreeQueue(qli_t *data_, int n); + qli_t *read(void); + void write(qli_t *Q); +}; + + +/* + * Many reader Many writer capiable queue + * - lock free + * - allocation free (post initialization) + */ +class MultiQueue +{ + qli_t *pool; + LockFreeQueue m_free; + LockFreeQueue m_msgs; + + public: + MultiQueue(void); + ~MultiQueue(void); + void dump(void); + qli_t *alloc(void) { return m_free.read(); } + void free(qli_t *q) { m_free.write(q); } + void write(qli_t *q) { m_msgs.write(q); } + qli_t *read(void) { return m_msgs.read(); } +};