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 <errno.h> |
---|
22 | #include <pthread.h> |
---|
23 | |
---|
24 | #include <rtems/system.h> |
---|
25 | #include <rtems/score/coremuteximpl.h> |
---|
26 | #include <rtems/score/watchdog.h> |
---|
27 | #include <rtems/posix/muteximpl.h> |
---|
28 | #include <rtems/posix/priorityimpl.h> |
---|
29 | |
---|
30 | /* |
---|
31 | * 11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87 |
---|
32 | */ |
---|
33 | |
---|
34 | int pthread_mutex_destroy( |
---|
35 | pthread_mutex_t *mutex |
---|
36 | ) |
---|
37 | { |
---|
38 | register POSIX_Mutex_Control *the_mutex; |
---|
39 | Objects_Locations location; |
---|
40 | |
---|
41 | _Objects_Allocator_lock(); |
---|
42 | the_mutex = _POSIX_Mutex_Get( mutex, &location ); |
---|
43 | switch ( location ) { |
---|
44 | |
---|
45 | case OBJECTS_LOCAL: |
---|
46 | /* |
---|
47 | * XXX: There is an error for the mutex being locked |
---|
48 | * or being in use by a condition variable. |
---|
49 | */ |
---|
50 | |
---|
51 | if ( _CORE_mutex_Is_locked( &the_mutex->Mutex ) ) { |
---|
52 | _Objects_Put( &the_mutex->Object ); |
---|
53 | _Objects_Allocator_unlock(); |
---|
54 | return EBUSY; |
---|
55 | } |
---|
56 | |
---|
57 | _Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object ); |
---|
58 | _CORE_mutex_Flush( &the_mutex->Mutex, EINVAL, NULL, 0 ); |
---|
59 | _Objects_Put( &the_mutex->Object ); |
---|
60 | _POSIX_Mutex_Free( the_mutex ); |
---|
61 | _Objects_Allocator_unlock(); |
---|
62 | |
---|
63 | return 0; |
---|
64 | |
---|
65 | #if defined(RTEMS_MULTIPROCESSING) |
---|
66 | case OBJECTS_REMOTE: |
---|
67 | #endif |
---|
68 | case OBJECTS_ERROR: |
---|
69 | break; |
---|
70 | } |
---|
71 | |
---|
72 | _Objects_Allocator_unlock(); |
---|
73 | |
---|
74 | return EINVAL; |
---|
75 | } |
---|