LockFreeLIFO.h 748 B

12345678910111213141516171819202122232425262728293031
  1. #pragma once
  2. #include "foundation/types.h"
  3. #include "nu/queue_node.h"
  4. #include "foundation/align.h"
  5. /* lock free stack object
  6. multiple threads can push and pop without locking
  7. note that order is not guaranteed. that is, if Thread 1 calls Insert before Thread 2, Thread 2's item might still make it in before.
  8. */
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef NALIGN(8) struct lifo_struct_t
  13. {
  14. volatile queue_node_t *head;
  15. uint32_t aba;
  16. } lifo_t;
  17. /* use this to allocate an object that will go into this */
  18. queue_node_t *lifo_malloc(size_t bytes);
  19. void lifo_free(queue_node_t *ptr);
  20. void lifo_init(lifo_t *lifo);
  21. void lifo_push(lifo_t *lifo, queue_node_t *cl);
  22. queue_node_t *lifo_pop(lifo_t *lifo);
  23. #ifdef __cplusplus
  24. }
  25. #endif