From e3f963d2b436972c6857d78abe04cc742ef03a14 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Tue, 15 Jan 2019 15:27:06 +0800 Subject: [PATCH] circ_elem.h => elem_circ.h; organ => orgnz; elem_head => conn_head --- include/def.h | 4 +-- include/{circ_elem.h => elem_circ.h} | 37 +++++++++------------------- include/elem_def.h | 26 +++++++++++++++++++ include/queue.h | 2 +- test/test_circ.cpp | 2 +- 5 files changed, 41 insertions(+), 30 deletions(-) rename include/{circ_elem.h => elem_circ.h} (89%) create mode 100644 include/elem_def.h diff --git a/include/def.h b/include/def.h index a775a04..7c89992 100644 --- a/include/def.h +++ b/include/def.h @@ -31,7 +31,7 @@ enum : std::size_t { data_length = 16 }; -enum class organ { // data structure organization +enum class orgnz { // data structure organization linked, cyclic }; @@ -48,7 +48,7 @@ enum class trans { // transmission // producer-consumer policy declaration -template +template struct prod_cons; // concept helpers diff --git a/include/circ_elem.h b/include/elem_circ.h similarity index 89% rename from include/circ_elem.h rename to include/elem_circ.h index 5b0d77f..9ed694d 100644 --- a/include/circ_elem.h +++ b/include/elem_circ.h @@ -6,6 +6,7 @@ #include "def.h" #include "rw_lock.h" +#include "elem_def.h" namespace ipc { @@ -47,7 +48,7 @@ elem_t* elem_of(void* ptr) noexcept { //////////////////////////////////////////////////////////////// template <> -struct prod_cons { +struct prod_cons { std::atomic rd_ { 0 }; // read index std::atomic wt_ { 0 }; // write index @@ -82,8 +83,8 @@ struct prod_cons { }; template <> -struct prod_cons - : prod_cons { +struct prod_cons + : prod_cons { template bool pop(E* /*elems*/, circ::detail::u2_t& /*cur*/, F&& f, circ::detail::elem_t* elem_start) noexcept { @@ -105,8 +106,8 @@ struct prod_cons }; template <> -struct prod_cons - : prod_cons { +struct prod_cons + : prod_cons { std::atomic ct_ { 0 }; // commit index @@ -137,7 +138,7 @@ struct prod_cons }; template <> -struct prod_cons { +struct prod_cons { std::atomic wt_ { 0 }; // write index template @@ -194,8 +195,8 @@ struct prod_cons { }; template <> -struct prod_cons - : prod_cons { +struct prod_cons + : prod_cons { std::atomic ct_ { 0 }; // commit index @@ -230,7 +231,7 @@ struct prod_cons }; template -using prod_cons_circ = prod_cons; +using prod_cons_circ = prod_cons; namespace circ { @@ -238,28 +239,12 @@ namespace circ { /// element-array implementation //////////////////////////////////////////////////////////////// -struct elem_head { - std::atomic cc_ { 0 }; // connection counter - - std::size_t connect() noexcept { - return cc_.fetch_add(1, std::memory_order_release); - } - - std::size_t disconnect() noexcept { - return cc_.fetch_sub(1, std::memory_order_release); - } - - std::size_t conn_count(std::memory_order order = std::memory_order_acquire) const noexcept { - return cc_.load(order); - } -}; - template class elem_array : private Policy { public: using policy_t = Policy; using base_t = Policy; - using head_t = elem_head; + using head_t = ipc::conn_head; using elem_t = detail::elem_t>; enum : std::size_t { diff --git a/include/elem_def.h b/include/elem_def.h new file mode 100644 index 0000000..3ca8368 --- /dev/null +++ b/include/elem_def.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +namespace ipc { + +template +struct conn_head { + std::atomic cc_ { 0 }; // connection counter + + std::size_t connect() noexcept { + return cc_.fetch_add(1, std::memory_order_release); + } + + std::size_t disconnect() noexcept { + return cc_.fetch_sub(1, std::memory_order_release); + } + + std::size_t conn_count(std::memory_order order = std::memory_order_acquire) const noexcept { + return cc_.load(order); + } +}; + +} // namespace ipc diff --git a/include/queue.h b/include/queue.h index b0ce6fd..b50754e 100644 --- a/include/queue.h +++ b/include/queue.h @@ -11,7 +11,7 @@ #include "def.h" #include "rw_lock.h" -#include "circ_elem.h" +#include "elem_circ.h" namespace ipc { diff --git a/test/test_circ.cpp b/test/test_circ.cpp index 8810046..a2d7a62 100644 --- a/test/test_circ.cpp +++ b/test/test_circ.cpp @@ -6,7 +6,7 @@ #include #include -#include "circ_elem.h" +#include "elem_circ.h" #include "queue.h" #include "memory/resource.hpp" #include "test.h"