mpscqueue.h 803 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2010-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef BX_MPSCQUEUE_H_HEADER_GUARD
  6. #define BX_MPSCQUEUE_H_HEADER_GUARD
  7. #include "spscqueue.h"
  8. namespace bx
  9. {
  10. template <typename Ty>
  11. class MpScUnboundedQueue
  12. {
  13. BX_CLASS(MpScUnboundedQueue
  14. , NO_COPY
  15. , NO_ASSIGNMENT
  16. );
  17. public:
  18. MpScUnboundedQueue()
  19. {
  20. }
  21. ~MpScUnboundedQueue()
  22. {
  23. }
  24. void push(Ty* _ptr) // producer only
  25. {
  26. m_write.lock();
  27. m_queue.push(_ptr);
  28. m_write.unlock();
  29. }
  30. Ty* peek() // consumer only
  31. {
  32. return m_queue.peek();
  33. }
  34. Ty* pop() // consumer only
  35. {
  36. return m_queue.pop();
  37. }
  38. private:
  39. LwMutex m_write;
  40. SpScUnboundedQueue<Ty> m_queue;
  41. };
  42. } // namespace bx
  43. #endif // BX_MPSCQUEUE_H_HEADER_GUARD