1 | /* |
---|
2 | * $Id$ |
---|
3 | */ |
---|
4 | |
---|
5 | #include <assert.h> |
---|
6 | #include <errno.h> |
---|
7 | #include <pthread.h> |
---|
8 | |
---|
9 | #include <rtems/system.h> |
---|
10 | #include <rtems/score/coremutex.h> |
---|
11 | #include <rtems/score/watchdog.h> |
---|
12 | #if defined(RTEMS_MULTIPROCESSING) |
---|
13 | #include <rtems/score/mpci.h> |
---|
14 | #endif |
---|
15 | #include <rtems/posix/mutex.h> |
---|
16 | #include <rtems/posix/priority.h> |
---|
17 | #include <rtems/posix/time.h> |
---|
18 | |
---|
19 | /*PAGE |
---|
20 | * |
---|
21 | * 11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87 |
---|
22 | */ |
---|
23 | |
---|
24 | int pthread_mutex_destroy( |
---|
25 | pthread_mutex_t *mutex |
---|
26 | ) |
---|
27 | { |
---|
28 | register POSIX_Mutex_Control *the_mutex; |
---|
29 | Objects_Locations location; |
---|
30 | |
---|
31 | the_mutex = _POSIX_Mutex_Get( mutex, &location ); |
---|
32 | switch ( location ) { |
---|
33 | case OBJECTS_REMOTE: |
---|
34 | #if defined(RTEMS_MULTIPROCESSING) |
---|
35 | _Thread_Dispatch(); |
---|
36 | return POSIX_MP_NOT_IMPLEMENTED(); |
---|
37 | return EINVAL; |
---|
38 | #endif |
---|
39 | case OBJECTS_ERROR: |
---|
40 | return EINVAL; |
---|
41 | case OBJECTS_LOCAL: |
---|
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 | _Thread_Enable_dispatch(); |
---|
49 | return EBUSY; |
---|
50 | } |
---|
51 | |
---|
52 | _Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object ); |
---|
53 | |
---|
54 | _CORE_mutex_Flush( |
---|
55 | &the_mutex->Mutex, |
---|
56 | #if defined(RTEMS_MULTIPROCESSING) |
---|
57 | _POSIX_Mutex_MP_Send_object_was_deleted, |
---|
58 | #else |
---|
59 | NULL, |
---|
60 | #endif |
---|
61 | EINVAL |
---|
62 | ); |
---|
63 | |
---|
64 | _POSIX_Mutex_Free( the_mutex ); |
---|
65 | |
---|
66 | #if defined(RTEMS_MULTIPROCESSING) |
---|
67 | if ( the_mutex->process_shared == PTHREAD_PROCESS_SHARED ) { |
---|
68 | |
---|
69 | _Objects_MP_Close( &_POSIX_Mutex_Information, the_mutex->Object.id ); |
---|
70 | |
---|
71 | _POSIX_Mutex_MP_Send_process_packet( |
---|
72 | POSIX_MUTEX_MP_ANNOUNCE_DELETE, |
---|
73 | the_mutex->Object.id, |
---|
74 | 0, /* Not used */ |
---|
75 | 0 /* Not used */ |
---|
76 | ); |
---|
77 | } |
---|
78 | #endif |
---|
79 | _Thread_Enable_dispatch(); |
---|
80 | return 0; |
---|
81 | } |
---|
82 | return POSIX_BOTTOM_REACHED(); |
---|
83 | } |
---|