diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index c5542c86..d9a8d8a1 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -2,7 +2,7 @@ name: C/C++ CI on: push: - branches: [ master, develop, issue-* ] + branches: [ master, develop, issue-*, feature/* ] pull_request: branches: [ master, develop ] diff --git a/include/libipc/buffer.h b/include/libipc/buffer.h index 3f8c229b..7185c021 100755 --- a/include/libipc/buffer.h +++ b/include/libipc/buffer.h @@ -5,12 +5,12 @@ #include #include -#include "libipc/export.h" +#include "libipc/imp/export.h" #include "libipc/def.h" namespace ipc { -class IPC_EXPORT buffer { +class LIBIPC_EXPORT buffer { public: using destructor_t = void (*)(void*, std::size_t); @@ -57,8 +57,8 @@ class IPC_EXPORT buffer { }; } - friend IPC_EXPORT bool operator==(buffer const & b1, buffer const & b2); - friend IPC_EXPORT bool operator!=(buffer const & b1, buffer const & b2); + friend LIBIPC_EXPORT bool operator==(buffer const & b1, buffer const & b2); + friend LIBIPC_EXPORT bool operator!=(buffer const & b1, buffer const & b2); private: class buffer_; diff --git a/include/libipc/concur/intrusive_stack.h b/include/libipc/concur/intrusive_stack.h new file mode 100644 index 00000000..aa98a66d --- /dev/null +++ b/include/libipc/concur/intrusive_stack.h @@ -0,0 +1,66 @@ +/** + * \file libconcur/intrusive_stack.h + * \author mutouyun (orz@orzz.org) + * \brief Define concurrent intrusive stack. + */ +#pragma once + +#include + +namespace ipc { +namespace concur { + +/// \brief Intrusive stack node. +/// \tparam T The type of the value. +template +struct intrusive_node { + T value; + std::atomic next; +}; + +/// \brief Intrusive stack. +/// \tparam T The type of the value. +/// \tparam Node The type of the node. +template > +class intrusive_stack { +public: + using node = Node; + +private: + std::atomic top_{nullptr}; + +public: + intrusive_stack(intrusive_stack const &) = delete; + intrusive_stack(intrusive_stack &&) = delete; + intrusive_stack &operator=(intrusive_stack const &) = delete; + intrusive_stack &operator=(intrusive_stack &&) = delete; + + constexpr intrusive_stack() noexcept = default; + + bool empty() const noexcept { + return top_.load(std::memory_order_acquire) == nullptr; + } + + void push(node *n) noexcept { + node *old_top = top_.load(std::memory_order_acquire); + do { + n->next.store(old_top, std::memory_order_relaxed); + } while (!top_.compare_exchange_weak(old_top, n, std::memory_order_release + , std::memory_order_acquire)); + } + + node *pop() noexcept { + node *old_top = top_.load(std::memory_order_acquire); + do { + if (old_top == nullptr) { + return nullptr; + } + } while (!top_.compare_exchange_weak(old_top, old_top->next.load(std::memory_order_relaxed) + , std::memory_order_release + , std::memory_order_acquire)); + return old_top; + } +}; + +} // namespace concur +} // namespace ipc diff --git a/include/libipc/condition.h b/include/libipc/condition.h index 072074a9..201c33fe 100644 --- a/include/libipc/condition.h +++ b/include/libipc/condition.h @@ -2,14 +2,14 @@ #include // std::uint64_t -#include "libipc/export.h" +#include "libipc/imp/export.h" #include "libipc/def.h" #include "libipc/mutex.h" namespace ipc { namespace sync { -class IPC_EXPORT condition { +class LIBIPC_EXPORT condition { condition(condition const &) = delete; condition &operator=(condition const &) = delete; diff --git a/include/libipc/def.h b/include/libipc/def.h index 45cd7801..fdda14a1 100755 --- a/include/libipc/def.h +++ b/include/libipc/def.h @@ -26,25 +26,26 @@ using uint_t = typename uint::type; // constants enum : std::uint32_t { - invalid_value = (std::numeric_limits::max)(), - default_timeout = 100, // ms + invalid_value = (std::numeric_limits::max)(), + default_timeout = 100, // ms }; enum : std::size_t { - data_length = 64, - large_msg_limit = data_length, - large_msg_align = 1024, - large_msg_cache = 32, + central_cache_default_size = 1024 * 1024, ///< 1MB + data_length = 64, + large_msg_limit = data_length, + large_msg_align = 1024, + large_msg_cache = 32, }; enum class relat { // multiplicity of the relationship - single, - multi + single, + multi }; enum class trans { // transmission - unicast, - broadcast + unicast, + broadcast }; // producer-consumer policy flag @@ -57,9 +58,9 @@ struct relat_trait; template struct relat_trait> { - constexpr static bool is_multi_producer = (Rp == relat::multi); - constexpr static bool is_multi_consumer = (Rc == relat::multi); - constexpr static bool is_broadcast = (Ts == trans::broadcast); + constexpr static bool is_multi_producer = (Rp == relat::multi); + constexpr static bool is_multi_consumer = (Rc == relat::multi); + constexpr static bool is_broadcast = (Ts == trans::broadcast); }; template