The lists.cpp
File Reference
C++ source file with the implementations for the µOS++ lists methods. More...
Included Headers
Namespaces Index
namespace | micro_os_plus |
The primary namespace for the µOS++ framework. More... | |
namespace | micro_os_plus::utils |
The µOS++ utilities definitions. More... | |
Description
C++ source file with the implementations for the µOS++ lists methods.
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
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
31#include <micro-os-plus/utils/lists.h>
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
45namespace micro_os_plus::utils
46{
47 // ==========================================================================
48
57 bool
58 double_list_links_base::uninitialized (void) const
59 {
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;
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;
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.
162
163 // Reset the unlinked node to the initial state,
164 // with both pointers pointing to itself.
165 initialize ();
166 }
167
175 bool
176 double_list_links_base::linked (void) const
177 {
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.
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// ----------------------------------------------------------------------------
Generated via docusaurus-plugin-doxygen by Doxygen 1.13.2