From da17ebbde74d24620525234945dc67b49f7bb621 Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Mon, 17 Apr 2023 15:58:01 +0200 Subject: [PATCH] sys /cpp11-compat: remove pseudo anonymous namespaces --- sys/cpp11-compat/include/riot/chrono.hpp | 8 ++---- sys/cpp11-compat/include/riot/thread.hpp | 34 ++++++++---------------- sys/cpp11-compat/thread.cpp | 4 +-- 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/sys/cpp11-compat/include/riot/chrono.hpp b/sys/cpp11-compat/include/riot/chrono.hpp index 03809c13b0..6ca1bea38a 100644 --- a/sys/cpp11-compat/include/riot/chrono.hpp +++ b/sys/cpp11-compat/include/riot/chrono.hpp @@ -34,10 +34,6 @@ namespace riot { -namespace { -constexpr uint32_t microsecs_in_sec = 1000000; -} // namespace anaonymous - /** * @brief A time point for timed wait, as clocks from the standard are not * available on RIOT. @@ -94,9 +90,9 @@ class time_point { private: timex_t m_handle; void inline adjust_overhead() { - auto secs = m_handle.microseconds / microsecs_in_sec; + auto secs = m_handle.microseconds / US_PER_SEC; m_handle.seconds += secs; - m_handle.microseconds -= (secs * microsecs_in_sec); + m_handle.microseconds -= (secs * US_PER_SEC); } }; diff --git a/sys/cpp11-compat/include/riot/thread.hpp b/sys/cpp11-compat/include/riot/thread.hpp index bc30048a78..8647edbc5e 100644 --- a/sys/cpp11-compat/include/riot/thread.hpp +++ b/sys/cpp11-compat/include/riot/thread.hpp @@ -45,28 +45,17 @@ namespace riot { -namespace { -/** - * @brief Identify uninitialized threads. - */ -constexpr kernel_pid_t thread_uninitialized = -1; -/** - * @brief The stack size for new threads. - */ -constexpr size_t stack_size = THREAD_STACKSIZE_MAIN; -} - /** * @brief Holds context data for the thread. */ struct thread_data { - thread_data() : ref_count{2}, joining_thread{thread_uninitialized} { + thread_data() : ref_count{2}, joining_thread{KERNEL_PID_UNDEF} { // nop } /** @cond INTERNAL */ std::atomic ref_count; kernel_pid_t joining_thread; - std::array stack; + std::array stack; /** @endcond */ }; @@ -103,7 +92,7 @@ public: /** * @brief Creates a uninitialized thread id. */ - inline thread_id() noexcept : m_handle{thread_uninitialized} {} + inline thread_id() noexcept : m_handle{KERNEL_PID_UNDEF} {} /** * @brief Create a thread id from a native handle. */ @@ -236,7 +225,7 @@ public: /** * @brief Per default, an uninitialized thread is created. */ - inline thread() noexcept : m_handle{thread_uninitialized} {} + inline thread() noexcept : m_handle{KERNEL_PID_UNDEF} {} /** * @brief Create a thread from a functor and arguments for it. * @param[in] f Functor to run as a thread. @@ -254,7 +243,7 @@ public: * @brief Move constructor. */ inline thread(thread&& t) noexcept : m_handle{t.m_handle} { - t.m_handle = thread_uninitialized; + t.m_handle = KERNEL_PID_UNDEF; std::swap(m_data, t.m_data); } @@ -284,7 +273,7 @@ public: * @return `true` if the thread is joinable, `false` otherwise. */ inline bool joinable() const noexcept { - return m_handle != thread_uninitialized; + return m_handle != KERNEL_PID_UNDEF; } /** * @brief Block until the thread finishes. Leads to an error if the thread is @@ -340,7 +329,7 @@ void* thread_proxy(void* vp) { catch (...) { // nop } - if (data->joining_thread != thread_uninitialized) { + if (data->joining_thread != KERNEL_PID_UNDEF) { thread_wakeup(data->joining_thread); } } @@ -351,15 +340,14 @@ void* thread_proxy(void* vp) { /** @endcond */ template -thread::thread(F&& f, Args&&... args) - : m_data{new thread_data} { +thread::thread(F&& f, Args&&... args) : m_data{new thread_data} { using namespace std; using func_and_args = tuple ::type, typename decay::type...>; unique_ptr p( new func_and_args(m_data.get(), forward(f), forward(args)...)); m_handle = thread_create( - m_data->stack.data(), stack_size, THREAD_PRIORITY_MAIN - 1, 0, + m_data->stack.data(), m_data->stack.size(), THREAD_PRIORITY_MAIN - 1, 0, &thread_proxy, p.get(), "riot_cpp_thread"); if (m_handle >= 0) { p.release(); @@ -371,11 +359,11 @@ thread::thread(F&& f, Args&&... args) } inline thread& thread::operator=(thread&& other) noexcept { - if (m_handle != thread_uninitialized) { + if (m_handle != KERNEL_PID_UNDEF) { std::terminate(); } m_handle = other.m_handle; - other.m_handle = thread_uninitialized; + other.m_handle = KERNEL_PID_UNDEF; std::swap(m_data, other.m_data); return *this; } diff --git a/sys/cpp11-compat/thread.cpp b/sys/cpp11-compat/thread.cpp index 4895b7e745..e797fced0f 100644 --- a/sys/cpp11-compat/thread.cpp +++ b/sys/cpp11-compat/thread.cpp @@ -44,7 +44,7 @@ void thread::join() { m_data->joining_thread = thread_getpid(); thread_sleep(); } - m_handle = thread_uninitialized; + m_handle = KERNEL_PID_UNDEF; } else { throw system_error(make_error_code(errc::invalid_argument), "Can not join an unjoinable thread."); @@ -54,7 +54,7 @@ void thread::join() { void thread::detach() { if (joinable()) { - m_handle = thread_uninitialized; + m_handle = KERNEL_PID_UNDEF; } else { throw system_error(make_error_code(errc::invalid_argument), "Can not detach an unjoinable thread.");