13#if defined(OS_USE_OS_APP_CONFIG_H)
14#include <cmsis-plus/os-app-config.h>
22#pragma clang diagnostic ignored "-Wc++98-compat"
29#if defined(OS_HAS_INTERRUPTS_STACK)
61 bool is_started_ =
false;
69 state_t lock_state_ = state::init;
72#pragma GCC diagnostic push
74#pragma clang diagnostic ignored "-Wglobal-constructors"
75#pragma clang diagnostic ignored "-Wexit-time-destructors"
84 thread::threads_list top_threads_list_;
86#pragma GCC diagnostic pop
88#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
90 bool is_preemptive_ =
false;
92#pragma GCC diagnostic push
94#pragma clang diagnostic ignored "-Wpadded"
95#elif defined(__GNUC__)
96#pragma GCC diagnostic ignored "-Wpadded"
106#pragma GCC diagnostic pop
110#pragma GCC diagnostic push
111#if defined(__clang__)
112#elif defined(__GNUC__)
113#pragma GCC diagnostic ignored "-Winvalid-offsetof"
115 static_assert(offsetof(tiny_thread_t, errno_) == offsetof(
thread, errno_),
"adjust tiny_thread_t members");
116#pragma GCC diagnostic pop
118#pragma GCC diagnostic push
119#if defined(__clang__)
120#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
122 tiny_thread_t tiny_thread;
123#pragma GCC diagnostic pop
125#pragma GCC diagnostic push
126#pragma GCC diagnostic ignored "-Wcast-align"
127 thread*
volatile current_thread_ =
reinterpret_cast<thread*
>(&tiny_thread);
128#pragma GCC diagnostic pop
130#pragma GCC diagnostic push
131#if defined(__clang__)
132#pragma clang diagnostic ignored "-Wglobal-constructors"
133#pragma clang diagnostic ignored "-Wexit-time-destructors"
135 internal::ready_threads_list ready_threads_list_;
136#pragma GCC diagnostic pop
139#pragma GCC diagnostic push
140#if defined(__clang__)
141#pragma clang diagnostic ignored "-Wglobal-constructors"
142#pragma clang diagnostic ignored "-Wexit-time-destructors"
144 internal::terminated_threads_list terminated_threads_list_;
145#pragma GCC diagnostic pop
162#if defined(OS_TRACE_RTOS_SCHEDULER)
169#if defined(OS_USE_RTOS_PORT_SCHEDULER)
201#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
203 scheduler::statistics::context_switches_ = 0;
207#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
209 scheduler::statistics::cpu_cycles_ = 0;
210 scheduler::statistics::switch_timestamp_ =
hrclock.
now ();
214#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
229#if defined(OS_TRACE_RTOS_SCHEDULER)
235#if defined(OS_USE_RTOS_PORT_SCHEDULER)
246 tmp = is_preemptive_;
247 is_preemptive_ = state;
260 thread::threads_list&
265 return top_threads_list_;
269 return th->children_;
333 internal_link_node (internal::waiting_threads_list& list,
334 internal::waiting_thread_node& node)
341 node.thread_->waiting_node_ = &node;
347 internal_unlink_node (internal::waiting_thread_node& node)
351 interrupts::critical_section ics;
355 node.thread_->waiting_node_ =
nullptr;
362 internal_link_node (internal::waiting_threads_list& list,
363 internal::waiting_thread_node& node,
364 internal::clock_timestamps_list& timeout_list,
365 internal::timeout_thread_node& timeout_node)
372 node.thread_->waiting_node_ = &node;
377 timeout_list.link (timeout_node);
378 timeout_node.thread.clock_node_ = &timeout_node;
382 internal_unlink_node (internal::waiting_thread_node& node,
383 internal::timeout_thread_node& timeout_node)
386 interrupts::critical_section ics;
390 timeout_node.thread.clock_node_ =
nullptr;
391 timeout_node.unlink ();
395 node.thread_->waiting_node_ =
nullptr;
402#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
405 internal_switch_threads (
void)
407#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
412#pragma GCC diagnostic push
413#if defined(__clang__)
414#elif defined(__GNUC__)
415#pragma GCC diagnostic ignored "-Wuseless-cast"
422 - scheduler::statistics::switch_timestamp_);
424#pragma GCC diagnostic pop
427 scheduler::statistics::cpu_cycles_ += delta;
430 scheduler::current_thread_->statistics_.cpu_cycles_ += delta;
433 scheduler::statistics::switch_timestamp_ = now;
442 scheduler::current_thread_->internal_relink_running_ ();
445 scheduler::current_thread_ =
446 scheduler::ready_threads_list_.unlink_head ();
456#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
459 scheduler::statistics::context_switches_++;
462 scheduler::current_thread_->statistics_.context_switches_++;
472#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
478#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
558#if defined(OS_HAS_INTERRUPTS_STACK) || defined(__DOXYGEN__)
573 return &interrupts_stack;
622 name_ (name != nullptr ? name :
"-")
632#pragma GCC diagnostic push
633#if defined(__clang__)
634#pragma clang diagnostic ignored "-Wreserved-identifier"
635#elif defined(__GNUC__)
636#pragma GCC diagnostic ignored "-Wredundant-decls"
640#pragma GCC diagnostic pop
virtual void start(void) override
virtual timestamp_t now(void) override
Tell the current time.
virtual void start(void) override
Initialise and make the RTC tick.
virtual void start(void) override
object_named()
Construct a named object instance.
Interrupts critical section RAII helper.
POSIX compliant thread, using the default RTOS allocator.
#define OS_BOOL_RTOS_SCHEDULER_PREEMPTIVE
Default definition for the preemption flag.
int printf(const char *format,...)
Write a formatted string to the trace device.
int * __errno(void)
Per-thread error support.
clock_highres hrclock
The high resolution clock object instance.
clock_rtc rtclock
The real time clock object instance.
port::clock::timestamp_t timestamp_t
Type of variables holding clock time stamps.
clock_systick sysclock
The system clock object instance.
class thread::stack * stack(void)
Get the interrupts stack.
bool in_handler_mode(void)
Check if the CPU is in handler mode.
result_t initialize(void)
void prepare_suspend(void)
@ ok
Function completed; no errors or events occurred.
port::scheduler::state_t state_t
Type of variables holding scheduler state codes.
void start(void)
Start the RTOS scheduler.
thread::threads_list & children_threads(thread *th)
Get the children threads.
result_t initialize(void)
Initialise the RTOS scheduler.
bool preemptive(void)
Check if the scheduler is in preemptive mode.
bool locked(void)
Check if the scheduler is locked.
uint64_t duration_t
Type of variables holding durations in CPU cycles.
uint64_t counter_t
Type of variables holding context switches counters.
int * __errno(void)
Implementation of the library __errno() function.
uint32_t result_t
Type of values returned by RTOS functions.
#define os_assert_throw(__e, __er)
Assert or throw a system error exception.
#define os_assert_err(__e, __er)
Assert or return an error.
Single file µOS++ RTOS definitions.
@ suspended
Not present in the READY list, waiting for an event.