ThreadQueue.h 531 B

1234567891011121314151617181920212223
  1. #pragma once
  2. #include "RingBuffer.h"
  3. #include <semaphore.h>
  4. class ThreadQueue
  5. {
  6. public:
  7. ThreadQueue();
  8. ~ThreadQueue();
  9. void Queue(const void *);
  10. // Get() blocks until there's something in the queue
  11. void *Get();
  12. // return value is same as sem_wait
  13. // delay is in nanoseconds
  14. int Wait(long delay, void **val);
  15. // kind of like sem_trywait
  16. int Try(void **val);
  17. private:
  18. // TODO: need to use something safer than RingBuffer, preferably a lock-free linked list so we can grow unlimited
  19. RingBuffer buffer;
  20. sem_t event;
  21. };