µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
lists.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#if defined(OS_USE_OS_APP_CONFIG_H)
13#include <cmsis-plus/os-app-config.h>
14#endif
15
17
19
20// ----------------------------------------------------------------------------
21
22#if defined(__clang__)
23#pragma clang diagnostic ignored "-Wc++98-compat"
24#elif defined(__GNUC__)
25#pragma GCC diagnostic ignored "-Wmissing-include-dirs"
26#endif
27
28// ----------------------------------------------------------------------------
29
30namespace os
31{
32 namespace utils
33 {
34 // ========================================================================
35
58 void
60 {
61 // Check if not already unlinked.
62 if (unlinked ())
63 {
64 assert (prev_ == nullptr);
65#if defined(OS_TRACE_UTILS_LISTS)
66 trace::printf ("%s() %p nop\n", __func__, this);
67#endif
68 return;
69 }
70
71#if defined(OS_TRACE_UTILS_LISTS)
72 trace::printf ("%s() %p \n", __func__, this);
73#endif
74
75 // Make neighbours point to each other.
76 prev_->next_ = next_;
77 next_->prev_ = prev_;
78
79 // Nullify both pointers in the unlinked node.
80 prev_ = nullptr;
81 next_ = nullptr;
82 }
83
84 // ========================================================================
85
107 void
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 }
119
120 void
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 }
146
147 // ========================================================================
148
154 {
155#if defined(OS_TRACE_UTILS_LISTS_CONSTRUCT) || defined(OS_TRACE_UTILS_LISTS)
156 trace::printf ("%s() %p \n", __func__, this);
157#endif
158
159 clear ();
160 }
161
167 {
168#if defined(OS_TRACE_UTILS_LISTS_CONSTRUCT) || defined(OS_TRACE_UTILS_LISTS)
169 trace::printf ("%s() %p \n", __func__, this);
170#endif
171
172 assert (empty ());
173 }
174
175 } /* namespace utils */
176} /* namespace os */
177
178// ----------------------------------------------------------------------------
double_list()
Construct a list.
Definition lists.cpp:153
~double_list()
Destruct the list.
Definition lists.cpp:166
static_double_list_links head_
A list node used to point to head and tail.
Definition lists.h:473
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
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
System namespace.