1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys /cpp11-compat: remove pseudo anonymous namespaces

This commit is contained in:
Karl Fessel 2023-04-17 15:58:01 +02:00
parent 812c216f0c
commit da17ebbde7
3 changed files with 15 additions and 31 deletions

View File

@ -34,10 +34,6 @@
namespace riot { 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 * @brief A time point for timed wait, as clocks from the standard are not
* available on RIOT. * available on RIOT.
@ -94,9 +90,9 @@ class time_point {
private: private:
timex_t m_handle; timex_t m_handle;
void inline adjust_overhead() { 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.seconds += secs;
m_handle.microseconds -= (secs * microsecs_in_sec); m_handle.microseconds -= (secs * US_PER_SEC);
} }
}; };

View File

@ -45,28 +45,17 @@
namespace riot { 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. * @brief Holds context data for the thread.
*/ */
struct thread_data { struct thread_data {
thread_data() : ref_count{2}, joining_thread{thread_uninitialized} { thread_data() : ref_count{2}, joining_thread{KERNEL_PID_UNDEF} {
// nop // nop
} }
/** @cond INTERNAL */ /** @cond INTERNAL */
std::atomic<unsigned> ref_count; std::atomic<unsigned> ref_count;
kernel_pid_t joining_thread; kernel_pid_t joining_thread;
std::array<char, stack_size> stack; std::array<char, THREAD_STACKSIZE_MAIN> stack;
/** @endcond */ /** @endcond */
}; };
@ -103,7 +92,7 @@ public:
/** /**
* @brief Creates a uninitialized thread id. * @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. * @brief Create a thread id from a native handle.
*/ */
@ -236,7 +225,7 @@ public:
/** /**
* @brief Per default, an uninitialized thread is created. * @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. * @brief Create a thread from a functor and arguments for it.
* @param[in] f Functor to run as a thread. * @param[in] f Functor to run as a thread.
@ -254,7 +243,7 @@ public:
* @brief Move constructor. * @brief Move constructor.
*/ */
inline thread(thread&& t) noexcept : m_handle{t.m_handle} { 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); std::swap(m_data, t.m_data);
} }
@ -284,7 +273,7 @@ public:
* @return `true` if the thread is joinable, `false` otherwise. * @return `true` if the thread is joinable, `false` otherwise.
*/ */
inline bool joinable() const noexcept { 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 * @brief Block until the thread finishes. Leads to an error if the thread is
@ -340,7 +329,7 @@ void* thread_proxy(void* vp) {
catch (...) { catch (...) {
// nop // nop
} }
if (data->joining_thread != thread_uninitialized) { if (data->joining_thread != KERNEL_PID_UNDEF) {
thread_wakeup(data->joining_thread); thread_wakeup(data->joining_thread);
} }
} }
@ -351,15 +340,14 @@ void* thread_proxy(void* vp) {
/** @endcond */ /** @endcond */
template <class F, class... Args> template <class F, class... Args>
thread::thread(F&& f, Args&&... args) thread::thread(F&& f, Args&&... args) : m_data{new thread_data} {
: m_data{new thread_data} {
using namespace std; using namespace std;
using func_and_args = tuple using func_and_args = tuple
<thread_data*, typename decay<F>::type, typename decay<Args>::type...>; <thread_data*, typename decay<F>::type, typename decay<Args>::type...>;
unique_ptr<func_and_args> p( unique_ptr<func_and_args> p(
new func_and_args(m_data.get(), forward<F>(f), forward<Args>(args)...)); new func_and_args(m_data.get(), forward<F>(f), forward<Args>(args)...));
m_handle = thread_create( 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<func_and_args>, p.get(), "riot_cpp_thread"); &thread_proxy<func_and_args>, p.get(), "riot_cpp_thread");
if (m_handle >= 0) { if (m_handle >= 0) {
p.release(); p.release();
@ -371,11 +359,11 @@ thread::thread(F&& f, Args&&... args)
} }
inline thread& thread::operator=(thread&& other) noexcept { inline thread& thread::operator=(thread&& other) noexcept {
if (m_handle != thread_uninitialized) { if (m_handle != KERNEL_PID_UNDEF) {
std::terminate(); std::terminate();
} }
m_handle = other.m_handle; m_handle = other.m_handle;
other.m_handle = thread_uninitialized; other.m_handle = KERNEL_PID_UNDEF;
std::swap(m_data, other.m_data); std::swap(m_data, other.m_data);
return *this; return *this;
} }

View File

@ -44,7 +44,7 @@ void thread::join() {
m_data->joining_thread = thread_getpid(); m_data->joining_thread = thread_getpid();
thread_sleep(); thread_sleep();
} }
m_handle = thread_uninitialized; m_handle = KERNEL_PID_UNDEF;
} else { } else {
throw system_error(make_error_code(errc::invalid_argument), throw system_error(make_error_code(errc::invalid_argument),
"Can not join an unjoinable thread."); "Can not join an unjoinable thread.");
@ -54,7 +54,7 @@ void thread::join() {
void thread::detach() { void thread::detach() {
if (joinable()) { if (joinable()) {
m_handle = thread_uninitialized; m_handle = KERNEL_PID_UNDEF;
} else { } else {
throw system_error(make_error_code(errc::invalid_argument), throw system_error(make_error_code(errc::invalid_argument),
"Can not detach an unjoinable thread."); "Can not detach an unjoinable thread.");