mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
circ_elem.h => elem_circ.h; organ => orgnz; elem_head => conn_head
This commit is contained in:
parent
b62d5a3946
commit
e3f963d2b4
@ -31,7 +31,7 @@ enum : std::size_t {
|
|||||||
data_length = 16
|
data_length = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class organ { // data structure organization
|
enum class orgnz { // data structure organization
|
||||||
linked,
|
linked,
|
||||||
cyclic
|
cyclic
|
||||||
};
|
};
|
||||||
@ -48,7 +48,7 @@ enum class trans { // transmission
|
|||||||
|
|
||||||
// producer-consumer policy declaration
|
// producer-consumer policy declaration
|
||||||
|
|
||||||
template <organ Oz, relat Rp, relat Rc, trans Ts>
|
template <orgnz Oz, relat Rp, relat Rc, trans Ts>
|
||||||
struct prod_cons;
|
struct prod_cons;
|
||||||
|
|
||||||
// concept helpers
|
// concept helpers
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
#include "rw_lock.h"
|
#include "rw_lock.h"
|
||||||
|
#include "elem_def.h"
|
||||||
|
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ elem_t<S>* elem_of(void* ptr) noexcept {
|
|||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct prod_cons<organ::cyclic, relat::single, relat::single, trans::unicast> {
|
struct prod_cons<orgnz::cyclic, relat::single, relat::single, trans::unicast> {
|
||||||
std::atomic<circ::detail::u2_t> rd_ { 0 }; // read index
|
std::atomic<circ::detail::u2_t> rd_ { 0 }; // read index
|
||||||
std::atomic<circ::detail::u2_t> wt_ { 0 }; // write index
|
std::atomic<circ::detail::u2_t> wt_ { 0 }; // write index
|
||||||
|
|
||||||
@ -82,8 +83,8 @@ struct prod_cons<organ::cyclic, relat::single, relat::single, trans::unicast> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct prod_cons<organ::cyclic, relat::single, relat::multi , trans::unicast>
|
struct prod_cons<orgnz::cyclic, relat::single, relat::multi , trans::unicast>
|
||||||
: prod_cons<organ::cyclic, relat::single, relat::single, trans::unicast> {
|
: prod_cons<orgnz::cyclic, relat::single, relat::single, trans::unicast> {
|
||||||
|
|
||||||
template <typename E, typename F, std::size_t S>
|
template <typename E, typename F, std::size_t S>
|
||||||
bool pop(E* /*elems*/, circ::detail::u2_t& /*cur*/, F&& f, circ::detail::elem_t<S>* elem_start) noexcept {
|
bool pop(E* /*elems*/, circ::detail::u2_t& /*cur*/, F&& f, circ::detail::elem_t<S>* elem_start) noexcept {
|
||||||
@ -105,8 +106,8 @@ struct prod_cons<organ::cyclic, relat::single, relat::multi , trans::unicast>
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct prod_cons<organ::cyclic, relat::multi , relat::multi, trans::unicast>
|
struct prod_cons<orgnz::cyclic, relat::multi , relat::multi, trans::unicast>
|
||||||
: prod_cons<organ::cyclic, relat::single, relat::multi, trans::unicast> {
|
: prod_cons<orgnz::cyclic, relat::single, relat::multi, trans::unicast> {
|
||||||
|
|
||||||
std::atomic<circ::detail::u2_t> ct_ { 0 }; // commit index
|
std::atomic<circ::detail::u2_t> ct_ { 0 }; // commit index
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ struct prod_cons<organ::cyclic, relat::multi , relat::multi, trans::unicast>
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct prod_cons<organ::cyclic, relat::single, relat::multi, trans::broadcast> {
|
struct prod_cons<orgnz::cyclic, relat::single, relat::multi, trans::broadcast> {
|
||||||
std::atomic<circ::detail::u2_t> wt_ { 0 }; // write index
|
std::atomic<circ::detail::u2_t> wt_ { 0 }; // write index
|
||||||
|
|
||||||
template <std::size_t DataSize>
|
template <std::size_t DataSize>
|
||||||
@ -194,8 +195,8 @@ struct prod_cons<organ::cyclic, relat::single, relat::multi, trans::broadcast> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct prod_cons<organ::cyclic, relat::multi , relat::multi, trans::broadcast>
|
struct prod_cons<orgnz::cyclic, relat::multi , relat::multi, trans::broadcast>
|
||||||
: prod_cons<organ::cyclic, relat::single, relat::multi, trans::broadcast> {
|
: prod_cons<orgnz::cyclic, relat::single, relat::multi, trans::broadcast> {
|
||||||
|
|
||||||
std::atomic<circ::detail::u2_t> ct_ { 0 }; // commit index
|
std::atomic<circ::detail::u2_t> ct_ { 0 }; // commit index
|
||||||
|
|
||||||
@ -230,7 +231,7 @@ struct prod_cons<organ::cyclic, relat::multi , relat::multi, trans::broadcast>
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <relat Rp, relat Rc, trans Ts>
|
template <relat Rp, relat Rc, trans Ts>
|
||||||
using prod_cons_circ = prod_cons<organ::cyclic, Rp, Rc, Ts>;
|
using prod_cons_circ = prod_cons<orgnz::cyclic, Rp, Rc, Ts>;
|
||||||
|
|
||||||
namespace circ {
|
namespace circ {
|
||||||
|
|
||||||
@ -238,28 +239,12 @@ namespace circ {
|
|||||||
/// element-array implementation
|
/// element-array implementation
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct elem_head {
|
|
||||||
std::atomic<detail::u2_t> 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 <std::size_t DataSize, typename Policy>
|
template <std::size_t DataSize, typename Policy>
|
||||||
class elem_array : private Policy {
|
class elem_array : private Policy {
|
||||||
public:
|
public:
|
||||||
using policy_t = Policy;
|
using policy_t = Policy;
|
||||||
using base_t = Policy;
|
using base_t = Policy;
|
||||||
using head_t = elem_head;
|
using head_t = ipc::conn_head<detail::u2_t>;
|
||||||
using elem_t = detail::elem_t<policy_t::template elem_param<DataSize>>;
|
using elem_t = detail::elem_t<policy_t::template elem_param<DataSize>>;
|
||||||
|
|
||||||
enum : std::size_t {
|
enum : std::size_t {
|
||||||
26
include/elem_def.h
Normal file
26
include/elem_def.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace ipc {
|
||||||
|
|
||||||
|
template <typename U2>
|
||||||
|
struct conn_head {
|
||||||
|
std::atomic<U2> 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
|
||||||
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
#include "rw_lock.h"
|
#include "rw_lock.h"
|
||||||
#include "circ_elem.h"
|
#include "elem_circ.h"
|
||||||
|
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "circ_elem.h"
|
#include "elem_circ.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "memory/resource.hpp"
|
#include "memory/resource.hpp"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user