µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os-idle.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#if defined(OS_USE_OS_APP_CONFIG_H)
13#include <cmsis-plus/os-app-config.h>
14#endif
15
16#include <cmsis-plus/rtos/os.h>
17
18// ----------------------------------------------------------------------------
19
20#if defined(__clang__)
21#pragma clang diagnostic ignored "-Wc++98-compat"
22#endif
23
24// ----------------------------------------------------------------------------
25
26using namespace os;
27using namespace os::rtos;
28
29// ----------------------------------------------------------------------------
30
31void*
33
34// os-thread.h
35// void
36// os_rtos_idle_actions (void);
37
56bool __attribute__ ((weak))
58{
59 return false;
60}
61
62void __attribute__ ((weak))
64{
65 while (!scheduler::terminated_threads_list_.empty ())
66 {
68 {
69 // ----- Enter critical section ---------------------------------------
71 node = const_cast<internal::waiting_thread_node*> (
72 scheduler::terminated_threads_list_.head ());
73 node->unlink ();
74 // ----- Exit critical section ----------------------------------------
75 }
76 node->thread_->internal_destroy_ ();
77
79 }
80
81#if defined(OS_HAS_INTERRUPTS_STACK)
82 // Simple test to verify that the interrupts
83 // did not underflow the stack.
84 assert (rtos::interrupts::stack ()->check_bottom_magic ());
85#endif
86
88 {
89 port::scheduler::wait_for_interrupt ();
90 }
91}
92
93#if !defined(OS_USE_RTOS_PORT_SCHEDULER) || defined(__DOXYGEN__)
94
98extern thread* os_idle_thread;
99
100thread* os_idle_thread;
101
102#pragma GCC diagnostic push
103#if defined(__clang__)
104#pragma clang diagnostic ignored "-Wexit-time-destructors"
105#pragma clang diagnostic ignored "-Wglobal-constructors"
106#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
107#endif
108
109#if defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS)
110
112 "idle", os_idle, nullptr
113};
114
115#else
116
117static std::unique_ptr<thread> os_idle_thread_;
118
119#endif /* defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS) */
120
121#pragma GCC diagnostic pop
122
123void __attribute__ ((weak))
125{
126#if defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS)
127
128 // The thread object instance was created by the static constructors.
129 os_idle_thread = &os_idle_thread_;
130
131#else
132
133 thread::attributes attr = thread::initializer;
135
136 // No need for an explicit delete, it is deallocated by the unique_ptr.
137 os_idle_thread_
138 = std::unique_ptr<thread> (new thread ("idle", os_idle, nullptr, attr));
139
140 os_idle_thread = os_idle_thread_.get ();
141
142#endif /* defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS) */
143}
144
145void*
146os_idle (thread::func_args_t args __attribute__ ((unused)))
147{
148
149 // The thread was created with the default priority, and the
150 // idle thread must run with th lowest possible priority.
151
152#if defined(OS_BOOL_RTOS_THREAD_IDLE_PRIORITY_BELOW_IDLE)
153 // The CMSIS RTOS validator creates threads with `priority::idle`,
154 // so, to be sure that the system idle thread has the lowest priority,
155 // go one step below the idle priority.
156 this_thread::thread ().priority (thread::priority::idle - 1);
157#else
158 this_thread::thread ().priority (thread::priority::idle);
159#endif
160
161 while (true)
162 {
164
165 // Possibly switch to threads that were resumed during sleep.
167 }
168}
169
173#endif /* !defined(OS_USE_RTOS_PORT_SCHEDULER) */
174
175// ----------------------------------------------------------------------------
Double linked list node, with thread reference.
Definition os-lists.h:59
rtos::thread * thread_
Pointer to waiting thread.
Definition os-lists.h:107
Interrupts critical section RAII helper.
Definition os-sched.h:502
Thread attributes.
Definition os-thread.h:800
std::size_t th_stack_size_bytes
Size of the user defined storage for the thread stack, in bytes.
Definition os-thread.h:861
Template of a POSIX compliant thread with local stack.
Definition os-thread.h:1825
_func_args_t func_args_t
Type of thread function arguments.
Definition os-thread.h:414
Standard thread.
#define OS_INTEGER_RTOS_IDLE_STACK_SIZE_BYTES
Define the idle thread stack size.
void os_startup_create_thread_idle(void)
Create the idle thread.
bool os_rtos_idle_enter_power_saving_mode_hook(void)
Hook to enter a power saving mode.
Definition os-idle.cpp:57
class thread::stack * stack(void)
Get the interrupts stack.
Definition os-core.cpp:583
RTOS namespace.
Definition os-flags.h:37
System namespace.
void yield() noexcept
Yield the CPU to the next ready thread.
void os_rtos_idle_actions(void)
Definition os-idle.cpp:63
void * os_idle(thread::func_args_t args)
Single file µOS++ RTOS definitions.