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

Ordered list of time stamp nodes. More...

#include <os-lists.h>

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

Public Member Functions

Constructors & Destructor
 clock_timestamps_list ()
 Construct a list of clock time stamps.
 
 ~clock_timestamps_list ()
 Destruct the list.
 
Public Member Functions
void link (timestamp_node &node)
 Add a new thread node to the list.
 
volatile timestamp_nodehead (void) const
 Get list head.
 
void check_timestamp (port::clock::timestamp_t now)
 Check list time stamps.
 
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 665 of file os-lists.h.

Constructor & Destructor Documentation

◆ clock_timestamps_list()

os::rtos::internal::clock_timestamps_list::clock_timestamps_list ( )
inline

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

958 {
959 }

◆ ~clock_timestamps_list()

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

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

962 {
963 }

Member Function Documentation

◆ check_timestamp()

void os::rtos::internal::clock_timestamps_list::check_timestamp ( port::clock::timestamp_t  now)
Parameters
[in]nowThe current clock time stamp.
Returns
Nothing.

With the list ordered, check if the list head time stamp was reached and run the node action.

Repeat for all nodes that have overdue time stamps.

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

491 {
492 if (head_.next () == nullptr)
493 {
494 // This happens before the constructors are executed.
495 return;
496 }
497
498 // Multiple threads can wait for the same time stamp, so
499 // iterate until a node with future time stamp is identified.
500 for (;;)
501 {
502 // ----- Enter critical section -----------------------------------
503 interrupts::critical_section ics;
504
505 if (empty ())
506 {
507 break;
508 }
509#pragma GCC diagnostic push
510#if defined(__clang__)
511#elif defined(__GNUC__)
512#pragma GCC diagnostic ignored "-Wnull-dereference"
513#endif
514 clock::timestamp_t head_ts = head ()->timestamp;
515#pragma GCC diagnostic pop
516 if (now >= head_ts)
517 {
518#if defined(OS_TRACE_RTOS_LISTS_CLOCKS)
519 trace::printf ("%s() %u \n", __func__,
520 static_cast<uint32_t> (sysclock.now ()));
521#endif
522 const_cast<timestamp_node*> (head ())->action ();
523 }
524 else
525 {
526 break;
527 }
528 // ----- Exit critical section ------------------------------------
529 }
530 }
virtual timestamp_t now(void)
Tell the current time, possibly adjusted for epoch.
volatile timestamp_node * head(void) const
Get list head.
Definition os-lists.h:966
port::clock::timestamp_t timestamp
Time stamp when the next action will be performed.
Definition os-lists.h:198
static_double_list_links head_
A list node used to point to head and tail.
Definition lists.h:473
bool empty(void) const
Check if the list is empty.
Definition lists.h:1001
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
port::clock::timestamp_t timestamp_t
Type of variables holding clock time stamps.
Definition os-clocks.h:88
clock_systick sysclock
The system clock object instance.

References os::utils::static_double_list::empty(), head(), os::utils::static_double_list::head_, os::utils::static_double_list_links::next(), os::rtos::clock::now(), os::trace::printf(), os::rtos::sysclock, and os::rtos::internal::timestamp_node::timestamp.

◆ 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 }

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(), os::rtos::internal::ready_threads_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(), check_timestamp(), link(), os::rtos::internal::ready_threads_list::link(), os::rtos::internal::waiting_threads_list::link(), os::rtos::internal::waiting_threads_list::resume_one(), and os::rtos::internal::ready_threads_list::unlink_head().

◆ head()

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

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

967 {
968 return static_cast<volatile timestamp_node*> (double_list::head ());
969 }

Referenced by check_timestamp(), and link().

◆ 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 }

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(), link(), os::rtos::internal::ready_threads_list::link(), os::rtos::internal::waiting_threads_list::link(), and os::rtos::internal::terminated_threads_list::link().

◆ link()

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

The list is kept in ascending time stamp order.

Based on time stamp, the node is inserted

  • at the end of the list,
  • at the beginning of the list,
  • in the middle of the list, which requires a partial list traversal (done from the end).

To satisfy the circular double linked list requirements, an empty list still contains the head node with references to itself.

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

414 {
415 clock::timestamp_t timestamp = node.timestamp;
416
417 timeout_thread_node* after = static_cast<timeout_thread_node*> (
418 const_cast<utils::static_double_list_links*> (tail ()));
419
420 if (empty ())
421 {
422 // Insert at the end of the list.
423#if defined(OS_TRACE_RTOS_LISTS_CLOCKS)
424 trace::printf ("clock %s() empty +%u\n", __func__,
425 static_cast<uint32_t> (timestamp));
426#endif
427 }
428 else if (timestamp >= after->timestamp)
429 {
430 // Insert at the end of the list.
431#if defined(OS_TRACE_RTOS_LISTS_CLOCKS)
432 trace::printf ("clock %s() back %u +%u\n", __func__,
433 static_cast<uint32_t> (after->timestamp),
434 static_cast<uint32_t> (timestamp));
435#endif
436 }
437 else if (timestamp < head ()->timestamp)
438 {
439#pragma GCC diagnostic push
440#if defined(__clang__)
441#elif defined(__GNUC__)
442#pragma GCC diagnostic ignored "-Wuseless-cast"
443#endif
444 // Insert at the beginning of the list
445 // and update the new head.
446 after = static_cast<timeout_thread_node*> (
447 const_cast<utils::static_double_list_links*> (&head_));
448#if defined(OS_TRACE_RTOS_LISTS_CLOCKS)
449 trace::printf ("clock %s() front +%u %u\n", __func__,
450 static_cast<uint32_t> (timestamp),
451 static_cast<uint32_t> (head ()->timestamp));
452#endif
453#pragma GCC diagnostic pop
454 }
455 else
456 {
457 // Insert in the middle of the list.
458 // The loop is guaranteed to terminate.
459 while (timestamp < after->timestamp)
460 {
461#pragma GCC diagnostic push
462#if defined(__clang__)
463#elif defined(__GNUC__)
464#pragma GCC diagnostic ignored "-Wuseless-cast"
465#endif
466 after = static_cast<timeout_thread_node*> (
467 const_cast<utils::static_double_list_links*> (
468 after->prev ()));
469 }
470#if defined(OS_TRACE_RTOS_LISTS_CLOCKS)
471 trace::printf ("clock %s() middle %u +%u\n", __func__,
472 static_cast<uint32_t> (after->timestamp),
473 static_cast<uint32_t> (timestamp));
474#endif
475#pragma GCC diagnostic pop
476 }
477
478 insert_after (node, after);
479 }
void insert_after(static_double_list_links &node, static_double_list_links *after)
Insert a new node after existing node.
Definition lists.cpp:121
volatile static_double_list_links * tail(void) const
Get the list tail.
Definition lists.h:1014

References 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::utils::static_double_list::tail(), and os::rtos::internal::timestamp_node::timestamp.

◆ 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().

Member Data Documentation

◆ head_


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