RTEMS 6.1-rc2
Loading...
Searching...
No Matches
smplock.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * COPYRIGHT (c) 1989-2011.
14 * On-Line Applications Research Corporation (OAR).
15 *
16 * Copyright (C) 2013, 2016 embedded brains GmbH & Co. KG
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#ifndef _RTEMS_SCORE_SMPLOCK_H
41#define _RTEMS_SCORE_SMPLOCK_H
42
43#include <rtems/score/cpuopts.h>
44
64#if defined(RTEMS_SMP)
65
69
70#if defined(RTEMS_DEBUG)
71#include <rtems/score/assert.h>
72#include <rtems/score/smp.h>
73#endif
74
75#ifdef __cplusplus
76extern "C" {
77#endif /* __cplusplus */
78
79#if defined(RTEMS_DEBUG) || defined(RTEMS_PROFILING)
80#define RTEMS_SMP_LOCK_DO_NOT_INLINE
81#endif
82
86typedef struct {
87 SMP_ticket_lock_Control Ticket_lock;
88#if defined(RTEMS_DEBUG)
101 uint32_t owner;
102#endif
103#if defined(RTEMS_PROFILING)
104 SMP_lock_Stats Stats;
105#endif
106} SMP_lock_Control;
107
111typedef struct {
112 ISR_Level isr_level;
113#if defined(RTEMS_DEBUG)
114 SMP_lock_Control *lock_used_for_acquire;
115#endif
116#if defined(RTEMS_PROFILING)
117 SMP_lock_Stats_context Stats_context;
118#endif
119} SMP_lock_Context;
120
121#if defined(RTEMS_DEBUG)
122#define SMP_LOCK_NO_OWNER 0
123#endif
124
128#if defined(RTEMS_DEBUG) && defined(RTEMS_PROFILING)
129 #define SMP_LOCK_INITIALIZER( name ) \
130 { \
131 SMP_TICKET_LOCK_INITIALIZER, \
132 SMP_LOCK_NO_OWNER, \
133 SMP_LOCK_STATS_INITIALIZER( name ) \
134 }
135#elif defined(RTEMS_DEBUG)
136 #define SMP_LOCK_INITIALIZER( name ) \
137 { SMP_TICKET_LOCK_INITIALIZER, SMP_LOCK_NO_OWNER }
138#elif defined(RTEMS_PROFILING)
139 #define SMP_LOCK_INITIALIZER( name ) \
140 { SMP_TICKET_LOCK_INITIALIZER, SMP_LOCK_STATS_INITIALIZER( name ) }
141#else
142 #define SMP_LOCK_INITIALIZER( name ) { SMP_TICKET_LOCK_INITIALIZER }
143#endif
144
150static inline void _SMP_lock_Initialize_inline(
151 SMP_lock_Control *lock,
152 const char *name
153)
154{
155 _SMP_ticket_lock_Initialize( &lock->Ticket_lock );
156#if defined(RTEMS_DEBUG)
157 lock->owner = SMP_LOCK_NO_OWNER;
158#endif
159#if defined(RTEMS_PROFILING)
160 _SMP_lock_Stats_initialize( &lock->Stats, name );
161#else
162 (void) name;
163#endif
164}
165
175#if defined(RTEMS_SMP_LOCK_DO_NOT_INLINE)
176void _SMP_lock_Initialize(
177 SMP_lock_Control *lock,
178 const char *name
179);
180#else
181#define _SMP_lock_Initialize( lock, name ) \
182 _SMP_lock_Initialize_inline( lock, name )
183#endif
184
190static inline void _SMP_lock_Destroy_inline( SMP_lock_Control *lock )
191{
192 _SMP_ticket_lock_Destroy( &lock->Ticket_lock );
193 _SMP_lock_Stats_destroy( &lock->Stats );
194}
195
203#if defined(RTEMS_SMP_LOCK_DO_NOT_INLINE)
204void _SMP_lock_Destroy( SMP_lock_Control *lock );
205#else
206#define _SMP_lock_Destroy( lock ) \
207 _SMP_lock_Destroy_inline( lock )
208#endif
209
217static inline void _SMP_lock_Set_name(
218 SMP_lock_Control *lock,
219 const char *name
220)
221{
222#if defined(RTEMS_PROFILING)
223 lock->Stats.name = name;
224#else
225 (void) lock;
226 (void) name;
227#endif
228}
229
235#if defined(RTEMS_DEBUG)
236static inline uint32_t _SMP_lock_Who_am_I( void )
237{
238 /*
239 * The CPU index starts with zero. Increment it by one, to allow global SMP
240 * locks to reside in the BSS section.
241 */
242 return _SMP_Get_current_processor() + 1;
243}
244#endif
245
252static inline void _SMP_lock_Acquire_inline(
253 SMP_lock_Control *lock,
254 SMP_lock_Context *context
255)
256{
257#if defined(RTEMS_DEBUG)
258 context->lock_used_for_acquire = lock;
259#else
260 (void) context;
261#endif
262 _SMP_ticket_lock_Acquire(
263 &lock->Ticket_lock,
264 &lock->Stats,
265 &context->Stats_context
266 );
267#if defined(RTEMS_DEBUG)
268 lock->owner = _SMP_lock_Who_am_I();
269#endif
270}
271
283void _SMP_lock_Acquire(
284 SMP_lock_Control *lock,
285 SMP_lock_Context *context
286);
287
294static inline void _SMP_lock_Release_inline(
295 SMP_lock_Control *lock,
296 SMP_lock_Context *context
297)
298{
299#if defined(RTEMS_DEBUG)
300 _Assert( context->lock_used_for_acquire == lock );
301 context->lock_used_for_acquire = NULL;
302 _Assert( lock->owner == _SMP_lock_Who_am_I() );
303 lock->owner = SMP_LOCK_NO_OWNER;
304#else
305 (void) context;
306#endif
307 _SMP_ticket_lock_Release(
308 &lock->Ticket_lock,
309 &context->Stats_context
310 );
311}
312
320#if defined(RTEMS_SMP_LOCK_DO_NOT_INLINE)
321void _SMP_lock_Release(
322 SMP_lock_Control *lock,
323 SMP_lock_Context *context
324);
325#else
326#define _SMP_lock_Release( lock, context ) \
327 _SMP_lock_Release_inline( lock, context )
328#endif
329
336static inline void _SMP_lock_ISR_disable_and_acquire_inline(
337 SMP_lock_Control *lock,
338 SMP_lock_Context *context
339)
340{
341 _ISR_Local_disable( context->isr_level );
342 _SMP_lock_Acquire_inline( lock, context );
343}
344
352void _SMP_lock_ISR_disable_and_acquire(
353 SMP_lock_Control *lock,
354 SMP_lock_Context *context
355);
356
363static inline void _SMP_lock_Release_and_ISR_enable_inline(
364 SMP_lock_Control *lock,
365 SMP_lock_Context *context
366)
367{
368 _SMP_lock_Release_inline( lock, context );
369 _ISR_Local_enable( context->isr_level );
370}
371
379#if defined(RTEMS_SMP_LOCK_DO_NOT_INLINE)
380void _SMP_lock_Release_and_ISR_enable(
381 SMP_lock_Control *lock,
382 SMP_lock_Context *context
383);
384#else
385#define _SMP_lock_Release_and_ISR_enable( lock, context ) \
386 _SMP_lock_Release_and_ISR_enable_inline( lock, context )
387#endif
388
389#if defined(RTEMS_DEBUG)
398bool _SMP_lock_Is_owner( const SMP_lock_Control *lock );
399#endif
400
403#ifdef __cplusplus
404}
405#endif /* __cplusplus */
406
407#endif /* RTEMS_SMP */
408
409#endif /* _RTEMS_SCORE_SMPLOCK_H */
This header file provides the interfaces of the Assert Handler.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
#define _ISR_Local_disable(_level)
Disables interrupts on this processor.
Definition: isrlevel.h:76
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
Definition: isrlevel.h:93
uint32_t ISR_Level
Definition: isrlevel.h:60
#define NULL
Requests a GPIO pin group configuration.
Definition: xil_types.h:54
This header file provides the ISR_Level related interfaces of the ISR Handler.
rtems_termios_device_context * context
Definition: console-config.c:62
This header file provides interfaces of the SMP Support which are used by the implementation and the ...
This header file provides the interfaces of the SMP Locks related to lock statistics.
This header file provides the interfaces of the SMP Locks related to ticket locks.