source: rtems/cpukit/sapi/src/chainsmp.c @ 1215fd4

4.115
Last change on this file since 1215fd4 was 1215fd4, checked in by Sebastian Huber <sebastian.huber@…>, on 08/26/13 at 13:14:33

sapi: SMP support for chains

Add ISR lock to chain control for proper SMP protection. Replace
rtems_chain_extract() with rtems_chain_explicit_extract() and
rtems_chain_insert() with rtems_chain_explicit_insert() on SMP
configurations. Use rtems_chain_explicit_extract() and
rtems_chain_explicit_insert() to provide SMP support.

  • Property mode set to 100644
File size: 3.0 KB
Line 
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
23void 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
35rtems_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
47void 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
60void 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
72void 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
84bool 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
102bool 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
120bool 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 ) */
Note: See TracBrowser for help on using the repository browser.