Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.0KB

  1. #pragma once
  2. #include <atomic>
  3. #include <cassert>
  4. //XXX rename this thing
  5. typedef struct QueueListItem qli_t;
  6. struct QueueListItem
  7. {
  8. QueueListItem(void);
  9. char *memory;
  10. uint32_t size;
  11. };
  12. //Many reader many writer
  13. class LockFreeQueue
  14. {
  15. qli_t *const data;
  16. const int elms;
  17. std::atomic<uint32_t> *tag;
  18. std::atomic<int32_t> next_r;
  19. std::atomic<int32_t> next_w;
  20. std::atomic<int32_t> avail;
  21. public:
  22. LockFreeQueue(qli_t *data_, int n);
  23. qli_t *read(void);
  24. void write(qli_t *Q);
  25. };
  26. /*
  27. * Many reader Many writer capiable queue
  28. * - lock free
  29. * - allocation free (post initialization)
  30. */
  31. class MultiQueue
  32. {
  33. qli_t *pool;
  34. LockFreeQueue m_free;
  35. LockFreeQueue m_msgs;
  36. public:
  37. MultiQueue(void);
  38. ~MultiQueue(void);
  39. void dump(void);
  40. qli_t *alloc(void) { return m_free.read(); }
  41. void free(qli_t *q) { m_free.write(q); }
  42. void write(qli_t *q) { m_msgs.write(q); }
  43. qli_t *read(void) { return m_msgs.read(); }
  44. };