µOS++ IIIe Reference  v6.3.15
“Perfekt ist nicht gut genug”
The third edition of µOS++, a POSIX inspired open source system, written in C++.
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 Liviu Ionescu.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or
11  * sell copies of the Software, and to permit persons to whom
12  * the Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 #include <cmsis-plus/utils/lists.h>
29 
30 #include <cmsis-plus/diag/trace.h>
31 
32 namespace os
33 {
34  namespace utils
35  {
36  // ======================================================================
37 
59  void
61  {
62  // Check if not already unlinked.
63  if (unlinked ())
64  {
65  assert(prev_ == nullptr);
66 #if defined(OS_TRACE_UTILS_LISTS)
67  trace::printf ("%s() %p nop\n", __func__, this);
68 #endif
69  return;
70  }
71 
72 #if defined(OS_TRACE_UTILS_LISTS)
73  trace::printf ("%s() %p \n", __func__, this);
74 #endif
75 
76  // Make neighbours point to each other.
77  prev_->next_ = next_;
78  next_->prev_ = prev_;
79 
80  // Nullify both pointers in the unlinked node.
81  prev_ = nullptr;
82  next_ = nullptr;
83  }
84 
85  // ========================================================================
86 
107  void
109  {
110  head_.next (const_cast<static_double_list_links*> (&head_));
111  head_.prev (const_cast<static_double_list_links*> (&head_));
112  }
113 
114  void
117  {
118 #if defined(OS_TRACE_UTILS_LISTS)
119  trace::printf ("%s() n=%p after %p\n", __func__, &node, after);
120 #endif
121 
122  // Unlinked nodes must have both pointers null.
123  // If not, most probably the node was already linked.
124  // Or the memory is corrupted.
125  assert(node.prev () == nullptr);
126  assert(node.next () == nullptr);
127 
128  // The `after` node must be linked. Only the `next` pointer is
129  // tested, since only it is used.
130  assert(after->next () != nullptr);
131 
132  // Make the new node point to its neighbours.
133  node.prev (after);
134  node.next (after->next ());
135 
136  // Make the neighbours point to the node. The order is important.
137  after->next ()->prev (&node);
138  after->next (&node);
139  }
140 
141  // ========================================================================
142 
148  {
149 #if defined(OS_TRACE_UTILS_LISTS_CONSTRUCT) || defined(OS_TRACE_UTILS_LISTS)
150  trace::printf ("%s() %p \n", __func__, this);
151 #endif
152 
153  clear ();
154  }
155 
161  {
162 #if defined(OS_TRACE_UTILS_LISTS_CONSTRUCT) || defined(OS_TRACE_UTILS_LISTS)
163  trace::printf ("%s() %p \n", __func__, this);
164 #endif
165 
166  assert(empty ());
167  }
168 
169  } /* namespace utils */
170 } /* namespace os */
Ask for flags to be cleared after read.
Definition: os-decls.h:303
double_list()
Construct a list.
Definition: lists.cpp:147
System namespace.
void insert_after(static_double_list_links &node, static_double_list_links *after)
Insert a new node after existing node.
Definition: lists.cpp:115
void clear(void)
Clear the list.
Definition: lists.cpp:108
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition: trace.cpp:74
~double_list()
Destruct the list.
Definition: lists.cpp:160