Pigweed
 
Loading...
Searching...
No Matches
pw::ThreadAttrs Class Reference

#include <attrs.h>

Public Member Functions

constexpr ThreadAttrs ()
 Initializes attributes to their backend-defined defaults.
 
constexpr ThreadAttrs (const ThreadAttrs &)=default
 Thread attributes can be copied to share properties between threads.
 
constexpr ThreadAttrsoperator= (const ThreadAttrs &)=default
 
constexpr const char * name () const
 Name hint as a null-terminated string. Never null.
 
constexpr ThreadAttrsset_name (const char *name)
 
constexpr ThreadAttrsset_name (std::nullptr_t)=delete
 
constexpr ThreadPriority priority () const
 
constexpr ThreadAttrsset_priority (ThreadPriority priority)
 Sets a thread priority hint.
 
constexpr auto native_stack () const
 
constexpr auto native_stack_pointer () const
 
constexpr auto native_stack_size () const
 
constexpr size_t stack_size_bytes () const
 Returns the size of the stack in bytes.
 
constexpr ThreadAttrsset_stack_size_bytes (size_t stack_size_bytes)
 
template<size_t kStackSizeBytes>
constexpr ThreadAttrsset_stack (ThreadStack< kStackSizeBytes > &stack)
 
constexpr ThreadAttrsclear_stack ()
 Clears a previous call to set_stack.
 
constexpr bool has_external_stack () const
 

Detailed Description

Generic attributes of a thread. ThreadAttrs is used with a ThreadContext to create threads.

ThreadAtts provides three attributes: name, priority, stack size, and stack location. These attributes should be considered only as hints – the pw_thread backend may not support them.

Member Function Documentation

◆ has_external_stack()

constexpr bool pw::ThreadAttrs::has_external_stack ( ) const
inlineconstexpr

True if the ThreadAttrs use an externally allocated stack, rather than one integrated with the ThreadContext.

◆ native_stack()

constexpr auto pw::ThreadAttrs::native_stack ( ) const
inlineconstexpr

Returns a span of the native stack to use for this thread. The stack may not be in terms of bytes! Backends that use void* for stacks return a std::byte span. If the backend doesn't support user-specified stacks,

This function is NOT constexpr if the backend uses void* for stacks.

◆ native_stack_pointer()

constexpr auto pw::ThreadAttrs::native_stack_pointer ( ) const
inlineconstexpr

Returns a pointer to the native stack to use for this thread.

Warning
This function is NOT portable!

◆ native_stack_size()

constexpr auto pw::ThreadAttrs::native_stack_size ( ) const
inlineconstexpr

Returns the size of the stack in native units (not necessarily bytes), using the native type (typically an unsigned integer).

Warning
This function is NOT portable!

◆ set_stack()

template<size_t kStackSizeBytes>
constexpr ThreadAttrs & pw::ThreadAttrs::set_stack ( ThreadStack< kStackSizeBytes > &  stack)
inlineconstexpr

Sets the thread to use the provided stack, instead of a stack integrated into the ThreadContext.

◆ set_stack_size_bytes()

constexpr ThreadAttrs & pw::ThreadAttrs::set_stack_size_bytes ( size_t  stack_size_bytes)
inlineconstexpr

Sets the thread stack size to use for a stack provided by the ThreadContext. If 0, the thread backend's minimum stack size is used.

Precondition
An external stack has not been set with set_stack().

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