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/isrlevel.h> |
---|
23 | #include <rtems/score/statesimpl.h> |
---|
24 | #include <rtems/score/threadqimpl.h> |
---|
25 | |
---|
26 | void _CORE_barrier_Wait( |
---|
27 | CORE_barrier_Control *the_barrier, |
---|
28 | Thread_Control *executing, |
---|
29 | Objects_Id id, |
---|
30 | bool wait, |
---|
31 | Watchdog_Interval timeout, |
---|
32 | CORE_barrier_API_mp_support_callout api_barrier_mp_support |
---|
33 | ) |
---|
34 | { |
---|
35 | ISR_lock_Context lock_context; |
---|
36 | |
---|
37 | executing->Wait.return_code = CORE_BARRIER_STATUS_SUCCESSFUL; |
---|
38 | _Thread_queue_Acquire( &the_barrier->Wait_queue, &lock_context ); |
---|
39 | the_barrier->number_of_waiting_threads++; |
---|
40 | if ( _CORE_barrier_Is_automatic( &the_barrier->Attributes ) ) { |
---|
41 | if ( the_barrier->number_of_waiting_threads == |
---|
42 | the_barrier->Attributes.maximum_count) { |
---|
43 | executing->Wait.return_code = CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED; |
---|
44 | _Thread_queue_Release( &the_barrier->Wait_queue, &lock_context ); |
---|
45 | _CORE_barrier_Release( the_barrier, id, api_barrier_mp_support ); |
---|
46 | return; |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | executing->Wait.id = id; |
---|
51 | |
---|
52 | _Thread_queue_Enqueue_critical( |
---|
53 | &the_barrier->Wait_queue.Queue, |
---|
54 | the_barrier->Wait_queue.operations, |
---|
55 | executing, |
---|
56 | STATES_WAITING_FOR_BARRIER, |
---|
57 | timeout, |
---|
58 | CORE_BARRIER_TIMEOUT, |
---|
59 | &lock_context |
---|
60 | ); |
---|
61 | } |
---|