mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
Update constants to use static constexpr
This commit is contained in:
parent
5aaa78a8a5
commit
2cffe55ee1
@ -379,15 +379,15 @@ struct producer<trans::broadcast, relation::multi> {
|
|||||||
private:
|
private:
|
||||||
friend struct producer::header_impl;
|
friend struct producer::header_impl;
|
||||||
|
|
||||||
constexpr static index_t get_index(state::flag_t flags) noexcept {
|
static constexpr index_t get_index(state::flag_t flags) noexcept {
|
||||||
return index_t(flags);
|
return index_t(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr static index_t get_begin(state::flag_t flags) noexcept {
|
static constexpr index_t get_begin(state::flag_t flags) noexcept {
|
||||||
return index_t(flags >> (sizeof(index_t) * CHAR_BIT));
|
return index_t(flags >> (sizeof(index_t) * CHAR_BIT));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr static state::flag_t make_flags(index_t idx, index_t beg) noexcept {
|
static constexpr state::flag_t make_flags(index_t idx, index_t beg) noexcept {
|
||||||
return state::flag_t(idx) | (state::flag_t(beg) << (sizeof(index_t) * CHAR_BIT));
|
return state::flag_t(idx) | (state::flag_t(beg) << (sizeof(index_t) * CHAR_BIT));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -29,7 +29,7 @@ private:
|
|||||||
static std::false_type check(...);
|
static std::false_type check(...);
|
||||||
public:
|
public:
|
||||||
using type = decltype(check<T>(nullptr));
|
using type = decltype(check<T>(nullptr));
|
||||||
constexpr static auto value = type::value;
|
static constexpr auto value = type::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -41,7 +41,7 @@ private:
|
|||||||
static std::false_type check(...);
|
static std::false_type check(...);
|
||||||
public:
|
public:
|
||||||
using type = decltype(check<T>(nullptr));
|
using type = decltype(check<T>(nullptr));
|
||||||
constexpr static auto value = type::value;
|
static constexpr auto value = type::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename C, bool = trait_has_size<C>::value
|
template <typename C, bool = trait_has_size<C>::value
|
||||||
@ -50,21 +50,21 @@ struct trait;
|
|||||||
|
|
||||||
template <typename T, std::size_t N>
|
template <typename T, std::size_t N>
|
||||||
struct trait<T[N], false, false> {
|
struct trait<T[N], false, false> {
|
||||||
constexpr static auto countof(T const (&)[N]) noexcept {
|
static constexpr auto countof(T const (&)[N]) noexcept {
|
||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename C, bool B>
|
template <typename C, bool B>
|
||||||
struct trait<C, true, B> {
|
struct trait<C, true, B> {
|
||||||
constexpr static auto countof(C const &c) noexcept(noexcept(c.size())) {
|
static constexpr auto countof(C const &c) noexcept(noexcept(c.size())) {
|
||||||
return c.size();
|
return c.size();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
struct trait<C, false, true> {
|
struct trait<C, false, true> {
|
||||||
constexpr static auto countof(C const &c) noexcept(noexcept(c.Size())) {
|
static constexpr auto countof(C const &c) noexcept(noexcept(c.Size())) {
|
||||||
return c.Size();
|
return c.Size();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -29,7 +29,7 @@ private:
|
|||||||
static std::false_type check(...);
|
static std::false_type check(...);
|
||||||
public:
|
public:
|
||||||
using type = decltype(check<T>(nullptr));
|
using type = decltype(check<T>(nullptr));
|
||||||
constexpr static auto value = type::value;
|
static constexpr auto value = type::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -41,7 +41,7 @@ private:
|
|||||||
static std::false_type check(...);
|
static std::false_type check(...);
|
||||||
public:
|
public:
|
||||||
using type = decltype(check<T>(nullptr));
|
using type = decltype(check<T>(nullptr));
|
||||||
constexpr static auto value = type::value;
|
static constexpr auto value = type::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename C, bool = trait_has_data<C>::value
|
template <typename C, bool = trait_has_data<C>::value
|
||||||
@ -50,10 +50,10 @@ struct trait;
|
|||||||
|
|
||||||
template <typename T, std::size_t N>
|
template <typename T, std::size_t N>
|
||||||
struct trait<T[N], false, false> {
|
struct trait<T[N], false, false> {
|
||||||
constexpr static T const *dataof(T const (&arr)[N]) noexcept {
|
static constexpr T const *dataof(T const (&arr)[N]) noexcept {
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
constexpr static T *dataof(T (&arr)[N]) noexcept {
|
static constexpr T *dataof(T (&arr)[N]) noexcept {
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -61,7 +61,7 @@ struct trait<T[N], false, false> {
|
|||||||
template <typename C, bool B>
|
template <typename C, bool B>
|
||||||
struct trait<C, true, B> {
|
struct trait<C, true, B> {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr static auto dataof(T &&c) noexcept(noexcept(c.data())) {
|
static constexpr auto dataof(T &&c) noexcept(noexcept(c.data())) {
|
||||||
return std::forward<T>(c).data();
|
return std::forward<T>(c).data();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -69,7 +69,7 @@ struct trait<C, true, B> {
|
|||||||
template <typename C>
|
template <typename C>
|
||||||
struct trait<C, false, true> {
|
struct trait<C, false, true> {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr static auto dataof(T &&c) noexcept(noexcept(c.Data())) {
|
static constexpr auto dataof(T &&c) noexcept(noexcept(c.Data())) {
|
||||||
return std::forward<T>(c).Data();
|
return std::forward<T>(c).Data();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -77,11 +77,11 @@ struct trait<C, false, true> {
|
|||||||
template <typename C>
|
template <typename C>
|
||||||
struct trait<C, false, false> {
|
struct trait<C, false, false> {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr static T const *dataof(std::initializer_list<T> il) noexcept {
|
static constexpr T const *dataof(std::initializer_list<T> il) noexcept {
|
||||||
return il.begin();
|
return il.begin();
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr static T const *dataof(T const *p) noexcept {
|
static constexpr T const *dataof(T const *p) noexcept {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -54,7 +54,7 @@ bool unfold_tuple_fmt_to(fmt_context &ctx, Tp const &tp, std::index_sequence<I..
|
|||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
bool context_to_string(fmt_context &f_ctx, context<T...> const &l_ctx) noexcept {
|
bool context_to_string(fmt_context &f_ctx, context<T...> const &l_ctx) noexcept {
|
||||||
constexpr static char types[] = {
|
static constexpr char types[] = {
|
||||||
'T', 'D', 'I', 'W', 'E', 'F',
|
'T', 'D', 'I', 'W', 'E', 'F',
|
||||||
};
|
};
|
||||||
LIBIMP_TRY {
|
LIBIMP_TRY {
|
||||||
|
|||||||
@ -41,27 +41,27 @@ struct generic_traits {
|
|||||||
using storage_t = std::tuple<T, std::error_code>;
|
using storage_t = std::tuple<T, std::error_code>;
|
||||||
|
|
||||||
/// \brief Custom initialization.
|
/// \brief Custom initialization.
|
||||||
constexpr static void init_code(storage_t &code) noexcept {
|
static constexpr void init_code(storage_t &code) noexcept {
|
||||||
code = {{}, std::error_code(-1, std::generic_category())};
|
code = {{}, std::error_code(-1, std::generic_category())};
|
||||||
}
|
}
|
||||||
constexpr static void init_code(storage_t &code, T value, std::error_code const &ec) noexcept {
|
static constexpr void init_code(storage_t &code, T value, std::error_code const &ec) noexcept {
|
||||||
code = {value, ec};
|
code = {value, ec};
|
||||||
}
|
}
|
||||||
constexpr static void init_code(storage_t &code, T value) noexcept {
|
static constexpr void init_code(storage_t &code, T value) noexcept {
|
||||||
code = {value, {}};
|
code = {value, {}};
|
||||||
}
|
}
|
||||||
constexpr static void init_code(storage_t &code, std::error_code const &ec) noexcept {
|
static constexpr void init_code(storage_t &code, std::error_code const &ec) noexcept {
|
||||||
code = {{}, ec};
|
code = {{}, ec};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Custom type data acquisition.
|
/// \brief Custom type data acquisition.
|
||||||
constexpr static T get_value(storage_t const &code) noexcept {
|
static constexpr T get_value(storage_t const &code) noexcept {
|
||||||
return std::get<0>(code);
|
return std::get<0>(code);
|
||||||
}
|
}
|
||||||
constexpr static bool get_ok(storage_t const &code) noexcept {
|
static constexpr bool get_ok(storage_t const &code) noexcept {
|
||||||
return !std::get<1>(code);
|
return !std::get<1>(code);
|
||||||
}
|
}
|
||||||
constexpr static std::error_code get_error(storage_t const &code) noexcept {
|
static constexpr std::error_code get_error(storage_t const &code) noexcept {
|
||||||
return std::get<1>(code);
|
return std::get<1>(code);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -72,18 +72,18 @@ struct default_traits<void, ___> {
|
|||||||
using storage_t = std::error_code;
|
using storage_t = std::error_code;
|
||||||
|
|
||||||
/// \brief Custom initialization.
|
/// \brief Custom initialization.
|
||||||
constexpr static void init_code(storage_t &code) noexcept {
|
static constexpr void init_code(storage_t &code) noexcept {
|
||||||
code = std::error_code(-1, std::generic_category());
|
code = std::error_code(-1, std::generic_category());
|
||||||
}
|
}
|
||||||
constexpr static void init_code(storage_t &code, std::error_code const &ec) noexcept {
|
static constexpr void init_code(storage_t &code, std::error_code const &ec) noexcept {
|
||||||
code = ec;
|
code = ec;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Custom type data acquisition.
|
/// \brief Custom type data acquisition.
|
||||||
constexpr static bool get_ok(storage_t const &code) noexcept {
|
static constexpr bool get_ok(storage_t const &code) noexcept {
|
||||||
return !code;
|
return !code;
|
||||||
}
|
}
|
||||||
constexpr static std::error_code get_error(storage_t const &code) noexcept {
|
static constexpr std::error_code get_error(storage_t const &code) noexcept {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ struct default_traits<void, ___> {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct default_traits<T, std::enable_if_t<std::is_integral<T>::value>> : generic_traits<T> {
|
struct default_traits<T, std::enable_if_t<std::is_integral<T>::value>> : generic_traits<T> {
|
||||||
/// \brief Custom initialization.
|
/// \brief Custom initialization.
|
||||||
constexpr static void init_code(typename generic_traits<T>::storage_t &code,
|
static constexpr void init_code(typename generic_traits<T>::storage_t &code,
|
||||||
T value, bool ok) noexcept {
|
T value, bool ok) noexcept {
|
||||||
code = {value, ok ? std::error_code() : std::error_code(-1, std::generic_category())};
|
code = {value, ok ? std::error_code() : std::error_code(-1, std::generic_category())};
|
||||||
}
|
}
|
||||||
@ -107,11 +107,11 @@ struct default_traits<T, std::enable_if_t<std::is_integral<T>::value>> : generic
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct default_traits<T, std::enable_if_t<std::is_pointer<T>::value>> : generic_traits<T> {
|
struct default_traits<T, std::enable_if_t<std::is_pointer<T>::value>> : generic_traits<T> {
|
||||||
/// \brief Custom initialization.
|
/// \brief Custom initialization.
|
||||||
constexpr static void init_code(typename generic_traits<T>::storage_t &code,
|
static constexpr void init_code(typename generic_traits<T>::storage_t &code,
|
||||||
std::nullptr_t, std::error_code const &ec) noexcept {
|
std::nullptr_t, std::error_code const &ec) noexcept {
|
||||||
code = {nullptr, ec};
|
code = {nullptr, ec};
|
||||||
}
|
}
|
||||||
constexpr static void init_code(typename generic_traits<T>::storage_t &code,
|
static constexpr void init_code(typename generic_traits<T>::storage_t &code,
|
||||||
std::nullptr_t) noexcept {
|
std::nullptr_t) noexcept {
|
||||||
code = {nullptr, std::error_code(-1, std::generic_category())};
|
code = {nullptr, std::error_code(-1, std::generic_category())};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -163,7 +163,7 @@ class block_pool<0, 0> {
|
|||||||
using central_cache_pool_t = central_cache_pool<block_t, 0>;
|
using central_cache_pool_t = central_cache_pool<block_t, 0>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr static std::size_t block_size = 0;
|
static constexpr std::size_t block_size = 0;
|
||||||
|
|
||||||
block_pool() noexcept : cursor_(central_cache_pool_t::instance().aqueire()) {}
|
block_pool() noexcept : cursor_(central_cache_pool_t::instance().aqueire()) {}
|
||||||
~block_pool() noexcept {
|
~block_pool() noexcept {
|
||||||
@ -202,7 +202,7 @@ class block_pool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr static std::size_t block_size = BlockSize;
|
static constexpr std::size_t block_size = BlockSize;
|
||||||
|
|
||||||
block_pool() noexcept : cursor_(expand()) {}
|
block_pool() noexcept : cursor_(expand()) {}
|
||||||
~block_pool() noexcept {
|
~block_pool() noexcept {
|
||||||
|
|||||||
@ -494,7 +494,7 @@ public:
|
|||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
class small_storage {
|
class small_storage {
|
||||||
|
|
||||||
constexpr static std::size_t storage_size = sizeof(holder<void *, false>) - sizeof(void *) + N;
|
static constexpr std::size_t storage_size = sizeof(holder<void *, false>) - sizeof(void *) + N;
|
||||||
static_assert(storage_size >= sizeof(holder<void *, false>), "N is not large enough to hold a pointer.");
|
static_assert(storage_size >= sizeof(holder<void *, false>), "N is not large enough to hold a pointer.");
|
||||||
|
|
||||||
alignas(std::max_align_t) std::array<::LIBIMP::byte, storage_size> storage_;
|
alignas(std::max_align_t) std::array<::LIBIMP::byte, storage_size> storage_;
|
||||||
|
|||||||
@ -21,7 +21,7 @@ LIBIMP_NAMESPACE_BEG_
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct sfmt_policy {
|
struct sfmt_policy {
|
||||||
constexpr static std::size_t aligned_size = 32U;
|
static constexpr std::size_t aligned_size = 32U;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Policy = sfmt_policy>
|
template <typename Policy = sfmt_policy>
|
||||||
|
|||||||
@ -93,7 +93,7 @@ void test_queue(std::size_t np, std::size_t nc) {
|
|||||||
};
|
};
|
||||||
circular_queue<Data, PR, CR> que;
|
circular_queue<Data, PR, CR> que;
|
||||||
|
|
||||||
constexpr static std::uint32_t loop_size = 10'0000;
|
static constexpr std::uint32_t loop_size = 10'0000;
|
||||||
|
|
||||||
std::atomic<std::uint64_t> sum {0};
|
std::atomic<std::uint64_t> sum {0};
|
||||||
std::atomic<std::size_t> running {np};
|
std::atomic<std::size_t> running {np};
|
||||||
|
|||||||
@ -95,7 +95,7 @@ void test_unicast(std::size_t np, std::size_t nc) {
|
|||||||
LIBIMP_LOG_();
|
LIBIMP_LOG_();
|
||||||
log.info("\n\tStart with: ", imp::nameof<PC>(), ", ", np, " producers, ", nc, " consumers...");
|
log.info("\n\tStart with: ", imp::nameof<PC>(), ", ", np, " producers, ", nc, " consumers...");
|
||||||
|
|
||||||
constexpr static std::uint32_t loop_size = 100'0000;
|
static constexpr std::uint32_t loop_size = 100'0000;
|
||||||
|
|
||||||
concur::element<std::uint64_t> circ[32] {};
|
concur::element<std::uint64_t> circ[32] {};
|
||||||
PC pc;
|
PC pc;
|
||||||
@ -232,7 +232,7 @@ void test_broadcast(std::size_t np, std::size_t nc) {
|
|||||||
typename concur::traits<PC>::header hdr {imp::make_span(circ)};
|
typename concur::traits<PC>::header hdr {imp::make_span(circ)};
|
||||||
ASSERT_TRUE(hdr.valid());
|
ASSERT_TRUE(hdr.valid());
|
||||||
|
|
||||||
constexpr static std::uint32_t loop_size = 10'0000;
|
static constexpr std::uint32_t loop_size = 10'0000;
|
||||||
|
|
||||||
std::atomic<std::uint64_t> sum {0};
|
std::atomic<std::uint64_t> sum {0};
|
||||||
std::atomic<std::size_t> running {np};
|
std::atomic<std::size_t> running {np};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user