Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. OS abstraction layers
  5. pw_thread
  6. OS abstraction layers
  7. Backends
  8. Eclipse ThreadX
  9. pw_thread_threadx
  10. pw::thread::threadx::Options Class Reference
pw::thread::threadx::Options Class Reference

Overview

pw::thread::Options for ThreadX.

Example usage:

// Uses the default priority and time slice interval (which may be
// disabled), but specifies a custom name and pre-allocated context.
// Note that the preemption threshold is disabled by default.
pw::Thread example_thread(
.set_name("example_thread")
.set_context(example_thread_context),
example_thread_function);
// Specifies the name, priority, time slice interval, and pre-allocated
// context, but does not use a preemption threshold.
pw::Thread static_example_thread(
.set_name("static_example_thread")
.set_priority(kFooPriority)
.set_context(example_thread_context),
example_thread_function);
Definition: thread.h:69
Definition: options.h:54
constexpr Options & set_priority(UINT priority)
Definition: options.h:82
constexpr Options & set_context(Context &context)
Definition: options.h:145
constexpr Options & set_name(const char *name)
Definition: options.h:67
constexpr Options & set_time_slice_interval(ULONG time_slice_interval)
Definition: options.h:132
Inheritance diagram for pw::thread::threadx::Options:
pw::thread::Options

Public Member Functions

constexpr Options (const Options &)=default
 
constexpr Options (Options &&)=default
 
constexpr Options & set_name (const char *name)
 
constexpr Options & set_priority (UINT priority)
 
constexpr Options & set_preemption_threshold (UINT preemption_threshold)
 
constexpr Options & set_time_slice_interval (ULONG time_slice_interval)
 
constexpr Options & set_context (Context &context)
 

Member Function Documentation

◆ set_context()

constexpr Options & pw::thread::threadx::Options::set_context ( Context &  context)
inlineconstexpr

Sets the pre-allocated context (all memory needed to run a thread). Note that this is required for this thread creation backend. The Context can either be constructed with an externally provided pw::span<ULONG> stack or the templated form of ContextWithStack<kStackSizeWords> can be used.

Parameters
[in,out]contextPre-allocated Context for the thread.
Returns
A reference to this Options instance for chaining.

◆ set_name()

constexpr Options & pw::thread::threadx::Options::set_name ( const char *  name)
inlineconstexpr

Sets the name for the ThreadX thread. Note that this will be deep-copied into the context and may be truncated based on PW_THREAD_THREADX_CONFIG_MAX_THREAD_NAME_LEN.

Parameters
[in]nameNull-terminated thread name string.
Returns
A reference to this Options instance for chaining.

◆ set_preemption_threshold()

constexpr Options & pw::thread::threadx::Options::set_preemption_threshold ( UINT  preemption_threshold)
inlineconstexpr

Optionally sets the initial preemption threshold for the ThreadX thread.

Only priorities higher than this level (i.e. lower number) are allowed to preempt this thread. In other words, this allows the thread to specify the priority ceiling for disabling preemption. Threads that have a higher priority than the ceiling are still allowed to preempt while those with less than or equal to the ceiling are not allowed to preempt.

Not setting the preemption threshold or explicitly specifying a value equal to the priority disables the preemption threshold.

Time slicing is disabled while the preemption threshold is enabled (i.e. not equal to the priority), even if a time slice interval was specified.

The preemption threshold can be adjusted at run time; this only sets the initial threshold.

Precondition
preemption_threshold <= priority.
Parameters
[in]preemption_thresholdInitial ThreadX preemption threshold.
Returns
A reference to this Options instance for chaining.

◆ set_priority()

constexpr Options & pw::thread::threadx::Options::set_priority ( UINT  priority)
inlineconstexpr

Sets the priority for the ThreadX thread from 0 through PW_THREAD_THREADX_CONFIG_MIN_PRIORITY (typically 31), where a value of 0 represents the highest priority. See ThreadX tx_thread_create for more detail.

Precondition
priority <= PW_THREAD_THREADX_CONFIG_MIN_PRIORITY.
Parameters
[in]priorityThreadX priority level.
Returns
A reference to this Options instance for chaining.

◆ set_time_slice_interval()

constexpr Options & pw::thread::threadx::Options::set_time_slice_interval ( ULONG  time_slice_interval)
inlineconstexpr

Sets the number of ticks this thread is allowed to run before other ready threads of the same priority are given a chance to run.

Time slicing is disabled while the preemption threshold is enabled (i.e. not equal to the priority), even if a time slice interval was specified.

A value of TX_NO_TIME_SLICE (a value of 0) disables time-slicing of this thread.

Using time slicing results in a slight amount of system overhead; threads with a unique priority should consider TX_NO_TIME_SLICE.

Parameters
[in]time_slice_intervalTime slice interval in ticks, or TX_NO_TIME_SLICE (0) to disable time-slicing.
Returns
A reference to this Options instance for chaining.

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