1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Delete Semaphore |
---|
5 | * @ingroup ClassicSem |
---|
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.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/rtems/status.h> |
---|
23 | #include <rtems/rtems/support.h> |
---|
24 | #include <rtems/rtems/attr.h> |
---|
25 | #include <rtems/score/isr.h> |
---|
26 | #include <rtems/score/object.h> |
---|
27 | #include <rtems/rtems/options.h> |
---|
28 | #include <rtems/rtems/sem.h> |
---|
29 | #include <rtems/score/coremutex.h> |
---|
30 | #include <rtems/score/coresem.h> |
---|
31 | #include <rtems/score/states.h> |
---|
32 | #include <rtems/score/thread.h> |
---|
33 | #include <rtems/score/threadq.h> |
---|
34 | #if defined(RTEMS_MULTIPROCESSING) |
---|
35 | #include <rtems/score/mpci.h> |
---|
36 | #endif |
---|
37 | #include <rtems/score/sysstate.h> |
---|
38 | |
---|
39 | #include <rtems/score/interr.h> |
---|
40 | |
---|
41 | #if defined(RTEMS_MULTIPROCESSING) |
---|
42 | #define SEMAPHORE_MP_OBJECT_WAS_DELETED _Semaphore_MP_Send_object_was_deleted |
---|
43 | #else |
---|
44 | #define SEMAPHORE_MP_OBJECT_WAS_DELETED NULL |
---|
45 | #endif |
---|
46 | |
---|
47 | rtems_status_code rtems_semaphore_delete( |
---|
48 | rtems_id id |
---|
49 | ) |
---|
50 | { |
---|
51 | register Semaphore_Control *the_semaphore; |
---|
52 | Objects_Locations location; |
---|
53 | |
---|
54 | the_semaphore = _Semaphore_Get( id, &location ); |
---|
55 | switch ( location ) { |
---|
56 | |
---|
57 | case OBJECTS_LOCAL: |
---|
58 | if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) { |
---|
59 | if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) && |
---|
60 | !_Attributes_Is_simple_binary_semaphore( |
---|
61 | the_semaphore->attribute_set ) ) { |
---|
62 | _Thread_Enable_dispatch(); |
---|
63 | return RTEMS_RESOURCE_IN_USE; |
---|
64 | } |
---|
65 | _CORE_mutex_Flush( |
---|
66 | &the_semaphore->Core_control.mutex, |
---|
67 | SEMAPHORE_MP_OBJECT_WAS_DELETED, |
---|
68 | CORE_MUTEX_WAS_DELETED |
---|
69 | ); |
---|
70 | } else { |
---|
71 | _CORE_semaphore_Flush( |
---|
72 | &the_semaphore->Core_control.semaphore, |
---|
73 | SEMAPHORE_MP_OBJECT_WAS_DELETED, |
---|
74 | CORE_SEMAPHORE_WAS_DELETED |
---|
75 | ); |
---|
76 | } |
---|
77 | |
---|
78 | _Objects_Close( &_Semaphore_Information, &the_semaphore->Object ); |
---|
79 | |
---|
80 | _Semaphore_Free( the_semaphore ); |
---|
81 | |
---|
82 | #if defined(RTEMS_MULTIPROCESSING) |
---|
83 | if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) { |
---|
84 | |
---|
85 | _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id ); |
---|
86 | |
---|
87 | _Semaphore_MP_Send_process_packet( |
---|
88 | SEMAPHORE_MP_ANNOUNCE_DELETE, |
---|
89 | the_semaphore->Object.id, |
---|
90 | 0, /* Not used */ |
---|
91 | 0 /* Not used */ |
---|
92 | ); |
---|
93 | } |
---|
94 | #endif |
---|
95 | _Thread_Enable_dispatch(); |
---|
96 | return RTEMS_SUCCESSFUL; |
---|
97 | |
---|
98 | #if defined(RTEMS_MULTIPROCESSING) |
---|
99 | case OBJECTS_REMOTE: |
---|
100 | _Thread_Dispatch(); |
---|
101 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
102 | #endif |
---|
103 | |
---|
104 | case OBJECTS_ERROR: |
---|
105 | break; |
---|
106 | } |
---|
107 | |
---|
108 | return RTEMS_INVALID_ID; |
---|
109 | } |
---|