1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSAPIClassicChains |
---|
7 | * |
---|
8 | * @brief This source file contains the implementation of rtems_chain_append(), |
---|
9 | * rtems_chain_append_with_empty_check(), rtems_chain_extract(), |
---|
10 | * rtems_chain_get(), rtems_chain_get_with_empty_check(), |
---|
11 | * rtems_chain_insert(), rtems_chain_prepend(), and |
---|
12 | * rtems_chain_prepend_with_empty_check(). |
---|
13 | */ |
---|
14 | |
---|
15 | /* |
---|
16 | * Copyright (c) 2013, 2016 embedded brains GmbH. All rights reserved. |
---|
17 | * |
---|
18 | * embedded brains GmbH |
---|
19 | * Dornierstr. 4 |
---|
20 | * 82178 Puchheim |
---|
21 | * Germany |
---|
22 | * <rtems@embedded-brains.de> |
---|
23 | * |
---|
24 | * Redistribution and use in source and binary forms, with or without |
---|
25 | * modification, are permitted provided that the following conditions |
---|
26 | * are met: |
---|
27 | * 1. Redistributions of source code must retain the above copyright |
---|
28 | * notice, this list of conditions and the following disclaimer. |
---|
29 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
30 | * notice, this list of conditions and the following disclaimer in the |
---|
31 | * documentation and/or other materials provided with the distribution. |
---|
32 | * |
---|
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
34 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
35 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
36 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
37 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
38 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
39 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
40 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
41 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
42 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
43 | * POSSIBILITY OF SUCH DAMAGE. |
---|
44 | */ |
---|
45 | |
---|
46 | #ifdef HAVE_CONFIG_H |
---|
47 | #include "config.h" |
---|
48 | #endif |
---|
49 | |
---|
50 | #include <rtems/chain.h> |
---|
51 | #include <rtems/rtems/intr.h> |
---|
52 | |
---|
53 | RTEMS_INTERRUPT_LOCK_DEFINE( static, chain_lock, "Chains" ) |
---|
54 | |
---|
55 | static void chain_acquire( rtems_interrupt_lock_context *lock_context ) |
---|
56 | { |
---|
57 | rtems_interrupt_lock_acquire( &chain_lock, lock_context ); |
---|
58 | } |
---|
59 | |
---|
60 | static void chain_release( rtems_interrupt_lock_context *lock_context ) |
---|
61 | { |
---|
62 | rtems_interrupt_lock_release( &chain_lock, lock_context ); |
---|
63 | } |
---|
64 | |
---|
65 | void rtems_chain_extract( rtems_chain_node *node ) |
---|
66 | { |
---|
67 | rtems_interrupt_lock_context lock_context; |
---|
68 | |
---|
69 | chain_acquire( &lock_context ); |
---|
70 | _Chain_Extract_unprotected( node ); |
---|
71 | chain_release( &lock_context ); |
---|
72 | } |
---|
73 | |
---|
74 | rtems_chain_node *rtems_chain_get( rtems_chain_control *chain ) |
---|
75 | { |
---|
76 | rtems_chain_node *node; |
---|
77 | rtems_interrupt_lock_context lock_context; |
---|
78 | |
---|
79 | chain_acquire( &lock_context ); |
---|
80 | node = _Chain_Get_unprotected( chain ); |
---|
81 | chain_release( &lock_context ); |
---|
82 | |
---|
83 | return node; |
---|
84 | } |
---|
85 | |
---|
86 | void rtems_chain_insert( rtems_chain_node *after_node, rtems_chain_node *node ) |
---|
87 | { |
---|
88 | rtems_interrupt_lock_context lock_context; |
---|
89 | |
---|
90 | chain_acquire( &lock_context ); |
---|
91 | _Chain_Insert_unprotected( after_node, node ); |
---|
92 | chain_release( &lock_context ); |
---|
93 | } |
---|
94 | |
---|
95 | void rtems_chain_append( |
---|
96 | rtems_chain_control *chain, |
---|
97 | rtems_chain_node *node |
---|
98 | ) |
---|
99 | { |
---|
100 | rtems_interrupt_lock_context lock_context; |
---|
101 | |
---|
102 | chain_acquire( &lock_context ); |
---|
103 | _Chain_Append_unprotected( chain, node ); |
---|
104 | chain_release( &lock_context ); |
---|
105 | } |
---|
106 | |
---|
107 | void rtems_chain_prepend( |
---|
108 | rtems_chain_control *chain, |
---|
109 | rtems_chain_node *node |
---|
110 | ) |
---|
111 | { |
---|
112 | rtems_interrupt_lock_context lock_context; |
---|
113 | |
---|
114 | chain_acquire( &lock_context ); |
---|
115 | _Chain_Prepend_unprotected( chain, node ); |
---|
116 | chain_release( &lock_context ); |
---|
117 | } |
---|
118 | |
---|
119 | bool rtems_chain_append_with_empty_check( |
---|
120 | rtems_chain_control *chain, |
---|
121 | rtems_chain_node *node |
---|
122 | ) |
---|
123 | { |
---|
124 | bool was_empty; |
---|
125 | rtems_interrupt_lock_context lock_context; |
---|
126 | |
---|
127 | chain_acquire( &lock_context ); |
---|
128 | was_empty = _Chain_Append_with_empty_check_unprotected( chain, node ); |
---|
129 | chain_release( &lock_context ); |
---|
130 | |
---|
131 | return was_empty; |
---|
132 | } |
---|
133 | |
---|
134 | bool rtems_chain_prepend_with_empty_check( |
---|
135 | rtems_chain_control *chain, |
---|
136 | rtems_chain_node *node |
---|
137 | ) |
---|
138 | { |
---|
139 | bool was_empty; |
---|
140 | rtems_interrupt_lock_context lock_context; |
---|
141 | |
---|
142 | chain_acquire( &lock_context ); |
---|
143 | was_empty = _Chain_Prepend_with_empty_check_unprotected( chain, node ); |
---|
144 | chain_release( &lock_context ); |
---|
145 | |
---|
146 | return was_empty; |
---|
147 | } |
---|
148 | |
---|
149 | bool rtems_chain_get_with_empty_check( |
---|
150 | rtems_chain_control *chain, |
---|
151 | rtems_chain_node **node |
---|
152 | ) |
---|
153 | { |
---|
154 | bool is_empty_now; |
---|
155 | rtems_interrupt_lock_context lock_context; |
---|
156 | |
---|
157 | chain_acquire( &lock_context ); |
---|
158 | is_empty_now = _Chain_Get_with_empty_check_unprotected( chain, node ); |
---|
159 | chain_release( &lock_context ); |
---|
160 | |
---|
161 | return is_empty_now; |
---|
162 | } |
---|