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
12// ----------------------------------------------------------------------------
13
14#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
15#include <micro-os-plus/config.h>
16#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
17
19#include <micro-os-plus/diag/trace.h>
20
21// ----------------------------------------------------------------------------
22
23#if defined(__GNUC__)
24#pragma GCC diagnostic push
25
26#pragma GCC diagnostic ignored "-Waggregate-return"
27#if defined(__clang__)
28#pragma clang diagnostic ignored "-Wc++98-compat"
29#endif
30#endif
31
33{
34 // ==========================================================================
35
44 bool
46 {
47 if (previous_ == nullptr || next_ == nullptr)
48 {
49 assert (previous_ == nullptr);
50 assert (next_ == nullptr);
51 return true;
52 }
53 return false;
54 }
55
71 void
73 {
74 if (uninitialized ())
75 {
76 initialize ();
77 }
78 }
79
87 void
89 {
90#if defined(MICRO_OS_PLUS_TRACE_UTILS_LISTS)
91 trace::printf ("%s() link %p after %p\n", __func__, node, this);
92#endif
93 assert (next_ != nullptr);
94 assert (next_->previous_ != nullptr);
95
96 // Make the new node point to its new neighbours.
97 node->previous_ = this;
98 node->next_ = next_;
99
100 next_->previous_ = node;
101 next_ = node;
102 }
103
111 void
113 {
114#if defined(MICRO_OS_PLUS_TRACE_UTILS_LISTS)
115 trace::printf ("%s() link %p before %p\n", __func__, node, this);
116#endif
117 assert (next_ != nullptr);
118 assert (next_->previous_ != nullptr);
119
120 // Make the new node point to its new neighbours.
121 node->next_ = this;
122 node->previous_ = previous_;
123
124 previous_->next_ = node;
125 previous_ = node;
126 }
127
136 void
138 {
139#if defined(MICRO_OS_PLUS_TRACE_UTILS_LISTS)
140 trace::printf ("%s() %p \n", __func__, this);
141#endif
142
143 // Make neighbours point to each other.
144 // This works even if the node is already unlinked,
145 // so no need for an extra test.
146 previous_->next_ = next_;
147 next_->previous_ = previous_;
148
149 // Reset the unlinked node to the initial state,
150 // with both pointers pointing to itself.
151 initialize ();
152 }
153
159 bool
161 {
162 if (next_ == this || previous_ == this)
163 {
164 assert (next_ == this);
165 assert (previous_ == this);
166 return false;
167 }
168 return true;
169 }
170
171 // ==========================================================================
172
177#if defined(__GNUC__) && !defined(__clang__)
178 // Prevent LTO to optimize out the code.
179 // https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
180 __attribute__ ((noinline, noipa))
181#endif
182 void
184 {
185 next_ = nullptr;
186 previous_ = nullptr;
187 }
188
189 // ==========================================================================
190} // namespace micro_os_plus::utils
191
192#if defined(__GNUC__)
193#pragma GCC diagnostic pop
194#endif
195
196// ----------------------------------------------------------------------------
µOS++ utility definitions.
Definition inlines.h:33