From 58a60b3772ac73dbe2960c5b0ae9e854c6ac029b Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov aka xDimon Date: Wed, 7 Feb 2024 01:03:57 +0300 Subject: [PATCH] fix: hotfixes Signed-off-by: Dmitriy Khaustov aka xDimon --- include/soralog/common.hpp | 65 ------------------------------ include/soralog/event.hpp | 1 - include/soralog/sink.hpp | 3 +- src/impl/sink_to_console.cpp | 2 - test/unit/circular_buffer_test.cpp | 36 ++++++++--------- test/unit/macros_test.cpp | 2 +- test/unit/sink_to_console_test.cpp | 6 +++ 7 files changed, 26 insertions(+), 89 deletions(-) delete mode 100644 include/soralog/common.hpp diff --git a/include/soralog/common.hpp b/include/soralog/common.hpp deleted file mode 100644 index 272ff2d..0000000 --- a/include/soralog/common.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright Quadrivium Co. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -// clang-format off -#if not defined(likely_if) or not defined(unlikely_if) - #if __cplusplus > 201703L - #define likely_if(x) [[likely]] if (x) - #define unlikely_if(x) [[unlikely]] if (x) - #elif defined( __has_builtin) - #if __has_builtin(__builtin_expect) - #define likely_if(x) if (__builtin_expect((x), 1)) - #define unlikely_if(x) if (__builtin_expect((x), 0)) - #else - #define likely_if(x) if (x) - #define unlikely_if(x) if (x) - #endif - #else - #define likely_if(x) if (x) - #define unlikely_if(x) if (x) - #endif -#endif -// clang-format on - -#include - -namespace soralog::fmt { - - using namespace ::fmt; - - template - inline auto format(Format format, Args &&...args) { - if constexpr (std::is_constructible_v<::fmt::format_string>) { - return ::fmt::format(format, std::forward(args)...); - } else { - return ::fmt::vformat( - format, ::fmt::make_format_args(std::forward(args)...)); - } - } - - template - auto format_to_n(OutputIt out, size_t size, const Format &format, - Args &&...args) { - if constexpr (sizeof...(args) == 0) { - struct R { - OutputIt out; - size_t size; - }; - auto f = ::fmt::detail_exported::compile_string_to_view(format); - auto n = std::min(size, std::size(f)); - return R{std::copy_n(std::begin(f), n, out), n}; - } else { - return ::fmt::vformat_to_n( - out, size, - ::fmt::detail_exported::compile_string_to_view(format), - ::fmt::make_format_args(args...)); - } - } - -} // namespace soralog::fmt diff --git a/include/soralog/event.hpp b/include/soralog/event.hpp index 3f92863..8ae370d 100644 --- a/include/soralog/event.hpp +++ b/include/soralog/event.hpp @@ -15,7 +15,6 @@ #include #include -#include #include #include #include diff --git a/include/soralog/sink.hpp b/include/soralog/sink.hpp index eb83d60..ee0fb30 100644 --- a/include/soralog/sink.hpp +++ b/include/soralog/sink.hpp @@ -14,7 +14,6 @@ #include #include -#include #include #ifdef NDEBUG @@ -24,7 +23,7 @@ #endif #if not defined(likely_if) -#if __cplusplus > 201703L +#if __cplusplus >= 202002L #define likely_if(x) [[likely]] if (x) #elif defined(__has_builtin) #if __has_builtin(__builtin_expect) diff --git a/src/impl/sink_to_console.cpp b/src/impl/sink_to_console.cpp index da5cecf..7e7b048 100644 --- a/src/impl/sink_to_console.cpp +++ b/src/impl/sink_to_console.cpp @@ -15,8 +15,6 @@ #include #include -#include - namespace soralog { namespace { diff --git a/test/unit/circular_buffer_test.cpp b/test/unit/circular_buffer_test.cpp index 397980d..954d6cd 100644 --- a/test/unit/circular_buffer_test.cpp +++ b/test/unit/circular_buffer_test.cpp @@ -7,8 +7,8 @@ #include -#if __cplusplus > 201703L -#include +#if __cplusplus >= 202002L +#include #endif #include "soralog/impl/sink_to_file.hpp" @@ -159,13 +159,13 @@ TEST_F(CircularBufferTest, PutGetMt) { std::atomic_size_t i = 0; std::atomic_size_t n = 100; -#if __cplusplus > 201703L - std::barrier barrier(3); +#if __cplusplus >= 202002L + std::latch latch(3); #endif std::thread prod([&] { -#if __cplusplus > 201703L - barrier.arrive_and_wait(); +#if __cplusplus >= 202002L + latch.arrive_and_wait(); #endif while (i < n) { std::cout << "w" << i << std::endl; @@ -181,8 +181,8 @@ TEST_F(CircularBufferTest, PutGetMt) { }); std::thread cons([&] { -#if __cplusplus > 201703L - barrier.arrive_and_wait(); +#if __cplusplus >= 202002L + latch.arrive_and_wait(); #endif while (i < n) { std::cout << "r" << std::endl; @@ -195,8 +195,8 @@ TEST_F(CircularBufferTest, PutGetMt) { } }); -#if __cplusplus > 201703L - barrier.arrive_and_wait(); +#if __cplusplus >= 202002L + latch.arrive_and_wait(); #endif prod.join(); cons.join(); @@ -207,13 +207,13 @@ TEST_F(CircularBufferTest, Mutual) { CircularBuffer testee(capacity); -#if __cplusplus > 201703L - std::barrier barrier(3); +#if __cplusplus >= 202002L + std::latch latch(3); #endif std::thread prod([&] { -#if __cplusplus > 201703L - barrier.arrive_and_wait(); +#if __cplusplus >= 202002L + latch.arrive_and_wait(); #endif if (auto ref = testee.put('*')) { std::cout << "put " << ref->c() // @@ -224,8 +224,8 @@ TEST_F(CircularBufferTest, Mutual) { }); std::thread cons([&] { -#if __cplusplus > 201703L - barrier.arrive_and_wait(); +#if __cplusplus >= 202002L + latch.arrive_and_wait(); #endif std::this_thread::sleep_for(std::chrono::milliseconds(50)); if (auto ref = testee.get()) { @@ -235,8 +235,8 @@ TEST_F(CircularBufferTest, Mutual) { } }); -#if __cplusplus > 201703L - barrier.arrive_and_wait(); +#if __cplusplus >= 202002L + latch.arrive_and_wait(); #endif prod.join(); cons.join(); diff --git a/test/unit/macros_test.cpp b/test/unit/macros_test.cpp index 781ffbf..7a109a2 100644 --- a/test/unit/macros_test.cpp +++ b/test/unit/macros_test.cpp @@ -21,7 +21,7 @@ class MacrosTest : public ::testing::Test { void log(Level lvl, const Format &format, Args &&...args) { last_level = lvl; size_t len = - fmt::vformat_to_n( + ::fmt::vformat_to_n( message_buf.begin(), message_buf.size(), ::fmt::detail_exported::compile_string_to_view(format), ::fmt::make_format_args(args...)) diff --git a/test/unit/sink_to_console_test.cpp b/test/unit/sink_to_console_test.cpp index 1b9698a..1ed3e9f 100644 --- a/test/unit/sink_to_console_test.cpp +++ b/test/unit/sink_to_console_test.cpp @@ -9,7 +9,9 @@ #include "soralog/impl/sink_to_console.hpp" +#if __cplusplus >= 202002L #include +#endif using namespace soralog; using namespace testing; @@ -116,10 +118,14 @@ TEST_F(SinkToConsoleTest, MultithreadLogging) { size_t treads_n = 10; size_t iters_n = 100; +#if __cplusplus >= 202002L std::latch latch(treads_n); +#endif auto task = [&] { +#if __cplusplus >= 202002L latch.arrive_and_wait(); +#endif std::mutex m; for (auto i = 0; i < iters_n; ++i) { logger->debug("iteration {}.1", i);