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:
parent
812c216f0c
commit
da17ebbde7
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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<unsigned> ref_count;
|
||||
kernel_pid_t joining_thread;
|
||||
std::array<char, stack_size> stack;
|
||||
std::array<char, THREAD_STACKSIZE_MAIN> 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 <class F, class... Args>
|
||||
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
|
||||
<thread_data*, typename decay<F>::type, typename decay<Args>::type...>;
|
||||
unique_ptr<func_and_args> p(
|
||||
new func_and_args(m_data.get(), forward<F>(f), forward<Args>(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<func_and_args>, 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;
|
||||
}
|
||||
|
@ -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.");
|
||||
|
Loading…
Reference in New Issue
Block a user