µ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::internal::ready_threads_list Class Reference

Priority ordered list of threads waiting too run. More...

#include <os-lists.h>

+ Inheritance diagram for os::rtos::internal::ready_threads_list:

Public Member Functions

Constructors & Destructor
 ready_threads_list ()
 Construct a list of waiting threads.
 
 ~ready_threads_list ()
 Destruct the list.
 
Public Member Functions
void link (waiting_thread_node &node)
 Add a new thread node to the list.
 
volatile waiting_thread_nodehead (void) const
 Get list head.
 
threadunlink_head (void)
 Remove the top node from the list.
 
Public Member Functions
bool uninitialized (void) const
 Check if the list is uninitialised.
 
void clear (void)
 Clear the list.
 
bool empty (void) const
 Check if the list is empty.
 
volatile static_double_list_links * tail (void) const
 Get the list tail.
 

Protected Member Functions

Private Member Functions
void insert_after (static_double_list_links &node, static_double_list_links *after)
 Insert a new node after existing node.
 

Protected Attributes

Private Member Variables
static_double_list_links head_
 A list node used to point to head and tail.
 

Detailed Description

Definition at line 458 of file os-lists.h.

Constructor & Destructor Documentation

◆ ready_threads_list()

os::rtos::internal::ready_threads_list::ready_threads_list ( )
inline

The initial list status is empty.

Definition at line 895 of file os-lists.h.

896 {
897 }

◆ ~ready_threads_list()

os::rtos::internal::ready_threads_list::~ready_threads_list ( )
inline

Definition at line 899 of file os-lists.h.

900 {
901 }

Member Function Documentation

◆ clear()

void os::utils::static_double_list::clear ( void  )
inherited
Parameters
None.
Returns
Nothing.

Initialise the mandatory node with links to itself.

Definition at line 108 of file lists.cpp.

109 {
110#pragma GCC diagnostic push
111#if defined(__clang__)
112#elif defined(__GNUC__)
113#pragma GCC diagnostic ignored "-Wuseless-cast"
114#endif
115 head_.next (const_cast<static_double_list_links*> (&head_));
116 head_.prev (const_cast<static_double_list_links*> (&head_));
117#pragma GCC diagnostic pop
118 }
static_double_list_links head_
A list node used to point to head and tail.
Definition lists.h:473

References os::utils::static_double_list::head_, os::utils::static_double_list_links::next(), and os::utils::static_double_list_links::prev().

Referenced by os::utils::double_list::double_list(), link(), and os::rtos::internal::terminated_threads_list::link().

◆ empty()

bool os::utils::static_double_list::empty ( void  ) const
inlineinherited
Parameters
None.
Return values
trueThe list has no nodes.
falseThe list has at least one node.

Definition at line 1001 of file lists.h.

1002 {
1003 // If it points to itself, it is empty.
1004 return (head_.next () == &head_) || (head_.next () == nullptr);
1005 }

References os::utils::static_double_list::head_, and os::utils::static_double_list_links::next().

Referenced by os::utils::double_list::~double_list(), os::rtos::internal::clock_timestamps_list::check_timestamp(), os::rtos::internal::clock_timestamps_list::link(), link(), os::rtos::internal::waiting_threads_list::link(), os::rtos::internal::waiting_threads_list::resume_one(), and unlink_head().

◆ head()

volatile waiting_thread_node * os::rtos::internal::ready_threads_list::head ( void  ) const
inline
Parameters
None.
Returns
Casted pointer to head node.

Definition at line 904 of file os-lists.h.

905 {
906 return static_cast<volatile waiting_thread_node*> (
907 static_double_list::head ());
908 }

Referenced by link(), and unlink_head().

◆ insert_after()

void os::utils::static_double_list::insert_after ( static_double_list_links node,
static_double_list_links after 
)
protectedinherited
Parameters
nodeReference to node to insert.
afterReference to existing node.
Returns
Nothing.

Definition at line 121 of file lists.cpp.

123 {
124#if defined(OS_TRACE_UTILS_LISTS)
125 trace::printf ("%s() n=%p after %p\n", __func__, &node, after);
126#endif
127
128 // Unlinked nodes must have both pointers null.
129 // If not, most probably the node was already linked.
130 // Or the memory is corrupted.
131 assert (node.prev () == nullptr);
132 assert (node.next () == nullptr);
133
134 // The `after` node must be linked. Only the `next` pointer is
135 // tested, since only it is used.
136 assert (after->next () != nullptr);
137
138 // Make the new node point to its neighbours.
139 node.prev (after);
140 node.next (after->next ());
141
142 // Make the neighbours point to the node. The order is important.
143 after->next ()->prev (&node);
144 after->next (&node);
145 }
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59

References os::utils::static_double_list_links::next(), os::utils::static_double_list_links::prev(), and os::trace::printf().

Referenced by os::rtos::internal::thread_children_list::link(), os::rtos::internal::clock_timestamps_list::link(), link(), os::rtos::internal::waiting_threads_list::link(), and os::rtos::internal::terminated_threads_list::link().

◆ link()

void os::rtos::internal::ready_threads_list::link ( waiting_thread_node node)
Parameters
[in]nodeReference to a list node.
Returns
Nothing.

Definition at line 47 of file os-lists.cpp.

48 {
49 if (head_.prev () == nullptr)
50 {
51 // If this is the first time, initialise the list to empty.
52 clear ();
53 }
54
55 thread::priority_t prio = node.thread_->priority ();
56
57 waiting_thread_node* after = static_cast<waiting_thread_node*> (
58 const_cast<utils::static_double_list_links*> (tail ()));
59
60 if (empty ())
61 {
62 // Insert at the end of the list.
63#if defined(OS_TRACE_RTOS_LISTS)
64 trace::printf ("ready %s() empty +%u\n", __func__, prio);
65#endif
66 }
67 else if (prio <= after->thread_->priority ())
68 {
69 // Insert at the end of the list.
70#if defined(OS_TRACE_RTOS_LISTS)
71 trace::printf ("ready %s() back %u +%u \n", __func__,
72 after->thread_->priority (), prio);
73#endif
74 }
75 else if (prio > head ()->thread_->priority ())
76 {
77#pragma GCC diagnostic push
78#if defined(__clang__)
79#elif defined(__GNUC__)
80#pragma GCC diagnostic ignored "-Wuseless-cast"
81#endif
82 // Insert at the beginning of the list.
83 after = static_cast<waiting_thread_node*> (
84 const_cast<utils::static_double_list_links*> (&head_));
85#pragma GCC diagnostic pop
86
87#if defined(OS_TRACE_RTOS_LISTS)
88 trace::printf ("ready %s() front +%u %u \n", __func__, prio,
89 head ()->thread_->priority ());
90#endif
91 }
92 else
93 {
94#pragma GCC diagnostic push
95#if defined(__clang__)
96#elif defined(__GNUC__)
97#pragma GCC diagnostic ignored "-Wuseless-cast"
98#endif
99 // Insert in the middle of the list.
100 // The loop is guaranteed to terminate, and not hit the head.
101 // The weight is relatively small, priority() is not heavy.
102 while (prio > after->thread_->priority ())
103 {
104 after = static_cast<waiting_thread_node*> (
105 const_cast<utils::static_double_list_links*> (
106 after->prev ()));
107 }
108#pragma GCC diagnostic pop
109
110#if defined(OS_TRACE_RTOS_LISTS)
111 trace::printf ("ready %s() middle %u +%u \n", __func__,
112 after->thread_->priority (), prio);
113#endif
114 }
115
116 insert_after (node, after);
117
118 node.thread_->state_ = thread::state::ready;
119 }
volatile waiting_thread_node * head(void) const
Get list head.
Definition os-lists.h:904
void insert_after(static_double_list_links &node, static_double_list_links *after)
Insert a new node after existing node.
Definition lists.cpp:121
bool empty(void) const
Check if the list is empty.
Definition lists.h:1001
void clear(void)
Clear the list.
Definition lists.cpp:108
volatile static_double_list_links * tail(void) const
Get the list tail.
Definition lists.h:1014
uint8_t priority_t
Type of variables holding thread priorities.
Definition os-thread.h:271
@ ready
Present in the READY list and competing for CPU.
Definition os-thread.h:382

References os::utils::static_double_list::clear(), os::utils::static_double_list::empty(), head(), os::utils::static_double_list::head_, os::utils::static_double_list::insert_after(), os::utils::static_double_list_links::prev(), os::trace::printf(), os::rtos::thread::priority(), os::rtos::thread::state::ready, os::utils::static_double_list::tail(), and os::rtos::internal::waiting_thread_node::thread_.

◆ tail()

volatile static_double_list_links * os::utils::static_double_list::tail ( void  ) const
inlineinherited

◆ uninitialized()

bool os::utils::static_double_list::uninitialized ( void  ) const
inlineinherited
Parameters
None.
Return values
trueThe list was not initialised.
falseThe list was initialised.

Definition at line 994 of file lists.h.

995 {
996 // If it points to nowhere, it is not yet initialised.
997 return (head_.prev () == nullptr);
998 }

References os::utils::static_double_list::head_, and os::utils::static_double_list_links::prev().

◆ unlink_head()

thread * os::rtos::internal::ready_threads_list::unlink_head ( void  )
Parameters
None.
Returns
Pointer to thread.

Must be called in a critical section.

Definition at line 126 of file os-lists.cpp.

127 {
128 assert (!empty ());
129
130 thread* th = head ()->thread_;
131
132#if defined(OS_TRACE_RTOS_LISTS)
133 trace::printf ("ready %s() %p %s\n", __func__, th, th->name ());
134#endif
135
136 const_cast<waiting_thread_node*> (head ())->unlink ();
137
138 assert (th != nullptr);
139
140 // Unlinking is immediately followed by a context switch,
141 // so in order to guarantee that the thread is marked as
142 // running, it is saver to do it here.
143
144 th->state_ = thread::state::running;
145 return th;
146 }
rtos::thread * thread_
Pointer to waiting thread.
Definition os-lists.h:107
Standard thread.
int unlink(const char *name)
@ running
Has the CPU and runs.
Definition os-thread.h:386

References os::utils::static_double_list::empty(), head(), os::rtos::internal::object_named::name(), os::trace::printf(), os::rtos::thread::state::running, os::rtos::internal::waiting_thread_node::thread_, and unlink().

Member Data Documentation

◆ head_


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