summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems/score/isrlock.h
blob: fb20a8e2d5c9adc70065280f5efc506004c74ff3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
 * @file
 *
 * @ingroup ScoreISRLocks
 *
 * @brief ISR Locks
 */

/*
 * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Dornierstr. 4
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.com/license/LICENSE.
 */

#ifndef _RTEMS_SCORE_ISR_LOCK_H
#define _RTEMS_SCORE_ISR_LOCK_H

#include <rtems/score/isrlevel.h>
#include <rtems/score/smplock.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @defgroup ScoreISRLocks ISR Locks
 *
 * @ingroup ScoreISR
 *
 * @brief Low-level lock to protect critical sections accessed by threads and
 * interrupt service routines.
 *
 * On single processor configurations the ISR locks degrade to simple ISR
 * disable/enable sequences.  No additional storage or objects are required.
 *
 * This synchronization primitive is supported on SMP configurations.  Here SMP
 * locks are used.
 *
 * @{
 */

/**
 * @brief ISR lock control.
 */
typedef struct {
  #if defined( RTEMS_SMP )
    SMP_lock_Control lock;
  #endif
} ISR_lock_Control;

/**
 * @brief Initializer for static initialization of ISR locks.
 */
#if defined( RTEMS_SMP )
  #define ISR_LOCK_INITIALIZER \
    { SMP_LOCK_INITIALIZER }
#else
  #define ISR_LOCK_INITIALIZER \
    { }
#endif

/**
 * @brief Initializes an ISR lock.
 *
 * Concurrent initialization leads to unpredictable results.
 *
 * @param[in,out] _lock The ISR lock control.
 */
#if defined( RTEMS_SMP )
  #define _ISR_lock_Initialize( _lock ) \
    _SMP_lock_Initialize( &( _lock )->lock )
#else
  #define _ISR_lock_Initialize( _lock ) \
    do { \
      (void) _lock; \
    } while (0)
#endif

/**
 * @brief Acquires an ISR lock.
 *
 * Interrupts will be disabled.  On SMP configurations this function acquires
 * an SMP lock.
 *
 * This function can be used in thread and interrupt context.
 *
 * @param[in,out] _lock The ISR lock control.
 * @param[out] _isr_cookie The interrupt status to restore will be returned.
 *
 * @see _ISR_lock_Release().
 */
#if defined( RTEMS_SMP )
  #define _ISR_lock_Acquire( _lock, _isr_cookie ) \
    _SMP_lock_ISR_disable_and_acquire( &( _lock )->lock, _isr_cookie )
#else
  #define _ISR_lock_Acquire( _lock, _isr_cookie ) \
    do { \
      (void) _lock; \
      _ISR_Disable( _isr_cookie ); \
    } while (0)
#endif

/**
 * @brief Releases an ISR lock.
 *
 * The interrupt status will be restored.  On SMP configurations this function
 * releases an SMP lock.
 *
 * This function can be used in thread and interrupt context.
 *
 * @param[in,out] _lock The ISR lock control.
 * @param[in] _isr_cookie The interrupt status to restore.
 *
 * @see _ISR_lock_Acquire().
 */
#if defined( RTEMS_SMP )
  #define _ISR_lock_Release( _lock, _isr_cookie ) \
    _SMP_lock_Release_and_ISR_enable( &( _lock )->lock, _isr_cookie )
#else
  #define _ISR_lock_Release( _lock, _isr_cookie ) \
    do { \
      (void) _lock; \
      _ISR_Enable( _isr_cookie ); \
    } while (0)
#endif

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* _RTEMS_SCORE_ISR_LOCK_H */