LockFreeFIFO.h 827 B

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include "queue_node.h"
  3. /* Algorithm taken from
  4. Lock-Free Techniques for Concurrent Access to Shared Objects
  5. Dominique Fober, Yann Orlarey, Stephane Letz
  6. http://www.grame.fr/Ressources/pub/LockFree.pdf
  7. http://nedko.arnaudov.name/soft/L17_Fober.pdf
  8. http://www.grame.fr/Ressources/pub/TR-050523.pdf
  9. This implementation (c) 2010 Nullsoft, Inc.
  10. */
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. struct FIFO_POINTER
  15. {
  16. queue_node_t *fifo_node_t;
  17. size_t count;
  18. };
  19. struct fifo_t
  20. {
  21. FIFO_POINTER head; // _head pointer and total count of pop operations (ocount)
  22. FIFO_POINTER tail; // _tail pointer and total count of push operations (icount)
  23. queue_node_t dummy;
  24. size_t count;
  25. };
  26. void fifo_init(fifo_t *fifo);
  27. void fifo_push(fifo_t *fifo, queue_node_t *cl);
  28. queue_node_t *fifo_pop(fifo_t *fifo);
  29. #ifdef __cplusplus
  30. }
  31. #endif