1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Implements wake up version of the "signal" operation |
---|
5 | * @ingroup POSIX_COND_VARS Condition Variables |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
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/posix/condimpl.h> |
---|
22 | |
---|
23 | /* |
---|
24 | * _POSIX_Condition_variables_Signal_support |
---|
25 | * |
---|
26 | * A support routine which implements guts of the broadcast and single task |
---|
27 | * wake up version of the "signal" operation. |
---|
28 | */ |
---|
29 | |
---|
30 | int _POSIX_Condition_variables_Signal_support( |
---|
31 | pthread_cond_t *cond, |
---|
32 | bool is_broadcast |
---|
33 | ) |
---|
34 | { |
---|
35 | POSIX_Condition_variables_Control *the_cond; |
---|
36 | unsigned long flags; |
---|
37 | const Thread_queue_Operations *operations; |
---|
38 | Thread_queue_Heads *heads; |
---|
39 | |
---|
40 | the_cond = _POSIX_Condition_variables_Get( cond ); |
---|
41 | POSIX_CONDITION_VARIABLES_VALIDATE_OBJECT( the_cond, flags ); |
---|
42 | operations = POSIX_CONDITION_VARIABLES_TQ_OPERATIONS; |
---|
43 | |
---|
44 | do { |
---|
45 | Thread_queue_Context queue_context; |
---|
46 | |
---|
47 | _Thread_queue_Context_initialize( &queue_context ); |
---|
48 | _POSIX_Condition_variables_Acquire( the_cond, &queue_context ); |
---|
49 | |
---|
50 | heads = the_cond->Queue.Queue.heads; |
---|
51 | |
---|
52 | if ( heads != NULL ) { |
---|
53 | Thread_Control *the_thread; |
---|
54 | |
---|
55 | the_thread = ( *operations->first )( heads ); |
---|
56 | _Thread_queue_Extract_critical( |
---|
57 | &the_cond->Queue.Queue, |
---|
58 | operations, |
---|
59 | the_thread, |
---|
60 | &queue_context |
---|
61 | ); |
---|
62 | } else { |
---|
63 | the_cond->mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX; |
---|
64 | _POSIX_Condition_variables_Release( the_cond, &queue_context ); |
---|
65 | } |
---|
66 | } while ( is_broadcast && heads != NULL ); |
---|
67 | |
---|
68 | return 0; |
---|
69 | } |
---|