diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h index c5fb7a27c6..e10baed2ed 100644 --- a/src/common/threadsafe_queue.h +++ b/src/common/threadsafe_queue.h @@ -7,12 +7,11 @@ // a simple lockless thread-safe, // single reader, single writer queue -#include #include #include #include #include -#include "common/common_types.h" +#include namespace Common { template @@ -26,7 +25,7 @@ public: delete read_ptr; } - u32 Size() const { + std::size_t Size() const { return size.load(); } @@ -47,9 +46,9 @@ public: ElementPtr* new_ptr = new ElementPtr(); write_ptr->next.store(new_ptr, std::memory_order_release); write_ptr = new_ptr; - cv.notify_one(); - ++size; + + cv.notify_one(); } void Pop() { @@ -99,7 +98,7 @@ private: // and a pointer to the next ElementPtr class ElementPtr { public: - ElementPtr() : next(nullptr) {} + ElementPtr() = default; ~ElementPtr() { ElementPtr* next_ptr = next.load(); @@ -108,12 +107,12 @@ private: } T current; - std::atomic next; + std::atomic next{nullptr}; }; ElementPtr* write_ptr; ElementPtr* read_ptr; - std::atomic size; + std::atomic_size_t size{0}; std::mutex cv_mutex; std::condition_variable cv; }; @@ -124,7 +123,7 @@ private: template class MPSCQueue { public: - u32 Size() const { + std::size_t Size() const { return spsc_queue.Size(); }