From ad7292f26465027cb8fd5494e613f5bd63607623 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 14 Feb 2014 12:57:53 +0100 Subject: score: Add SMP barrier --- cpukit/score/include/rtems/score/smpbarrier.h | 127 ++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 cpukit/score/include/rtems/score/smpbarrier.h (limited to 'cpukit/score/include/rtems/score/smpbarrier.h') diff --git a/cpukit/score/include/rtems/score/smpbarrier.h b/cpukit/score/include/rtems/score/smpbarrier.h new file mode 100644 index 0000000000..549887d0ae --- /dev/null +++ b/cpukit/score/include/rtems/score/smpbarrier.h @@ -0,0 +1,127 @@ +/** + * @file + * + * @ingroup ScoreSMPBarrier + * + * @brief SMP Barrier API + */ + +/* + * Copyright (c) 2013-2014 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.com/license/LICENSE. + */ + +#ifndef _RTEMS_SCORE_SMPBARRIER_H +#define _RTEMS_SCORE_SMPBARRIER_H + +#include + +#if defined( RTEMS_SMP ) + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @defgroup ScoreSMPBarrier SMP Barriers + * + * @ingroup Score + * + * @brief The SMP barrier provides barrier synchronization for SMP systems at + * the lowest level. + * + * The SMP barrier is implemented as a sense barrier, see also Herlihy and + * Shavit, "The Art of Multiprocessor Programming", 17.3 Sense-Reversing + * Barrier. + * + * @{ + */ + +/** + * @brief SMP barrier control. + */ +typedef struct { + Atomic_Uint value; + Atomic_Uint sense; +} SMP_barrier_Control; + +/** + * @brief SMP barrier per-thread state. + * + * Each user of the barrier must provide this per-thread state. + */ +typedef struct { + unsigned int sense; +} SMP_barrier_State; + +/** + * @brief SMP barrier control initializer for static initialization. + */ +#define SMP_BARRIER_CONTROL_INITIALIZER \ + { ATOMIC_INITIALIZER_UINT( 0U ), ATOMIC_INITIALIZER_UINT( 0U ) } + +/** + * @brief SMP barrier per-thread state initializer for static initialization. + */ +#define SMP_BARRIER_STATE_INITIALIZER { 0U } + +/** + * @brief Initializes a SMP barrier control. + * + * Concurrent initialization leads to unpredictable results. + * + * @param[out] control The SMP barrier control. + */ +static inline void _SMP_barrier_Control_initialize( + SMP_barrier_Control *control +) +{ + _Atomic_Init_uint( &control->value, 0U ); + _Atomic_Init_uint( &control->sense, 0U ); +} + +/** + * @brief Initializes a SMP barrier per-thread state. + * + * @param[out] state The SMP barrier control. + */ +static inline void _SMP_barrier_State_initialize( + SMP_barrier_State *state +) +{ + state->sense = 0U; +} + +/** + * @brief Waits on the SMP barrier until count threads rendezvoused. + * + * @param[in, out] control The SMP barrier control. + * @param[in, out] state The SMP barrier per-thread state. + * @param[in] count The thread count bound to rendezvous. + */ +void _SMP_barrier_Wait( + SMP_barrier_Control *control, + SMP_barrier_State *state, + unsigned int count +); + +/**@}*/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* defined( RTEMS_SMP ) */ + +#endif /* _RTEMS_SCORE_SMPBARRIER_H */ -- cgit v1.2.3