1 | /* |
---|
2 | * Copyright (c) 2013, 2016 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.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/chain.h> |
---|
20 | #include <rtems/rtems/intr.h> |
---|
21 | |
---|
22 | RTEMS_INTERRUPT_LOCK_DEFINE( static, chain_lock, "Chains" ) |
---|
23 | |
---|
24 | static void chain_acquire( rtems_interrupt_lock_context *lock_context ) |
---|
25 | { |
---|
26 | rtems_interrupt_lock_acquire( &chain_lock, lock_context ); |
---|
27 | } |
---|
28 | |
---|
29 | static void chain_release( rtems_interrupt_lock_context *lock_context ) |
---|
30 | { |
---|
31 | rtems_interrupt_lock_release( &chain_lock, lock_context ); |
---|
32 | } |
---|
33 | |
---|
34 | void rtems_chain_extract( rtems_chain_node *node ) |
---|
35 | { |
---|
36 | rtems_interrupt_lock_context lock_context; |
---|
37 | |
---|
38 | chain_acquire( &lock_context ); |
---|
39 | _Chain_Extract_unprotected( node ); |
---|
40 | chain_release( &lock_context ); |
---|
41 | } |
---|
42 | |
---|
43 | rtems_chain_node *rtems_chain_get( rtems_chain_control *chain ) |
---|
44 | { |
---|
45 | rtems_chain_node *node; |
---|
46 | rtems_interrupt_lock_context lock_context; |
---|
47 | |
---|
48 | chain_acquire( &lock_context ); |
---|
49 | node = _Chain_Get_unprotected( chain ); |
---|
50 | chain_release( &lock_context ); |
---|
51 | |
---|
52 | return node; |
---|
53 | } |
---|
54 | |
---|
55 | void rtems_chain_insert( rtems_chain_node *after_node, rtems_chain_node *node ) |
---|
56 | { |
---|
57 | rtems_interrupt_lock_context lock_context; |
---|
58 | |
---|
59 | chain_acquire( &lock_context ); |
---|
60 | _Chain_Insert_unprotected( after_node, node ); |
---|
61 | chain_release( &lock_context ); |
---|
62 | } |
---|
63 | |
---|
64 | void rtems_chain_append( |
---|
65 | rtems_chain_control *chain, |
---|
66 | rtems_chain_node *node |
---|
67 | ) |
---|
68 | { |
---|
69 | rtems_interrupt_lock_context lock_context; |
---|
70 | |
---|
71 | chain_acquire( &lock_context ); |
---|
72 | _Chain_Append_unprotected( chain, node ); |
---|
73 | chain_release( &lock_context ); |
---|
74 | } |
---|
75 | |
---|
76 | void rtems_chain_prepend( |
---|
77 | rtems_chain_control *chain, |
---|
78 | rtems_chain_node *node |
---|
79 | ) |
---|
80 | { |
---|
81 | rtems_interrupt_lock_context lock_context; |
---|
82 | |
---|
83 | chain_acquire( &lock_context ); |
---|
84 | _Chain_Prepend_unprotected( chain, node ); |
---|
85 | chain_release( &lock_context ); |
---|
86 | } |
---|
87 | |
---|
88 | bool rtems_chain_append_with_empty_check( |
---|
89 | rtems_chain_control *chain, |
---|
90 | rtems_chain_node *node |
---|
91 | ) |
---|
92 | { |
---|
93 | bool was_empty; |
---|
94 | rtems_interrupt_lock_context lock_context; |
---|
95 | |
---|
96 | chain_acquire( &lock_context ); |
---|
97 | was_empty = _Chain_Append_with_empty_check_unprotected( chain, node ); |
---|
98 | chain_release( &lock_context ); |
---|
99 | |
---|
100 | return was_empty; |
---|
101 | } |
---|
102 | |
---|
103 | bool rtems_chain_prepend_with_empty_check( |
---|
104 | rtems_chain_control *chain, |
---|
105 | rtems_chain_node *node |
---|
106 | ) |
---|
107 | { |
---|
108 | bool was_empty; |
---|
109 | rtems_interrupt_lock_context lock_context; |
---|
110 | |
---|
111 | chain_acquire( &lock_context ); |
---|
112 | was_empty = _Chain_Prepend_with_empty_check_unprotected( chain, node ); |
---|
113 | chain_release( &lock_context ); |
---|
114 | |
---|
115 | return was_empty; |
---|
116 | } |
---|
117 | |
---|
118 | bool rtems_chain_get_with_empty_check( |
---|
119 | rtems_chain_control *chain, |
---|
120 | rtems_chain_node **node |
---|
121 | ) |
---|
122 | { |
---|
123 | bool is_empty_now; |
---|
124 | rtems_interrupt_lock_context lock_context; |
---|
125 | |
---|
126 | chain_acquire( &lock_context ); |
---|
127 | is_empty_now = _Chain_Get_with_empty_check_unprotected( chain, node ); |
---|
128 | chain_release( &lock_context ); |
---|
129 | |
---|
130 | return is_empty_now; |
---|
131 | } |
---|