1 | /* |
---|
2 | * Copyright (c) 2013 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/chain.h> |
---|
20 | |
---|
21 | #if defined( RTEMS_SMP ) |
---|
22 | |
---|
23 | void rtems_chain_explicit_extract( |
---|
24 | rtems_chain_control *chain, |
---|
25 | rtems_chain_node *node |
---|
26 | ) |
---|
27 | { |
---|
28 | ISR_Level level; |
---|
29 | |
---|
30 | _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level ); |
---|
31 | _Chain_Extract_unprotected( node ); |
---|
32 | _ISR_lock_Release_and_ISR_enable( &chain->Lock, level ); |
---|
33 | } |
---|
34 | |
---|
35 | rtems_chain_node *rtems_chain_get( rtems_chain_control *chain ) |
---|
36 | { |
---|
37 | rtems_chain_node *node; |
---|
38 | ISR_Level level; |
---|
39 | |
---|
40 | _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level ); |
---|
41 | node = _Chain_Get_unprotected( &chain->Chain ); |
---|
42 | _ISR_lock_Release_and_ISR_enable( &chain->Lock, level ); |
---|
43 | |
---|
44 | return node; |
---|
45 | } |
---|
46 | |
---|
47 | void rtems_chain_explicit_insert( |
---|
48 | rtems_chain_control *chain, |
---|
49 | rtems_chain_node *after_node, |
---|
50 | rtems_chain_node *node |
---|
51 | ) |
---|
52 | { |
---|
53 | ISR_Level level; |
---|
54 | |
---|
55 | _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level ); |
---|
56 | _Chain_Insert_unprotected( after_node, node ); |
---|
57 | _ISR_lock_Release_and_ISR_enable( &chain->Lock, level ); |
---|
58 | } |
---|
59 | |
---|
60 | void rtems_chain_append( |
---|
61 | rtems_chain_control *chain, |
---|
62 | rtems_chain_node *node |
---|
63 | ) |
---|
64 | { |
---|
65 | ISR_Level level; |
---|
66 | |
---|
67 | _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level ); |
---|
68 | _Chain_Append_unprotected( &chain->Chain, node ); |
---|
69 | _ISR_lock_Release_and_ISR_enable( &chain->Lock, level ); |
---|
70 | } |
---|
71 | |
---|
72 | void rtems_chain_prepend( |
---|
73 | rtems_chain_control *chain, |
---|
74 | rtems_chain_node *node |
---|
75 | ) |
---|
76 | { |
---|
77 | ISR_Level level; |
---|
78 | |
---|
79 | _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level ); |
---|
80 | _Chain_Prepend_unprotected( &chain->Chain, node ); |
---|
81 | _ISR_lock_Release_and_ISR_enable( &chain->Lock, level ); |
---|
82 | } |
---|
83 | |
---|
84 | bool rtems_chain_append_with_empty_check( |
---|
85 | rtems_chain_control *chain, |
---|
86 | rtems_chain_node *node |
---|
87 | ) |
---|
88 | { |
---|
89 | bool was_empty; |
---|
90 | ISR_Level level; |
---|
91 | |
---|
92 | _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level ); |
---|
93 | was_empty = _Chain_Append_with_empty_check_unprotected( |
---|
94 | &chain->Chain, |
---|
95 | node |
---|
96 | ); |
---|
97 | _ISR_lock_Release_and_ISR_enable( &chain->Lock, level ); |
---|
98 | |
---|
99 | return was_empty; |
---|
100 | } |
---|
101 | |
---|
102 | bool rtems_chain_prepend_with_empty_check( |
---|
103 | rtems_chain_control *chain, |
---|
104 | rtems_chain_node *node |
---|
105 | ) |
---|
106 | { |
---|
107 | bool was_empty; |
---|
108 | ISR_Level level; |
---|
109 | |
---|
110 | _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level ); |
---|
111 | was_empty = _Chain_Prepend_with_empty_check_unprotected( |
---|
112 | &chain->Chain, |
---|
113 | node |
---|
114 | ); |
---|
115 | _ISR_lock_Release_and_ISR_enable( &chain->Lock, level ); |
---|
116 | |
---|
117 | return was_empty; |
---|
118 | } |
---|
119 | |
---|
120 | bool rtems_chain_get_with_empty_check( |
---|
121 | rtems_chain_control *chain, |
---|
122 | rtems_chain_node **node |
---|
123 | ) |
---|
124 | { |
---|
125 | bool is_empty_now; |
---|
126 | ISR_Level level; |
---|
127 | |
---|
128 | _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level ); |
---|
129 | is_empty_now = _Chain_Get_with_empty_check_unprotected( |
---|
130 | &chain->Chain, |
---|
131 | node |
---|
132 | ); |
---|
133 | _ISR_lock_Release_and_ISR_enable( &chain->Lock, level ); |
---|
134 | |
---|
135 | return is_empty_now; |
---|
136 | } |
---|
137 | |
---|
138 | #endif /* defined( RTEMS_SMP ) */ |
---|