diff --git a/benchmark/test_performance.cpp b/benchmark/test_performance.cpp index ac27737..9817f53 100644 --- a/benchmark/test_performance.cpp +++ b/benchmark/test_performance.cpp @@ -62,14 +62,14 @@ // // TEST(Performance, MPMC_1_to_1) { // // using namespace std; -// // auto queue = queue_api::CreateQueue>(kAmount); +// // auto queue = queue_api::CreateQueue>(kAmount); // // RunSPSC(queue, kAmount); // // } // // TEST(Performance, MPMC_1_to_1_Smaller) { // // using namespace std; -// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); +// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); // // RunSPSC(queue, kAmount); // // } @@ -99,7 +99,7 @@ // // TEST(Performance, DISABLED_MPMC_1_to_4_20secRun_LargeData) { // // using namespace std; -// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); +// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); // // const size_t large = 65000; // // std::string payload(large, 'x'); // // EXPECT_EQ(large, payload.size()); @@ -111,7 +111,7 @@ // // TEST(Performance, DISABLED_MPMC_1_to_4_20secRun_SmallData) { // // using namespace std; -// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); +// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); // // const size_t small = 10; // // std::string payload(small, 'x'); // // EXPECT_EQ(small, payload.size()); @@ -157,7 +157,7 @@ // // TEST(Performance, DISABLED_MPMC_4_to_1_20secRun_LargeData) { // // using namespace std; -// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); +// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); // // const size_t large = 65000; // // std::string payload(large, 'x'); // // EXPECT_EQ(large, payload.size()); @@ -169,7 +169,7 @@ // // TEST(Performance, DISABLED_MPMC_4_to_1_20secRun_SmallData) { // // using namespace std; -// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); +// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); // // const size_t small = 10; // // std::string payload(small, 'x'); // // EXPECT_EQ(small, payload.size()); @@ -215,7 +215,7 @@ // // TEST(Performance, DISABLED_MPMC_4_to_4_20secRun_LargeData) { // // using namespace std; -// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); +// // auto queue = queue_api::CreateQueue>(kSmallQueueSize); // // const size_t large = 65000; // // std::string payload(large, 'x'); // // EXPECT_EQ(large, payload.size()); diff --git a/src/q/mpmc.hpp b/src/q/mpmc.hpp index 02bfbe4..5b9d736 100644 --- a/src/q/mpmc.hpp +++ b/src/q/mpmc.hpp @@ -17,4 +17,4 @@ #pragma once -#include "q/mpmc_flexible_lock_queue.hpp" +#include "q/mpmc_lock_queue.hpp" diff --git a/src/q/mpmc_flexible_lock_queue.hpp b/src/q/mpmc_flexible_lock_queue.hpp index 9ed93d7..ecc113e 100644 --- a/src/q/mpmc_flexible_lock_queue.hpp +++ b/src/q/mpmc_flexible_lock_queue.hpp @@ -35,7 +35,7 @@ * protected by mutex. Since 'return by reference' is used this queue won't throw */ namespace mpmc { template - class flexible_lock_queue { + class lock_queue { static const int kUnlimited = -1; static const int kSmallDefault = 100; const int kMaxSize; @@ -43,8 +43,8 @@ namespace mpmc { mutable std::mutex m_; std::condition_variable data_cond_; - flexible_lock_queue& operator=(const flexible_lock_queue&) = delete; - flexible_lock_queue(const flexible_lock_queue& other) = delete; + lock_queue& operator=(const lock_queue&) = delete; + lock_queue(const lock_queue& other) = delete; bool internal_full() const; size_t internal_capacity() const; @@ -52,7 +52,7 @@ namespace mpmc { public: // -1 : unbounded // 0 ... N : bounded (0 is silly) - flexible_lock_queue(const int maxSize = kSmallDefault); + lock_queue(const int maxSize = kSmallDefault); bool lock_free() const; bool push(T& item); @@ -68,16 +68,16 @@ namespace mpmc { // maxSize of -1 equals unlimited size template - flexible_lock_queue::flexible_lock_queue(int maxSize) : + lock_queue::lock_queue(int maxSize) : kMaxSize(maxSize) {} template - bool flexible_lock_queue::lock_free() const { + bool lock_queue::lock_free() const { return false; } template - bool flexible_lock_queue::push(T& item) { + bool lock_queue::push(T& item) { { std::lock_guard lock(m_); if (internal_full()) { @@ -90,7 +90,7 @@ namespace mpmc { } template - bool flexible_lock_queue::pop(T& popped_item) { + bool lock_queue::pop(T& popped_item) { std::lock_guard lock(m_); if (queue_.empty()) { return false; @@ -101,7 +101,7 @@ namespace mpmc { } template - bool flexible_lock_queue::wait_and_pop(T& popped_item, std::chrono::milliseconds max_wait) { + bool lock_queue::wait_and_pop(T& popped_item, std::chrono::milliseconds max_wait) { std::unique_lock lock(m_); auto const timeout = std::chrono::steady_clock::now() + max_wait; while (queue_.empty()) { @@ -121,44 +121,44 @@ namespace mpmc { } template - bool flexible_lock_queue::full() { + bool lock_queue::full() { std::lock_guard lock(m_); return internal_full(); } template - bool flexible_lock_queue::empty() const { + bool lock_queue::empty() const { std::lock_guard lock(m_); return queue_.empty(); } template - size_t flexible_lock_queue::size() const { + size_t lock_queue::size() const { std::lock_guard lock(m_); return queue_.size(); } template - size_t flexible_lock_queue::capacity() const { + size_t lock_queue::capacity() const { std::lock_guard lock(m_); return internal_capacity(); } template - size_t flexible_lock_queue::capacity_free() const { + size_t lock_queue::capacity_free() const { std::lock_guard lock(m_); return internal_capacity() - queue_.size(); } template - size_t flexible_lock_queue::usage() const { + size_t lock_queue::usage() const { std::lock_guard lock(m_); return (100 * queue_.size() / internal_capacity()); } // private template - size_t flexible_lock_queue::internal_capacity() const { + size_t lock_queue::internal_capacity() const { if (kMaxSize == kUnlimited) { return std::numeric_limits::max(); } @@ -166,7 +166,7 @@ namespace mpmc { } template - bool flexible_lock_queue::internal_full() const { + bool lock_queue::internal_full() const { if (kMaxSize == kUnlimited) { return false; } diff --git a/test/test_queue.cpp b/test/test_queue.cpp index 2e613a4..4194e92 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -20,7 +20,7 @@ using Type = string; using FlexibleQ = spsc::flexible::circular_fifo; using FixedQ = spsc::fixed::circular_fifo; using FixedSmallQ = spsc::fixed::circular_fifo; -using LockedQ = mpmc::flexible_lock_queue; +using LockedQ = mpmc::lock_queue; template void ProdConsInitialization(Prod& prod, Cons& cons) { @@ -358,7 +358,7 @@ TEST(Queue, FixedQ_MoveUnique) { } TEST(Queue, LockedQ_MoveUnique) { - auto queue = queue_api::CreateQueue>(2); + auto queue = queue_api::CreateQueue>(2); auto producer = std::get(queue); auto consumer = std::get(queue); MoveUniquePtrArgument(producer, consumer); @@ -409,7 +409,7 @@ TEST(Queue, FixedQ_NoMoveOfPtr) { } TEST(Queue, LockedQ_NoMoveUnique) { - auto queue = queue_api::CreateQueue>(2); + auto queue = queue_api::CreateQueue>(2); auto producer = std::get(queue); auto consumer = std::get(queue); NoMovePtrArgument(producer, consumer);