1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Destroy a Barrier Object |
---|
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/barrierimpl.h> |
---|
22 | |
---|
23 | /** |
---|
24 | * This directive allows a thread to delete a barrier specified by |
---|
25 | * the barrier id. The barrier is freed back to the inactive |
---|
26 | * barrier chain. |
---|
27 | * |
---|
28 | * @param[in] barrier is the barrier id |
---|
29 | * |
---|
30 | * @return This method returns 0 if there was not an |
---|
31 | * error. Otherwise, a status code is returned indicating the |
---|
32 | * source of the error. |
---|
33 | */ |
---|
34 | int pthread_barrier_destroy( |
---|
35 | pthread_barrier_t *barrier |
---|
36 | ) |
---|
37 | { |
---|
38 | POSIX_Barrier_Control *the_barrier; |
---|
39 | Thread_queue_Context queue_context; |
---|
40 | |
---|
41 | if ( barrier == NULL ) { |
---|
42 | return EINVAL; |
---|
43 | } |
---|
44 | |
---|
45 | _Objects_Allocator_lock(); |
---|
46 | the_barrier = _POSIX_Barrier_Get( barrier, &queue_context ); |
---|
47 | |
---|
48 | if ( the_barrier == NULL ) { |
---|
49 | _Objects_Allocator_unlock(); |
---|
50 | return EINVAL; |
---|
51 | } |
---|
52 | |
---|
53 | _CORE_barrier_Acquire_critical( &the_barrier->Barrier, &queue_context ); |
---|
54 | |
---|
55 | if ( the_barrier->Barrier.number_of_waiting_threads != 0 ) { |
---|
56 | _CORE_barrier_Release( &the_barrier->Barrier, &queue_context ); |
---|
57 | _Objects_Allocator_unlock(); |
---|
58 | return EBUSY; |
---|
59 | } |
---|
60 | |
---|
61 | _Objects_Close( &_POSIX_Barrier_Information, &the_barrier->Object ); |
---|
62 | _CORE_barrier_Release( &the_barrier->Barrier, &queue_context ); |
---|
63 | _POSIX_Barrier_Free( the_barrier ); |
---|
64 | _Objects_Allocator_unlock(); |
---|
65 | return 0; |
---|
66 | } |
---|