1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Destroy a RWLock |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | /* |
---|
8 | * COPYRIGHT (c) 1989-2007. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.org/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #if HAVE_CONFIG_H |
---|
17 | #include "config.h" |
---|
18 | #endif |
---|
19 | |
---|
20 | #include <rtems/posix/rwlockimpl.h> |
---|
21 | |
---|
22 | int pthread_rwlock_destroy( |
---|
23 | pthread_rwlock_t *rwlock |
---|
24 | ) |
---|
25 | { |
---|
26 | POSIX_RWLock_Control *the_rwlock; |
---|
27 | Thread_queue_Context queue_context; |
---|
28 | |
---|
29 | _Objects_Allocator_lock(); |
---|
30 | the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context ); |
---|
31 | |
---|
32 | if ( the_rwlock == NULL ) { |
---|
33 | _Objects_Allocator_unlock(); |
---|
34 | return EINVAL; |
---|
35 | } |
---|
36 | |
---|
37 | _CORE_RWLock_Acquire_critical( &the_rwlock->RWLock, &queue_context ); |
---|
38 | |
---|
39 | /* |
---|
40 | * If there is at least one thread waiting, then do not delete it. |
---|
41 | */ |
---|
42 | |
---|
43 | if ( !_Thread_queue_Is_empty( &the_rwlock->RWLock.Wait_queue.Queue ) ) { |
---|
44 | _CORE_RWLock_Release( &the_rwlock->RWLock, &queue_context ); |
---|
45 | _Objects_Allocator_unlock(); |
---|
46 | return EBUSY; |
---|
47 | } |
---|
48 | |
---|
49 | /* |
---|
50 | * POSIX doesn't require behavior when it is locked. |
---|
51 | */ |
---|
52 | |
---|
53 | _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object ); |
---|
54 | _CORE_RWLock_Release( &the_rwlock->RWLock, &queue_context ); |
---|
55 | _POSIX_RWLock_Free( the_rwlock ); |
---|
56 | _Objects_Allocator_unlock(); |
---|
57 | return 0; |
---|
58 | } |
---|