zpp
Zephyr C++20 Framework
zpp::thread_prio Class Reference

Thread priority. More...

#include <thread_prio.hpp>

Public Member Functions

constexpr thread_prio () noexcept
 Default constructor initializing priority to zero. More...
 
constexpr thread_prio (int prio) noexcept
 Constructor initializing priority to prio. More...
 
constexpr int native_value () const noexcept
 Get the Zephyr native priority value. More...
 

Static Public Member Functions

static constexpr thread_prio highest_coop () noexcept
 Get the most prior cooperative priority. More...
 
static constexpr thread_prio lowest_coop () noexcept
 Get the least prior cooperative priority. More...
 
static constexpr thread_prio highest_preempt () noexcept
 Get the most prior preemptive priority. More...
 
static constexpr thread_prio lowest_preempt () noexcept
 Get the least prior preemptive priority. More...
 
static constexpr thread_prio min_coop_numeric () noexcept
 Get the minium coop numeric value. More...
 
static constexpr thread_prio max_coop_numeric () noexcept
 Get the minium coop numeric value. More...
 
static constexpr thread_prio min_preempt_numeric () noexcept
 Get the minium preempt numeric value. More...
 
static constexpr thread_prio max_preempt_numeric () noexcept
 Get the minium preempt numeric value. More...
 
static constexpr thread_prio min_numeric () noexcept
 Get the minium numeric value. More...
 
static constexpr thread_prio max_numeric () noexcept
 Get the maxium numeric value. More...
 
static constexpr thread_prio coop (int prio) noexcept
 Create a cooperative priority value. More...
 
static constexpr thread_prio preempt (int prio) noexcept
 Create a preemptive priority value. More...
 

Detailed Description

Thread priority.

Definition at line 18 of file thread_prio.hpp.

Constructor & Destructor Documentation

◆ thread_prio() [1/2]

constexpr zpp::thread_prio::thread_prio ( )
inlineconstexprnoexcept

Default constructor initializing priority to zero.

Definition at line 23 of file thread_prio.hpp.

24  {
25  }

Referenced by coop(), highest_coop(), highest_preempt(), lowest_coop(), lowest_preempt(), and preempt().

◆ thread_prio() [2/2]

constexpr zpp::thread_prio::thread_prio ( int  prio)
inlineexplicitconstexprnoexcept

Constructor initializing priority to prio.

Parameters
prioThe priority value to use for initialization

Definition at line 32 of file thread_prio.hpp.

33  : m_prio(prio)
34  {
35  if (m_prio < -CONFIG_NUM_COOP_PRIORITIES) {
36  m_prio = -CONFIG_NUM_COOP_PRIORITIES;
37  } else if (m_prio > (CONFIG_NUM_PREEMPT_PRIORITIES - 1)) {
38  m_prio = CONFIG_NUM_PREEMPT_PRIORITIES - 1;
39  }
40 
41  __ASSERT_NO_MSG(m_prio == prio);
42  }

Member Function Documentation

◆ coop()

static constexpr thread_prio zpp::thread_prio::coop ( int  prio)
inlinestaticconstexprnoexcept

Create a cooperative priority value.

Parameters
priothe value, from 0 to highest_coop
Returns
The priority value

Definition at line 174 of file thread_prio.hpp.

175  {
176  return thread_prio( lowest_coop().native_value() - prio );
177  }
constexpr thread_prio() noexcept
Default constructor initializing priority to zero.
Definition: thread_prio.hpp:23
constexpr int native_value() const noexcept
Get the Zephyr native priority value.
Definition: thread_prio.hpp:49
static constexpr thread_prio lowest_coop() noexcept
Get the least prior cooperative priority.
Definition: thread_prio.hpp:69

References thread_prio(), lowest_coop(), and native_value().

◆ highest_coop()

static constexpr thread_prio zpp::thread_prio::highest_coop ( )
inlinestaticconstexprnoexcept

Get the most prior cooperative priority.

Returns
The most prior cooperative priority

Definition at line 59 of file thread_prio.hpp.

60  {
61  return thread_prio(-CONFIG_NUM_COOP_PRIORITIES);
62  }

References thread_prio().

Referenced by min_coop_numeric().

◆ highest_preempt()

static constexpr thread_prio zpp::thread_prio::highest_preempt ( )
inlinestaticconstexprnoexcept

Get the most prior preemptive priority.

Returns
The most prior preemptive priority

Definition at line 79 of file thread_prio.hpp.

80  {
81  return thread_prio(0);
82  }

References thread_prio().

Referenced by min_preempt_numeric(), and preempt().

◆ lowest_coop()

static constexpr thread_prio zpp::thread_prio::lowest_coop ( )
inlinestaticconstexprnoexcept

Get the least prior cooperative priority.

Returns
The least prior cooperative priority

Definition at line 69 of file thread_prio.hpp.

70  {
71  return thread_prio(-1);
72  }

References thread_prio().

Referenced by coop(), and max_coop_numeric().

◆ lowest_preempt()

static constexpr thread_prio zpp::thread_prio::lowest_preempt ( )
inlinestaticconstexprnoexcept

Get the least prior preemptive priority.

Returns
The least prior preemptive priority

Definition at line 89 of file thread_prio.hpp.

90  {
91  return thread_prio(CONFIG_NUM_PREEMPT_PRIORITIES - 1);
92  }

References thread_prio().

Referenced by max_preempt_numeric(), and preempt().

◆ max_coop_numeric()

static constexpr thread_prio zpp::thread_prio::max_coop_numeric ( )
inlinestaticconstexprnoexcept

Get the minium coop numeric value.

The maxium coop numric value is the lowest coop thread priority

Returns
The smallest numeric value

Definition at line 115 of file thread_prio.hpp.

116  {
117  return lowest_coop();
118  }

References lowest_coop().

◆ max_numeric()

static constexpr thread_prio zpp::thread_prio::max_numeric ( )
inlinestaticconstexprnoexcept

Get the maxium numeric value.

Returns
The highest numeric value

Definition at line 161 of file thread_prio.hpp.

162  {
163  return max_preempt_numeric();
164  }
static constexpr thread_prio max_preempt_numeric() noexcept
Get the minium preempt numeric value.

References max_preempt_numeric().

◆ max_preempt_numeric()

static constexpr thread_prio zpp::thread_prio::max_preempt_numeric ( )
inlinestaticconstexprnoexcept

Get the minium preempt numeric value.

The maxium coop numric value is the lowest thread priority

Returns
The largest numeric value

Definition at line 141 of file thread_prio.hpp.

142  {
143  return lowest_preempt();
144  }
static constexpr thread_prio lowest_preempt() noexcept
Get the least prior preemptive priority.
Definition: thread_prio.hpp:89

References lowest_preempt().

Referenced by max_numeric().

◆ min_coop_numeric()

static constexpr thread_prio zpp::thread_prio::min_coop_numeric ( )
inlinestaticconstexprnoexcept

Get the minium coop numeric value.

The minium coop numric value is the highest thread priority

Returns
The smallest numeric value

Definition at line 102 of file thread_prio.hpp.

103  {
104  return highest_coop();
105  }
static constexpr thread_prio highest_coop() noexcept
Get the most prior cooperative priority.
Definition: thread_prio.hpp:59

References highest_coop().

Referenced by min_numeric().

◆ min_numeric()

static constexpr thread_prio zpp::thread_prio::min_numeric ( )
inlinestaticconstexprnoexcept

Get the minium numeric value.

Returns
The smallest numeric value

Definition at line 151 of file thread_prio.hpp.

152  {
153  return min_coop_numeric();
154  }
static constexpr thread_prio min_coop_numeric() noexcept
Get the minium coop numeric value.

References min_coop_numeric().

◆ min_preempt_numeric()

static constexpr thread_prio zpp::thread_prio::min_preempt_numeric ( )
inlinestaticconstexprnoexcept

Get the minium preempt numeric value.

The minium preempt numric value is the highest preempt thread priority

Returns
The smallest numeric value

Definition at line 128 of file thread_prio.hpp.

129  {
130  return highest_preempt();
131  }
static constexpr thread_prio highest_preempt() noexcept
Get the most prior preemptive priority.
Definition: thread_prio.hpp:79

References highest_preempt().

◆ native_value()

constexpr int zpp::thread_prio::native_value ( ) const
inlineconstexprnoexcept

Get the Zephyr native priority value.

Returns
the Zephyr native priority value

Definition at line 49 of file thread_prio.hpp.

50  {
51  return m_prio;
52  }

Referenced by coop(), zpp::thread_attr::native_prio(), and preempt().

◆ preempt()

static constexpr thread_prio zpp::thread_prio::preempt ( int  prio)
inlinestaticconstexprnoexcept

Create a preemptive priority value.

Parameters
priothe value, from 0 to highest_preempt
Returns
The priority value

Definition at line 186 of file thread_prio.hpp.

187  {
188  return (prio >= CONFIG_NUM_PREEMPT_PRIORITIES) ?
189  highest_preempt() :
191  }

References thread_prio(), highest_preempt(), lowest_preempt(), and native_value().

Referenced by main(), and ZTEST().


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