From 6e5f83ee24e1db09ef2e08576eeed1182bc169fe Mon Sep 17 00:00:00 2001 From: B3n30 Date: Sat, 21 Jul 2018 16:16:21 +0200 Subject: remove polymorphism issue --- src/common/threadsafe_queue.h | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h index a0c731e8c..edf13bc49 100644 --- a/src/common/threadsafe_queue.h +++ b/src/common/threadsafe_queue.h @@ -33,9 +33,11 @@ public: bool Empty() const { return !read_ptr->next.load(); } + T& Front() const { return read_ptr->current; } + template void Push(Arg&& t) { // create the element, add it to the queue @@ -108,15 +110,41 @@ private: // single reader, multiple writer queue template -class MPSCQueue : public SPSCQueue { +class MPSCQueue { public: + u32 Size() const { + return spsc_queue.Size(); + } + + bool Empty() const { + return spsc_queue.Empty(); + } + + T& Front() const { + return spsc_queue.Front(); + } + template void Push(Arg&& t) { std::lock_guard lock(write_lock); - SPSCQueue::Push(t); + spsc_queue.Push(t); + } + + void Pop() { + return spsc_queue.Pop(); + } + + bool Pop(T& t) { + return spsc_queue.Pop(t); + } + + // not thread-safe + void Clear() { + spsc_queue.Clear(); } private: + SPSCQueue spsc_queue; std::mutex write_lock; }; } // namespace Common -- cgit v1.2.3