33#pragma clang diagnostic ignored "-Wc++98-compat"
40#if defined(OS_HAS_INTERRUPTS_STACK)
72 bool is_started_ =
false;
80 state_t lock_state_ = state::init;
83#pragma GCC diagnostic push
85#pragma clang diagnostic ignored "-Wglobal-constructors"
86#pragma clang diagnostic ignored "-Wexit-time-destructors"
95 thread::threads_list top_threads_list_;
97#pragma GCC diagnostic pop
99#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
101 bool is_preemptive_ =
false;
103#pragma GCC diagnostic push
104#pragma GCC diagnostic ignored "-Wpadded"
113#pragma GCC diagnostic pop
117#pragma GCC diagnostic push
118#pragma GCC diagnostic ignored "-Winvalid-offsetof"
119 static_assert(offsetof(tiny_thread_t, errno_) == offsetof(
thread, errno_),
"adjust tiny_thread_t members");
120#pragma GCC diagnostic pop
122#pragma GCC diagnostic push
123#if defined(__clang__)
124#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
126 tiny_thread_t tiny_thread;
127#pragma GCC diagnostic pop
129 thread*
volatile current_thread_ =
reinterpret_cast<thread*
>(&tiny_thread);
131#pragma GCC diagnostic push
132#if defined(__clang__)
133#pragma clang diagnostic ignored "-Wglobal-constructors"
134#pragma clang diagnostic ignored "-Wexit-time-destructors"
136 internal::ready_threads_list ready_threads_list_;
137#pragma GCC diagnostic pop
140#pragma GCC diagnostic push
141#if defined(__clang__)
142#pragma clang diagnostic ignored "-Wglobal-constructors"
143#pragma clang diagnostic ignored "-Wexit-time-destructors"
145 internal::terminated_threads_list terminated_threads_list_;
146#pragma GCC diagnostic pop
163#if defined(OS_TRACE_RTOS_SCHEDULER)
170#if defined(OS_USE_RTOS_PORT_SCHEDULER)
202#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
204 scheduler::statistics::context_switches_ = 0;
208#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
210 scheduler::statistics::cpu_cycles_ = 0;
211 scheduler::statistics::switch_timestamp_ =
hrclock.
now ();
215#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
230#if defined(OS_TRACE_RTOS_SCHEDULER)
236#if defined(OS_USE_RTOS_PORT_SCHEDULER)
247 tmp = is_preemptive_;
248 is_preemptive_ = state;
261 thread::threads_list&
266 return top_threads_list_;
270 return th->children_;
334 internal_link_node (internal::waiting_threads_list& list,
335 internal::waiting_thread_node& node)
342 node.thread_->waiting_node_ = &node;
348 internal_unlink_node (internal::waiting_thread_node& node)
352 interrupts::critical_section ics;
356 node.thread_->waiting_node_ =
nullptr;
363 internal_link_node (internal::waiting_threads_list& list,
364 internal::waiting_thread_node& node,
365 internal::clock_timestamps_list& timeout_list,
366 internal::timeout_thread_node& timeout_node)
373 node.thread_->waiting_node_ = &node;
378 timeout_list.link (timeout_node);
379 timeout_node.thread.clock_node_ = &timeout_node;
383 internal_unlink_node (internal::waiting_thread_node& node,
384 internal::timeout_thread_node& timeout_node)
387 interrupts::critical_section ics;
391 timeout_node.thread.clock_node_ =
nullptr;
392 timeout_node.unlink ();
396 node.thread_->waiting_node_ =
nullptr;
403#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
406 internal_switch_threads (
void)
408#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
417 - scheduler::statistics::switch_timestamp_);
420 scheduler::statistics::cpu_cycles_ += delta;
423 scheduler::current_thread_->statistics_.cpu_cycles_ += delta;
426 scheduler::statistics::switch_timestamp_ = now;
435 scheduler::current_thread_->internal_relink_running_ ();
438 scheduler::current_thread_ =
439 scheduler::ready_threads_list_.unlink_head ();
449#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
452 scheduler::statistics::context_switches_++;
455 scheduler::current_thread_->statistics_.context_switches_++;
465#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
471#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
551#if defined(OS_HAS_INTERRUPTS_STACK) || defined(__DOXYGEN__)
566 return &interrupts_stack;
616 name_ (name != nullptr ? name :
"-")
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.