From fd6fde85a9977c6f176aa1fd4a021ba021f0793f Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 19 Apr 2016 09:25:03 +0200 Subject: score: Add libatomic support Close #2695. --- cpukit/score/src/libatomic.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 cpukit/score/src/libatomic.c (limited to 'cpukit/score/src/libatomic.c') diff --git a/cpukit/score/src/libatomic.c b/cpukit/score/src/libatomic.c new file mode 100644 index 0000000000..bfa3e6fb25 --- /dev/null +++ b/cpukit/score/src/libatomic.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#if defined(RTEMS_SMP) +/* + * For real SMP targets this is not useful. The main purpose is support for + * testing on simulators like SIS. + */ +static Atomic_Flag _Libatomic_The_one_lock = ATOMIC_INITIALIZER_FLAG; +#endif + +__uint32_t _Libatomic_Protect_start( void *ptr ) +{ + ISR_Level isr_level; + + (void) ptr; + _ISR_Local_disable( isr_level ); + +#if defined(RTEMS_SMP) + while ( + _Atomic_Flag_test_and_set( &_Libatomic_The_one_lock, ATOMIC_ORDER_SEQ_CST ) + ) { + /* Next try. Yes, a TAS spin lock implementation is stupid. */ + } +#endif + + return isr_level; +} + +void _Libatomic_Protect_end( void *ptr, __uint32_t isr_level ) +{ + (void) ptr; + +#if defined(RTEMS_SMP) + _Atomic_Flag_clear( &_Libatomic_The_one_lock, ATOMIC_ORDER_SEQ_CST ); +#endif + + _ISR_Local_enable( isr_level ); +} + +/* + * FIXME: The once lock should be only a temporary solution. We need a + * dedicated internal mutex for this. + */ + +void _Libatomic_Lock_n( void *ptr, __size_t n ) +{ + (void) ptr; + (void) n; + _Once_Lock(); +} + +void _Libatomic_Unlock_n( void *ptr, __size_t n ) +{ + (void) ptr; + (void) n; + _Once_Unlock(); +} -- cgit v1.2.3