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 <pthread.h> |
---|
21 | #include <errno.h> |
---|
22 | |
---|
23 | #include <rtems/posix/rwlockimpl.h> |
---|
24 | #include <rtems/score/threadqimpl.h> |
---|
25 | |
---|
26 | /** |
---|
27 | * This directive allows a thread to delete a rwlock specified by |
---|
28 | * the rwlock id. The rwlock is freed back to the inactive |
---|
29 | * rwlock chain. |
---|
30 | * |
---|
31 | * @param[in] rwlock is the rwlock id |
---|
32 | * |
---|
33 | * @return This method returns 0 if there was not an |
---|
34 | * error. Otherwise, a status code is returned indicating the |
---|
35 | * source of the error. |
---|
36 | */ |
---|
37 | int pthread_rwlock_destroy( |
---|
38 | pthread_rwlock_t *rwlock |
---|
39 | ) |
---|
40 | { |
---|
41 | POSIX_RWLock_Control *the_rwlock = NULL; |
---|
42 | Objects_Locations location; |
---|
43 | |
---|
44 | if ( !rwlock ) |
---|
45 | return EINVAL; |
---|
46 | |
---|
47 | the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); |
---|
48 | switch ( location ) { |
---|
49 | |
---|
50 | case OBJECTS_LOCAL: |
---|
51 | /* |
---|
52 | * If there is at least one thread waiting, then do not delete it. |
---|
53 | */ |
---|
54 | if ( _Thread_queue_First( &the_rwlock->RWLock.Wait_queue ) != NULL ) { |
---|
55 | _Objects_Put( &the_rwlock->Object ); |
---|
56 | return EBUSY; |
---|
57 | } |
---|
58 | |
---|
59 | /* |
---|
60 | * POSIX doesn't require behavior when it is locked. |
---|
61 | */ |
---|
62 | |
---|
63 | _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object ); |
---|
64 | |
---|
65 | _POSIX_RWLock_Free( the_rwlock ); |
---|
66 | |
---|
67 | _Objects_Put( &the_rwlock->Object ); |
---|
68 | return 0; |
---|
69 | |
---|
70 | #if defined(RTEMS_MULTIPROCESSING) |
---|
71 | case OBJECTS_REMOTE: |
---|
72 | #endif |
---|
73 | case OBJECTS_ERROR: |
---|
74 | break; |
---|
75 | } |
---|
76 | |
---|
77 | return EINVAL; |
---|
78 | } |
---|