12#if defined(OS_USE_OS_APP_CONFIG_H)
13#include <cmsis-plus/os-app-config.h>
21#pragma clang diagnostic ignored "-Wc++98-compat"
28#if defined(OS_HAS_INTERRUPTS_STACK)
60 bool is_started_ =
false;
68 state_t lock_state_ = state::init;
71#pragma GCC diagnostic push
73#pragma clang diagnostic ignored "-Wglobal-constructors"
74#pragma clang diagnostic ignored "-Wexit-time-destructors"
83 thread::threads_list top_threads_list_;
85#pragma GCC diagnostic pop
87#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
89 bool is_preemptive_ =
false;
91#pragma GCC diagnostic push
93#pragma clang diagnostic ignored "-Wpadded"
94#elif defined(__GNUC__)
95#pragma GCC diagnostic ignored "-Wpadded"
106#pragma GCC diagnostic pop
110#pragma GCC diagnostic push
111#if defined(__clang__)
112#pragma clang diagnostic ignored "-Winvalid-offsetof"
113#elif defined(__GNUC__)
114#pragma GCC diagnostic ignored "-Winvalid-offsetof"
116 static_assert (offsetof (tiny_thread_t, errno_)
117 == offsetof (
thread, errno_),
118 "adjust tiny_thread_t members");
119#pragma GCC diagnostic pop
121#pragma GCC diagnostic push
122#if defined(__clang__)
123#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
125 tiny_thread_t tiny_thread;
126#pragma GCC diagnostic pop
128#pragma GCC diagnostic push
129#pragma GCC diagnostic ignored "-Wcast-align"
130 thread*
volatile current_thread_
131 =
reinterpret_cast<thread*
> (&tiny_thread);
132#pragma GCC diagnostic pop
134#pragma GCC diagnostic push
135#if defined(__clang__)
136#pragma clang diagnostic ignored "-Wglobal-constructors"
137#pragma clang diagnostic ignored "-Wexit-time-destructors"
139 internal::ready_threads_list ready_threads_list_;
140#pragma GCC diagnostic pop
143#pragma GCC diagnostic push
144#if defined(__clang__)
145#pragma clang diagnostic ignored "-Wglobal-constructors"
146#pragma clang diagnostic ignored "-Wexit-time-destructors"
148 internal::terminated_threads_list terminated_threads_list_;
149#pragma GCC diagnostic pop
166#if defined(OS_TRACE_RTOS_SCHEDULER)
173#if defined(OS_USE_RTOS_PORT_SCHEDULER)
205#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
207 scheduler::statistics::context_switches_ = 0;
211#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
213 scheduler::statistics::cpu_cycles_ = 0;
214 scheduler::statistics::switch_timestamp_ =
hrclock.
now ();
218#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
233#if defined(OS_TRACE_RTOS_SCHEDULER)
239#if defined(OS_USE_RTOS_PORT_SCHEDULER)
250 tmp = is_preemptive_;
251 is_preemptive_ = state;
264 thread::threads_list&
269 return top_threads_list_;
273 return th->children_;
341 internal_link_node (internal::waiting_threads_list& list,
342 internal::waiting_thread_node& node)
349 node.thread_->waiting_node_ = &node;
355 internal_unlink_node (internal::waiting_thread_node& node)
359 interrupts::critical_section ics;
363 node.thread_->waiting_node_ =
nullptr;
370 internal_link_node (internal::waiting_threads_list& list,
371 internal::waiting_thread_node& node,
372 internal::clock_timestamps_list& timeout_list,
373 internal::timeout_thread_node& timeout_node)
380 node.thread_->waiting_node_ = &node;
385 timeout_list.link (timeout_node);
386 timeout_node.thread.clock_node_ = &timeout_node;
390 internal_unlink_node (internal::waiting_thread_node& node,
391 internal::timeout_thread_node& timeout_node)
394 interrupts::critical_section ics;
398 timeout_node.thread.clock_node_ =
nullptr;
399 timeout_node.unlink ();
403 node.thread_->waiting_node_ =
nullptr;
410#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
413 internal_switch_threads (
void)
415#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
420#pragma GCC diagnostic push
421#if defined(__clang__)
422#elif defined(__GNUC__)
423#pragma GCC diagnostic ignored "-Wuseless-cast"
430 now - scheduler::statistics::switch_timestamp_);
432#pragma GCC diagnostic pop
435 scheduler::statistics::cpu_cycles_ += delta;
438 scheduler::current_thread_->statistics_.cpu_cycles_ += delta;
441 scheduler::statistics::switch_timestamp_ = now;
450 scheduler::current_thread_->internal_relink_running_ ();
453 scheduler::current_thread_
454 = scheduler::ready_threads_list_.unlink_head ();
464#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
467 scheduler::statistics::context_switches_++;
470 scheduler::current_thread_->statistics_.context_switches_++;
479#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
485#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
570#if defined(OS_HAS_INTERRUPTS_STACK) || defined(__DOXYGEN__)
585 return &interrupts_stack;
636 : name_ (name != nullptr ? name :
"-")
646#pragma GCC diagnostic push
647#if defined(__clang__)
648#pragma clang diagnostic ignored "-Wreserved-identifier"
649#elif defined(__GNUC__)
650#pragma GCC diagnostic ignored "-Wredundant-decls"
654#pragma GCC diagnostic pop
virtual void start(void) override
Start the clock.
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
Start the clock.
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 pre-emption 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.