source: rtems/cpukit/score/src/libatomic.c @ 21275b58

5
Last change on this file since 21275b58 was 6c2b8a4b, checked in by Sebastian Huber <sebastian.huber@…>, on 11/29/17 at 05:23:27

score: Use self-contained API mutex

Use a self-contained recursive mutex for API_Mutex_Control. The API
mutexes are protected against asynchronous thread cancellation.

Add dedicated mutexes for libatomic and TOD.

Close #2629.
Close #2630.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 * Copyright (c) 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 <machine/_libatomic.h>
20
21#include <rtems/score/apimutex.h>
22#include <rtems/score/atomic.h>
23#include <rtems/score/isrlevel.h>
24
25#if defined(RTEMS_SMP)
26/*
27 * For real SMP targets this is not useful.  The main purpose is support for
28 * testing on simulators like SIS.
29 */
30static Atomic_Flag _Libatomic_The_one_lock = ATOMIC_INITIALIZER_FLAG;
31#endif
32
33__uint32_t _Libatomic_Protect_start( void *ptr )
34{
35  ISR_Level isr_level;
36
37  (void) ptr;
38  _ISR_Local_disable( isr_level );
39
40#if defined(RTEMS_SMP)
41  while (
42    _Atomic_Flag_test_and_set( &_Libatomic_The_one_lock, ATOMIC_ORDER_SEQ_CST )
43  ) {
44    /* Next try.  Yes, a TAS spin lock implementation is stupid. */
45  }
46#endif
47
48  return isr_level;
49}
50
51void _Libatomic_Protect_end( void *ptr, __uint32_t isr_level )
52{
53  (void) ptr;
54
55#if defined(RTEMS_SMP)
56  _Atomic_Flag_clear( &_Libatomic_The_one_lock, ATOMIC_ORDER_SEQ_CST );
57#endif
58
59  _ISR_Local_enable( isr_level );
60}
61
62static API_Mutex_Control _Libatomic_Mutex =
63  API_MUTEX_INITIALIZER( "_Libatomic" );
64
65void _Libatomic_Lock_n( void *ptr, __size_t n )
66{
67  (void) ptr;
68  (void) n;
69  _API_Mutex_Lock( &_Libatomic_Mutex );
70}
71
72void _Libatomic_Unlock_n( void *ptr, __size_t n )
73{
74  (void) ptr;
75  (void) n;
76  _API_Mutex_Unlock( &_Libatomic_Mutex );
77}
Note: See TracBrowser for help on using the repository browser.