1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Initializing and Destroying a Mutex |
---|
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/muteximpl.h> |
---|
22 | |
---|
23 | /* |
---|
24 | * 11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87 |
---|
25 | */ |
---|
26 | |
---|
27 | int pthread_mutex_destroy( |
---|
28 | pthread_mutex_t *mutex |
---|
29 | ) |
---|
30 | { |
---|
31 | POSIX_Mutex_Control *the_mutex; |
---|
32 | Thread_queue_Context queue_context; |
---|
33 | int eno; |
---|
34 | |
---|
35 | _Objects_Allocator_lock(); |
---|
36 | |
---|
37 | the_mutex = _POSIX_Mutex_Get( mutex, &queue_context ); |
---|
38 | |
---|
39 | if ( the_mutex != NULL ) { |
---|
40 | _CORE_mutex_Acquire_critical( &the_mutex->Mutex, &queue_context ); |
---|
41 | |
---|
42 | /* |
---|
43 | * XXX: There is an error for the mutex being locked |
---|
44 | * or being in use by a condition variable. |
---|
45 | */ |
---|
46 | |
---|
47 | if ( !_CORE_mutex_Is_locked( &the_mutex->Mutex ) ) { |
---|
48 | _Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object ); |
---|
49 | _CORE_mutex_Release( &the_mutex->Mutex, &queue_context ); |
---|
50 | _CORE_mutex_Destroy( &the_mutex->Mutex ); |
---|
51 | _POSIX_Mutex_Free( the_mutex ); |
---|
52 | eno = 0; |
---|
53 | } else { |
---|
54 | _CORE_mutex_Release( &the_mutex->Mutex, &queue_context ); |
---|
55 | eno = EBUSY; |
---|
56 | } |
---|
57 | } else { |
---|
58 | eno = EINVAL; |
---|
59 | } |
---|
60 | |
---|
61 | _Objects_Allocator_unlock(); |
---|
62 | return eno; |
---|
63 | } |
---|