| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- /*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
- */
- #ifndef BX_SPSCQUEUE_H_HEADER_GUARD
- #define BX_SPSCQUEUE_H_HEADER_GUARD
- #include "allocator.h"
- #include "cpu.h"
- #include "semaphore.h"
- namespace bx
- {
- ///
- class SpScUnboundedQueue
- {
- BX_CLASS(SpScUnboundedQueue
- , NO_COPY
- , NO_ASSIGNMENT
- );
- public:
- ///
- SpScUnboundedQueue(AllocatorI* _allocator);
- ///
- ~SpScUnboundedQueue();
- ///
- void push(void* _ptr);
- ///
- void* peek();
- ///
- void* pop();
- private:
- struct Node
- {
- ///
- Node(void* _ptr);
- void* m_ptr;
- Node* m_next;
- };
- AllocatorI* m_allocator;
- Node* m_first;
- Node* m_divider;
- Node* m_last;
- };
- ///
- template<typename Ty>
- class SpScUnboundedQueueT
- {
- BX_CLASS(SpScUnboundedQueueT
- , NO_COPY
- , NO_ASSIGNMENT
- );
- public:
- ///
- SpScUnboundedQueueT(AllocatorI* _allocator);
- ///
- ~SpScUnboundedQueueT();
- ///
- void push(Ty* _ptr);
- ///
- Ty* peek();
- ///
- Ty* pop();
- private:
- SpScUnboundedQueue m_queue;
- };
- #if BX_CONFIG_SUPPORTS_THREADING
- ///
- class SpScBlockingUnboundedQueue
- {
- BX_CLASS(SpScBlockingUnboundedQueue
- , NO_COPY
- , NO_ASSIGNMENT
- );
- public:
- ///
- SpScBlockingUnboundedQueue(AllocatorI* _allocator);
- ///
- ~SpScBlockingUnboundedQueue();
- ///
- void push(void* _ptr); // producer only
- ///
- void* peek(); // consumer only
- ///
- void* pop(int32_t _msecs = -1); // consumer only
- private:
- Semaphore m_count;
- SpScUnboundedQueue m_queue;
- };
- ///
- template<typename Ty>
- class SpScBlockingUnboundedQueueT
- {
- BX_CLASS(SpScBlockingUnboundedQueueT
- , NO_COPY
- , NO_ASSIGNMENT
- );
- public:
- ///
- SpScBlockingUnboundedQueueT(AllocatorI* _allocator);
- ///
- ~SpScBlockingUnboundedQueueT();
- ///
- void push(Ty* _ptr); // producer only
- ///
- Ty* peek(); // consumer only
- ///
- Ty* pop(int32_t _msecs = -1); // consumer only
- private:
- SpScBlockingUnboundedQueue m_queue;
- };
- #endif // BX_CONFIG_SUPPORTS_THREADING
- } // namespace bx
- #include "inline/spscqueue.inl"
- #endif // BX_SPSCQUEUE_H_HEADER_GUARD
|