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 | Thread_Control *the_thread; |
---|
36 | |
---|
37 | do { |
---|
38 | POSIX_Condition_variables_Control *the_cond; |
---|
39 | ISR_lock_Context lock_context; |
---|
40 | |
---|
41 | the_cond = _POSIX_Condition_variables_Get( cond, &lock_context ); |
---|
42 | |
---|
43 | if ( the_cond == NULL ) { |
---|
44 | return EINVAL; |
---|
45 | } |
---|
46 | |
---|
47 | _POSIX_Condition_variables_Acquire_critical( the_cond, &lock_context ); |
---|
48 | |
---|
49 | the_thread = _Thread_queue_First_locked( |
---|
50 | &the_cond->Wait_queue, |
---|
51 | POSIX_CONDITION_VARIABLES_TQ_OPERATIONS |
---|
52 | ); |
---|
53 | |
---|
54 | if ( the_thread != NULL ) { |
---|
55 | _Thread_queue_Extract_critical( |
---|
56 | &the_cond->Wait_queue.Queue, |
---|
57 | POSIX_CONDITION_VARIABLES_TQ_OPERATIONS, |
---|
58 | the_thread, |
---|
59 | NULL, |
---|
60 | &lock_context |
---|
61 | ); |
---|
62 | } else { |
---|
63 | the_cond->mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX; |
---|
64 | _POSIX_Condition_variables_Release( the_cond, &lock_context ); |
---|
65 | } |
---|
66 | } while ( is_broadcast && the_thread != NULL ); |
---|
67 | |
---|
68 | return 0; |
---|
69 | } |
---|