source: rtems/cpukit/sapi/src/chainsmp.c @ d50acdbb

4.115
Last change on this file since d50acdbb was d50acdbb, checked in by Sebastian Huber <sebastian.huber@…>, on 03/10/14 at 07:25:32

score: Add local context to SMP lock API

Add a local context structure to the SMP lock API for acquire and
release pairs. This context can be used to store the ISR level and
profiling information. It may be later used to enable more
sophisticated lock algorithms, e.g. MCS locks.

There is only one lock that cannot be used with a local context. This
is the per-CPU lock since here we would have to transfer the local
context through a context switch which is very complicated.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2013-2014 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#include <rtems/score/smplock.h>
24
25static SMP_lock_Control chain_lock = SMP_LOCK_INITIALIZER;
26
27static void chain_acquire( SMP_lock_Context *lock_context )
28{
29  _SMP_lock_ISR_disable_and_acquire( &chain_lock, lock_context );
30}
31
32static void chain_release( SMP_lock_Context *lock_context )
33{
34  _SMP_lock_Release_and_ISR_enable( &chain_lock, lock_context );
35}
36
37void rtems_chain_extract( rtems_chain_node *node )
38{
39  SMP_lock_Context lock_context;
40
41  chain_acquire( &lock_context );
42  _Chain_Extract_unprotected( node );
43  chain_release( &lock_context );
44}
45
46rtems_chain_node *rtems_chain_get( rtems_chain_control *chain )
47{
48  rtems_chain_node *node;
49  SMP_lock_Context lock_context;
50
51  chain_acquire( &lock_context );
52  node = _Chain_Get_unprotected( chain );
53  chain_release( &lock_context );
54
55  return node;
56}
57
58void rtems_chain_insert( rtems_chain_node *after_node, rtems_chain_node *node )
59{
60  SMP_lock_Context lock_context;
61
62  chain_acquire( &lock_context );
63  _Chain_Insert_unprotected( after_node, node );
64  chain_release( &lock_context );
65}
66
67void rtems_chain_append(
68  rtems_chain_control *chain,
69  rtems_chain_node *node
70)
71{
72  SMP_lock_Context lock_context;
73
74  chain_acquire( &lock_context );
75  _Chain_Append_unprotected( chain, node );
76  chain_release( &lock_context );
77}
78
79void rtems_chain_prepend(
80  rtems_chain_control *chain,
81  rtems_chain_node *node
82)
83{
84  SMP_lock_Context lock_context;
85
86  chain_acquire( &lock_context );
87  _Chain_Prepend_unprotected( chain, node );
88  chain_release( &lock_context );
89}
90
91bool rtems_chain_append_with_empty_check(
92  rtems_chain_control *chain,
93  rtems_chain_node *node
94)
95{
96  bool was_empty;
97  SMP_lock_Context lock_context;
98
99  chain_acquire( &lock_context );
100  was_empty = _Chain_Append_with_empty_check_unprotected( chain, node );
101  chain_release( &lock_context );
102
103  return was_empty;
104}
105
106bool rtems_chain_prepend_with_empty_check(
107  rtems_chain_control *chain,
108  rtems_chain_node *node
109)
110{
111  bool was_empty;
112  SMP_lock_Context lock_context;
113
114  chain_acquire( &lock_context );
115  was_empty = _Chain_Prepend_with_empty_check_unprotected( chain, node );
116  chain_release( &lock_context );
117
118  return was_empty;
119}
120
121bool rtems_chain_get_with_empty_check(
122  rtems_chain_control *chain,
123  rtems_chain_node **node
124)
125{
126  bool is_empty_now;
127  SMP_lock_Context lock_context;
128
129  chain_acquire( &lock_context );
130  is_empty_now = _Chain_Get_with_empty_check_unprotected( chain, node );
131  chain_release( &lock_context );
132
133  return is_empty_now;
134}
135
136#endif /* defined( RTEMS_SMP ) */
Note: See TracBrowser for help on using the repository browser.