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 | */ |
---|
30 | static 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 | |
---|
51 | void _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 | |
---|
62 | /* |
---|
63 | * FIXME: The once lock should be only a temporary solution. We need a |
---|
64 | * dedicated internal mutex for this. |
---|
65 | */ |
---|
66 | |
---|
67 | void _Libatomic_Lock_n( void *ptr, __size_t n ) |
---|
68 | { |
---|
69 | (void) ptr; |
---|
70 | (void) n; |
---|
71 | _Once_Lock(); |
---|
72 | } |
---|
73 | |
---|
74 | void _Libatomic_Unlock_n( void *ptr, __size_t n ) |
---|
75 | { |
---|
76 | (void) ptr; |
---|
77 | (void) n; |
---|
78 | _Once_Unlock(); |
---|
79 | } |
---|