1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Destroy a Condition Variable |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2007. |
---|
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 | * 11.4.2 Initializing and Destroying a Condition Variable, |
---|
25 | * P1003.1c/Draft 10, p. 87 |
---|
26 | */ |
---|
27 | int pthread_cond_destroy( |
---|
28 | pthread_cond_t *cond |
---|
29 | ) |
---|
30 | { |
---|
31 | POSIX_Condition_variables_Control *the_cond; |
---|
32 | Thread_queue_Context queue_context; |
---|
33 | |
---|
34 | _Objects_Allocator_lock(); |
---|
35 | the_cond = _POSIX_Condition_variables_Get( cond, &queue_context ); |
---|
36 | |
---|
37 | if ( the_cond == NULL ) { |
---|
38 | _Objects_Allocator_unlock(); |
---|
39 | return EINVAL; |
---|
40 | } |
---|
41 | |
---|
42 | _POSIX_Condition_variables_Acquire_critical( the_cond, &queue_context ); |
---|
43 | |
---|
44 | if ( !_Thread_queue_Is_empty( &the_cond->Wait_queue.Queue ) ) { |
---|
45 | _POSIX_Condition_variables_Release( the_cond, &queue_context ); |
---|
46 | _Objects_Allocator_unlock(); |
---|
47 | return EBUSY; |
---|
48 | } |
---|
49 | |
---|
50 | _Objects_Close( |
---|
51 | &_POSIX_Condition_variables_Information, |
---|
52 | &the_cond->Object |
---|
53 | ); |
---|
54 | _POSIX_Condition_variables_Release( the_cond, &queue_context ); |
---|
55 | _POSIX_Condition_variables_Destroy( the_cond ); |
---|
56 | _POSIX_Condition_variables_Free( the_cond ); |
---|
57 | _Objects_Allocator_unlock(); |
---|
58 | return 0; |
---|
59 | } |
---|