µ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::rtos::thread::stack Class Reference

Thread stack. More...

#include <cmsis-plus/rtos/os.h>

Public Types

using allocation_element_t = os::rtos::port::stack::allocation_element_t
 Type of a stack allocation element.
 
using element_t = os::rtos::port::stack::element_t
 Type of a stack element.
 

Public Member Functions

Constructors & Destructor
 stack ()
 Construct a thread stack object instance.
 
 ~stack ()=default
 Destruct the stack object instance.
 
Public Member Functions
void clear (void)
 Clear the stack pointer and size.
 
void set (stack::element_t *address, std::size_t size_bytes)
 Set the stack address and size.
 
void initialize (void)
 Align the pointers and initialise to a known pattern.
 
stack::element_tbottom (void)
 Get the stack lowest reserved address.
 
stack::element_ttop (void)
 Get the top stack address.
 
std::size_t size (void)
 Get the stack size.
 
bool check_bottom_magic (void)
 Check if bottom magic word is still there.
 
bool check_top_magic (void)
 Check if top magic word is still there.
 
std::size_t available (void)
 Compute how much available stack remains.
 

Static Public Member Functions

Public Static Member Functions
static std::size_t min_size (void)
 Get the min stack size.
 
static std::size_t min_size (std::size_t size_bytes)
 Set the min stack size.
 
static std::size_t default_size (void)
 Get the default stack size.
 
static std::size_t default_size (std::size_t size_bytes)
 Set the default stack size.
 

Static Public Attributes

static const element_t magic = os::rtos::port::stack::magic
 

Detailed Description

This class does not contain the stack space itself, it is allocated outside, but stores the address and the size of the stack.

It also manages the global variables storing the min and default stack sizes.

Definition at line 432 of file os-thread.h.

Member Typedef Documentation

◆ allocation_element_t

using os::rtos::thread::stack::allocation_element_t = os::rtos::port::stack::allocation_element_t

For alignment reasons, the stack is allocated in larger chunks, usually 8-bytes long on Cortex-M cores.

Definition at line 451 of file os-thread.h.

◆ element_t

using os::rtos::thread::stack::element_t = os::rtos::port::stack::element_t

The stack is organised as an array of platform words (usually 4-bytes long on Cortex-M cores).

Definition at line 442 of file os-thread.h.

Constructor & Destructor Documentation

◆ stack()

os::rtos::thread::stack::stack ( )
inline
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 2122 of file os-thread.h.

2123 {
2124 clear ();
2125 }
void clear(void)
Clear the stack pointer and size.
Definition os-thread.h:2131

◆ ~stack()

os::rtos::thread::stack::~stack ( )
default

Member Function Documentation

◆ available()

std::size_t os::rtos::thread::stack::available ( void  )
Parameters
None.
Returns
Number of available bytes.

Count the number of bytes where the magic is still there.

Warning
: For large stacks it may be an expensive operation.
Cannot be invoked from Interrupt Service Routines.

Definition at line 202 of file os-thread.cpp.

203 {
204#pragma GCC diagnostic push
205#if defined(__clang__)
206#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
207#endif
208 element_t* p = bottom_address_;
209 std::size_t count = 0;
210 while (*p == magic)
211 {
212 count += sizeof (element_t);
213 ++p;
214 }
215#pragma GCC diagnostic pop
216
217 return count;
218 }
os::rtos::port::stack::element_t element_t
Type of a stack element.
Definition os-thread.h:442
static const element_t magic
Definition os-thread.h:454

Referenced by os_terminate_goodbye().

◆ bottom()

thread::stack::element_t * os::rtos::thread::stack::bottom ( void  )
inline
Parameters
None.
Returns
The address of the stack reserved area.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 2152 of file os-thread.h.

2153 {
2154 return bottom_address_;
2155 }

◆ check_bottom_magic()

bool os::rtos::thread::stack::check_bottom_magic ( void  )
inline
Parameters
None.
Return values
trueThe magic word is still there.
falseThe magic word was overwritten.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 2184 of file os-thread.h.

2185 {
2186 return *bottom () == stack::magic;
2187 }
stack::element_t * bottom(void)
Get the stack lowest reserved address.
Definition os-thread.h:2152

References magic.

◆ check_top_magic()

bool os::rtos::thread::stack::check_top_magic ( void  )
inline
Parameters
None.
Return values
trueThe magic word is still there.
falseThe magic word was overwritten.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 2193 of file os-thread.h.

2194 {
2195 return *top () == stack::magic;
2196 }
stack::element_t * top(void)
Get the top stack address.
Definition os-thread.h:2161

References magic.

◆ clear()

void os::rtos::thread::stack::clear ( void  )
inline
Parameters
None.
Returns
Nothing
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 2131 of file os-thread.h.

2132 {
2133 bottom_address_ = nullptr;
2134 size_bytes_ = 0;
2135 }

◆ default_size() [1/2]

std::size_t os::rtos::thread::stack::default_size ( std::size_t  size_bytes)
inlinestatic
Parameters
[in]size_bytesDefault stack size in bytes.
Returns
The previous value of the default stack size in bytes.
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 2231 of file os-thread.h.

2232 {
2233 assert (size_bytes != 0);
2234 assert (size_bytes >= min_size_bytes_);
2235
2236 std::size_t tmp = default_size_bytes_;
2237 default_size_bytes_ = size_bytes;
2238 return tmp;
2239 }

◆ default_size() [2/2]

std::size_t os::rtos::thread::stack::default_size ( void  )
inlinestatic
Parameters
None.
Returns
The default stack size in bytes.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 2222 of file os-thread.h.

2223 {
2224 return default_size_bytes_;
2225 }

Referenced by os::rtos::thread::thread(), os_thread_stack_get_default_size(), and os_thread_stack_set_default_size().

◆ initialize()

void os::rtos::thread::stack::initialize ( void  )
Parameters
None.
Returns
Nothing.

◆ min_size() [1/2]

std::size_t os::rtos::thread::stack::min_size ( std::size_t  size_bytes)
inlinestatic
Parameters
[in]size_bytesMinimum stack size in bytes.
Returns
The previous value of the min stack size in bytes.
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 2211 of file os-thread.h.

2212 {
2213 std::size_t tmp = min_size_bytes_;
2214 min_size_bytes_ = size_bytes;
2215 return tmp;
2216 }

◆ min_size() [2/2]

std::size_t os::rtos::thread::stack::min_size ( void  )
inlinestatic
Parameters
None.
Returns
The min stack size in bytes.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 2202 of file os-thread.h.

2203 {
2204 return min_size_bytes_;
2205 }

Referenced by os::rtos::thread::thread(), os_thread_stack_get_min_size(), and os_thread_stack_set_min_size().

◆ set()

void os::rtos::thread::stack::set ( stack::element_t address,
std::size_t  size_bytes 
)
inline
Parameters
[in]addressBottom stack address.
[in]size_bytesReserved stack size, in bytes.
Parameters
None.
Returns
Nothing
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 2141 of file os-thread.h.

2142 {
2143 assert (size_bytes >= min_size_bytes_);
2144 bottom_address_ = address;
2145 size_bytes_ = size_bytes;
2146 }

Referenced by _start().

◆ size()

std::size_t os::rtos::thread::stack::size ( void  )
inline
Parameters
None.
Returns
The stack size in bytes.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 2175 of file os-thread.h.

2176 {
2177 return size_bytes_;
2178 }

Referenced by os_terminate_goodbye().

◆ top()

thread::stack::element_t * os::rtos::thread::stack::top ( void  )
inline
Parameters
None.
Returns
The address after the last stack element.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 2161 of file os-thread.h.

2162 {
2163#pragma GCC diagnostic push
2164#if defined(__clang__)
2165#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
2166#endif
2167 return bottom_address_ + (size_bytes_ / sizeof (element_t));
2168#pragma GCC diagnostic pop
2169 }

Member Data Documentation

◆ magic

const element_t os::rtos::thread::stack::magic = os::rtos::port::stack::magic
static

Definition at line 454 of file os-thread.h.

Referenced by check_bottom_magic(), and check_top_magic().


The documentation for this class was generated from the following files: