source: rtems/cpukit/score/src/corebarrierwait.c @ 469dc47

5
Last change on this file since 469dc47 was f27383a, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/16 at 12:01:02

score: Avoid Giant lock for barriers

Use _Thread_queue_Flush_critical() to atomically release the barrier.

Update #2555.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Wait For The Barrier
5 *  @ingroup ScoreBarrier
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2006.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/corebarrierimpl.h>
22#include <rtems/score/statesimpl.h>
23
24void _CORE_barrier_Do_seize(
25  CORE_barrier_Control    *the_barrier,
26  Thread_Control          *executing,
27  bool                     wait,
28  Watchdog_Interval        timeout,
29#if defined(RTEMS_MULTIPROCESSING)
30  Thread_queue_MP_callout  mp_callout,
31  Objects_Id               mp_id,
32#endif
33  ISR_lock_Context        *lock_context
34)
35{
36  uint32_t number_of_waiting_threads;
37
38  executing->Wait.return_code = CORE_BARRIER_STATUS_SUCCESSFUL;
39
40  _CORE_barrier_Acquire_critical( the_barrier, lock_context );
41
42  number_of_waiting_threads = the_barrier->number_of_waiting_threads;
43  ++number_of_waiting_threads;
44
45  if (
46    _CORE_barrier_Is_automatic( &the_barrier->Attributes )
47      && number_of_waiting_threads == the_barrier->Attributes.maximum_count
48  ) {
49    executing->Wait.return_code = CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED;
50    _CORE_barrier_Surrender( the_barrier, mp_callout, mp_id, lock_context );
51  } else {
52    the_barrier->number_of_waiting_threads = number_of_waiting_threads;
53    _Thread_queue_Enqueue_critical(
54      &the_barrier->Wait_queue.Queue,
55      CORE_BARRIER_TQ_OPERATIONS,
56      executing,
57      STATES_WAITING_FOR_BARRIER,
58      timeout,
59      CORE_BARRIER_TIMEOUT,
60      lock_context
61    );
62  }
63}
Note: See TracBrowser for help on using the repository browser.