µ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++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
13#if defined(OS_USE_OS_APP_CONFIG_H)
14#include <cmsis-plus/os-app-config.h>
15#endif
16
18
20
21// ----------------------------------------------------------------------------
22
23#if defined(__clang__)
24#pragma clang diagnostic ignored "-Wc++98-compat"
25#endif
26
27// ----------------------------------------------------------------------------
28
29namespace os
30{
31 namespace utils
32 {
33 // ======================================================================
34
56 void
58 {
59 // Check if not already unlinked.
60 if (unlinked ())
61 {
62 assert(prev_ == nullptr);
63#if defined(OS_TRACE_UTILS_LISTS)
64 trace::printf ("%s() %p nop\n", __func__, this);
65#endif
66 return;
67 }
68
69#if defined(OS_TRACE_UTILS_LISTS)
70 trace::printf ("%s() %p \n", __func__, this);
71#endif
72
73 // Make neighbours point to each other.
74 prev_->next_ = next_;
75 next_->prev_ = prev_;
76
77 // Nullify both pointers in the unlinked node.
78 prev_ = nullptr;
79 next_ = nullptr;
80 }
81
82 // ========================================================================
83
104 void
106 {
107#pragma GCC diagnostic push
108#if defined(__clang__)
109#elif defined(__GNUC__)
110#pragma GCC diagnostic ignored "-Wuseless-cast"
111#endif
112 head_.next (const_cast<static_double_list_links*> (&head_));
113 head_.prev (const_cast<static_double_list_links*> (&head_));
114#pragma GCC diagnostic pop
115 }
116
117 void
120 {
121#if defined(OS_TRACE_UTILS_LISTS)
122 trace::printf ("%s() n=%p after %p\n", __func__, &node, after);
123#endif
124
125 // Unlinked nodes must have both pointers null.
126 // If not, most probably the node was already linked.
127 // Or the memory is corrupted.
128 assert(node.prev () == nullptr);
129 assert(node.next () == nullptr);
130
131 // The `after` node must be linked. Only the `next` pointer is
132 // tested, since only it is used.
133 assert(after->next () != nullptr);
134
135 // Make the new node point to its neighbours.
136 node.prev (after);
137 node.next (after->next ());
138
139 // Make the neighbours point to the node. The order is important.
140 after->next ()->prev (&node);
141 after->next (&node);
142 }
143
144 // ========================================================================
145
151 {
152#if defined(OS_TRACE_UTILS_LISTS_CONSTRUCT) || defined(OS_TRACE_UTILS_LISTS)
153 trace::printf ("%s() %p \n", __func__, this);
154#endif
155
156 clear ();
157 }
158
164 {
165#if defined(OS_TRACE_UTILS_LISTS_CONSTRUCT) || defined(OS_TRACE_UTILS_LISTS)
166 trace::printf ("%s() %p \n", __func__, this);
167#endif
168
169 assert(empty ());
170 }
171
172 } /* namespace utils */
173} /* namespace os */
174
175// ----------------------------------------------------------------------------
double_list()
Construct a list.
Definition lists.cpp:150
~double_list()
Destruct the list.
Definition lists.cpp:163
static_double_list_links head_
A list node used to point to head and tail.
Definition lists.h:482
void insert_after(static_double_list_links &node, static_double_list_links *after)
Insert a new node after existing node.
Definition lists.cpp:118
bool empty(void) const
Check if the list is empty.
Definition lists.h:1028
void clear(void)
Clear the list.
Definition lists.cpp:105
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:60
System namespace.