MCPcopy Create free account
hub / github.com/cameron314/readerwriterqueue / BlockingReaderWriterQueue

Class BlockingReaderWriterQueue

readerwriterqueue.h:759–973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

757// Like ReaderWriterQueue, but also providees blocking operations
758template<typename T, size_t MAX_BLOCK_SIZE = 512>
759class BlockingReaderWriterQueue
760{
761private:
762 typedef ::moodycamel::ReaderWriterQueue<T, MAX_BLOCK_SIZE> ReaderWriterQueue;
763
764public:
765 explicit BlockingReaderWriterQueue(size_t size = 15) AE_NO_TSAN
766 : inner(size), sema(new spsc_sema::LightweightSemaphore())
767 { }
768
769 BlockingReaderWriterQueue(BlockingReaderWriterQueue&& other) AE_NO_TSAN
770 : inner(std::move(other.inner)), sema(std::move(other.sema))
771 { }
772
773 BlockingReaderWriterQueue& operator=(BlockingReaderWriterQueue&& other) AE_NO_TSAN
774 {
775 std::swap(sema, other.sema);
776 std::swap(inner, other.inner);
777 return *this;
778 }
779
780
781 // Enqueues a copy of element if there is room in the queue.
782 // Returns true if the element was enqueued, false otherwise.
783 // Does not allocate memory.
784 AE_FORCEINLINE bool try_enqueue(T const& element) AE_NO_TSAN
785 {
786 if (inner.try_enqueue(element)) {
787 sema->signal();
788 return true;
789 }
790 return false;
791 }
792
793 // Enqueues a moved copy of element if there is room in the queue.
794 // Returns true if the element was enqueued, false otherwise.
795 // Does not allocate memory.
796 AE_FORCEINLINE bool try_enqueue(T&& element) AE_NO_TSAN
797 {
798 if (inner.try_enqueue(std::forward<T>(element))) {
799 sema->signal();
800 return true;
801 }
802 return false;
803 }
804
805#if MOODYCAMEL_HAS_EMPLACE
806 // Like try_enqueue() but with emplace semantics (i.e. construct-in-place).
807 template<typename... Args>
808 AE_FORCEINLINE bool try_emplace(Args&&... args) AE_NO_TSAN
809 {
810 if (inner.try_emplace(std::forward<Args>(args)...)) {
811 sema->signal();
812 return true;
813 }
814 return false;
815 }
816#endif

Callers

nothing calls this directly

Calls 5

signalMethod · 0.80
emplaceMethod · 0.80
popMethod · 0.80
try_enqueueMethod · 0.45
enqueueMethod · 0.45

Tested by

no test coverage detected