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