Skip to main content

The lists.cpp File Reference

The file with the implementations of the µOS++ lists methods. More...

Included Headers

#include <micro-os-plus/utils/lists.h>
#include <micro-os-plus/diag/trace.h>

Namespaces

namespace

The top µOS++ namespace.

namespace

The µOS++ utilities definitions.

Description

The list.cpp source file contains the C++ implementations of the methods for the µOS++ Intrusive Lists classes, delivering an efficient and lightweight linked list management system tailored for embedded applications.

The class definitions are in the lists.h file.

File Listing

The file content with the documentation metadata removed is:

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
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
84 void
86 {
87 if (uninitialized ())
88 {
89 initialize ();
90 }
91 }
92
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
124 void
126 {
127#if defined(MICRO_OS_PLUS_TRACE_UTILS_LISTS)
128 trace::printf ("%s() link %p before %p\n", __func__, node, this);
129#endif
130 assert (next_ != nullptr);
131 assert (next_->previous_ != nullptr);
132
133 // Make the new node point to its new neighbours.
134 node->next_ = this;
135 node->previous_ = previous_;
136
137 previous_->next_ = node;
138 previous_ = node;
139 }
140
149 void
151 {
152#if defined(MICRO_OS_PLUS_TRACE_UTILS_LISTS)
153 trace::printf ("%s() %p \n", __func__, this);
154#endif
155
156 // Make neighbours point to each other.
157 // This works even if the node is already unlinked,
158 // so no need for an extra test.
159 previous_->next_ = next_;
160 next_->previous_ = previous_;
161
162 // Reset the unlinked node to the initial state,
163 // with both pointers pointing to itself.
164 initialize ();
165 }
166
172 bool
174 {
175 if (next_ == this || previous_ == this)
176 {
177 assert (next_ == this);
178 assert (previous_ == this);
179 return false;
180 }
181 return true;
182 }
183
184 // ==========================================================================
185
190#if defined(__GNUC__) && !defined(__clang__)
191 // Prevent LTO to optimize out the code.
193 __attribute__ ((noinline, noipa))
194#endif
195 void
197 {
198 next_ = nullptr;
199 previous_ = nullptr;
200 }
201
202 // ==========================================================================
203} // namespace micro_os_plus::utils
204
205#if defined(__GNUC__)
206#pragma GCC diagnostic pop
207#endif
208
209// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.13.2