utils-lists 4.0.2
The µOS++ Intrusive Lists
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.com/).
3 * Copyright (c) 2016 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
24
25// ----------------------------------------------------------------------------
26
27#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
28#include <micro-os-plus/config.h>
29#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
30
32#include <micro-os-plus/diag/trace.h>
33
34// ----------------------------------------------------------------------------
35
36#if defined(__GNUC__)
37#pragma GCC diagnostic push
38
39#pragma GCC diagnostic ignored "-Waggregate-return"
40#if defined(__clang__)
41#pragma clang diagnostic ignored "-Wc++98-compat"
42#endif
43#endif
44
46{
47 // ==========================================================================
48
57 bool
59 {
60 if (previous_ == nullptr || next_ == nullptr)
61 {
62 assert (previous_ == nullptr);
63 assert (next_ == nullptr);
64 return true;
65 }
66 return false;
67 }
68
82 void
84 {
85 if (uninitialized ())
86 {
87 initialize ();
88 }
89 }
90
100 void
102 {
103#if defined(MICRO_OS_PLUS_TRACE_UTILS_LISTS)
104 trace::printf ("%s() link %p after %p\n", __func__, node, this);
105#endif
106 assert (next_ != nullptr);
107 assert (next_->previous_ != nullptr);
108
109 // Make the new node point to its new neighbours.
110 node->previous_ = this;
111 node->next_ = next_;
112
113 next_->previous_ = node;
114 next_ = node;
115 }
116
126 void
128 {
129#if defined(MICRO_OS_PLUS_TRACE_UTILS_LISTS)
130 trace::printf ("%s() link %p before %p\n", __func__, node, this);
131#endif
132 assert (next_ != nullptr);
133 assert (next_->previous_ != nullptr);
134
135 // Make the new node point to its new neighbours.
136 node->next_ = this;
137 node->previous_ = previous_;
138
139 previous_->next_ = node;
140 previous_ = node;
141 }
142
150 void
152 {
153#if defined(MICRO_OS_PLUS_TRACE_UTILS_LISTS)
154 trace::printf ("%s() %p \n", __func__, this);
155#endif
156
157 // Make neighbours point to each other.
158 // This works even if the node is already unlinked,
159 // so no need for an extra test.
160 previous_->next_ = next_;
161 next_->previous_ = previous_;
162
163 // Reset the unlinked node to the initial state,
164 // with both pointers pointing to itself.
165 initialize ();
166 }
167
175 bool
177 {
178 if (next_ == this || previous_ == this)
179 {
180 assert (next_ == this);
181 assert (previous_ == this);
182 return false;
183 }
184 return true;
185 }
186
187 // ==========================================================================
188
197#if defined(__GNUC__) && !defined(__clang__)
198 // Prevent LTO to optimize out the code.
199 // https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
200 __attribute__ ((noinline, noipa))
201#endif
202 void
204 {
205 next_ = nullptr;
206 previous_ = nullptr;
207 }
208
209 // ==========================================================================
210} // namespace micro_os_plus::utils
211
212#if defined(__GNUC__)
213#pragma GCC diagnostic pop
214#endif
215
216// ----------------------------------------------------------------------------
Main C++ header file with the declarations for the µOS++ lists classes.
The µOS++ utilities definitions.