RTEMS
smpbarrierwait.c
1 /*
2  * Copyright (c) 2013-2014 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 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18 
19 #include <rtems/score/smpbarrier.h>
20 
22  SMP_barrier_Control *control,
23  SMP_barrier_State *state,
24  unsigned int count
25 )
26 {
27  unsigned int sense = ~state->sense;
28  unsigned int previous_value;
29  bool performed_release;
30 
31  state->sense = sense;
32 
33  previous_value = _Atomic_Fetch_add_uint(
34  &control->value,
35  1U,
36  ATOMIC_ORDER_RELAXED
37  );
38 
39  if ( previous_value + 1U == count ) {
40  _Atomic_Store_uint( &control->value, 0U, ATOMIC_ORDER_RELAXED );
41  _Atomic_Store_uint( &control->sense, sense, ATOMIC_ORDER_RELEASE );
42  performed_release = true;
43  } else {
44  while (
45  _Atomic_Load_uint( &control->sense, ATOMIC_ORDER_ACQUIRE ) != sense
46  ) {
47  /* Wait */
48  }
49 
50  performed_release = false;
51  }
52 
53  return performed_release;
54 }
SMP barrier control.
Definition: smpbarrier.h:51
SMP Barrier API.
bool _SMP_barrier_Wait(SMP_barrier_Control *control, SMP_barrier_State *state, unsigned int count)
Waits on the SMP barrier until count threads rendezvoused.
SMP barrier per-thread state.
Definition: smpbarrier.h:61