RTEMS
semdelete.c
Go to the documentation of this file.
1 
8 /*
9  * COPYRIGHT (c) 1989-2014.
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 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <rtems/rtems/semimpl.h>
22 #include <rtems/rtems/statusimpl.h>
23 
25  rtems_id id
26 )
27 {
28  Semaphore_Control *the_semaphore;
29  Thread_queue_Context queue_context;
30  uintptr_t flags;
31  Semaphore_Variant variant;
32  Status_Control status;
33 
35  the_semaphore = _Semaphore_Get( id, &queue_context );
36 
37  if ( the_semaphore == NULL ) {
39 
40 #if defined(RTEMS_MULTIPROCESSING)
41  if ( _Semaphore_MP_Is_remote( id ) ) {
43  }
44 #endif
45 
46  return RTEMS_INVALID_ID;
47  }
48 
50  &the_semaphore->Core_control.Wait_queue,
51  &queue_context
52  );
53  flags = _Semaphore_Get_flags( the_semaphore );
54  variant = _Semaphore_Get_variant( flags );
55 
56  switch ( variant ) {
57  case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
58  case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
59  case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
60  if (
62  &the_semaphore->Core_control.Mutex.Recursive.Mutex
63  )
64  ) {
65  status = STATUS_RESOURCE_IN_USE;
66  } else {
67  status = STATUS_SUCCESSFUL;
68  }
69 
70  break;
71 #if defined(RTEMS_SMP)
72  case SEMAPHORE_VARIANT_MRSP:
73  status = _MRSP_Can_destroy( &the_semaphore->Core_control.MRSP );
74  break;
75 #endif
76  default:
77  _Assert(
78  variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
79  || variant == SEMAPHORE_VARIANT_COUNTING
80  );
81  status = STATUS_SUCCESSFUL;
82  break;
83  }
84 
85  if ( status != STATUS_SUCCESSFUL ) {
87  &the_semaphore->Core_control.Wait_queue,
88  &queue_context
89  );
91  return _Status_Get( status );
92  }
93 
94  _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
95 
96  switch ( variant ) {
97 #if defined(RTEMS_SMP)
98  case SEMAPHORE_VARIANT_MRSP:
99  _MRSP_Destroy( &the_semaphore->Core_control.MRSP, &queue_context );
100  break;
101 #endif
102  default:
103  _Assert(
104  variant == SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY
105  || variant == SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING
106  || variant == SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL
107  || variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
108  || variant == SEMAPHORE_VARIANT_COUNTING
109  );
111  &the_semaphore->Core_control.Wait_queue.Queue,
112  _Semaphore_Get_operations( flags ),
114  &queue_context
115  );
116  _Thread_queue_Destroy( &the_semaphore->Core_control.Wait_queue );
117  break;
118  }
119 
120 #if defined(RTEMS_MULTIPROCESSING)
121  if ( _Semaphore_Is_global( flags ) ) {
122 
123  _Objects_MP_Close( &_Semaphore_Information, id );
124 
125  _Semaphore_MP_Send_process_packet(
126  SEMAPHORE_MP_ANNOUNCE_DELETE,
127  id,
128  0, /* Not used */
129  0 /* Not used */
130  );
131  }
132 #endif
133 
134  _Semaphore_Free( the_semaphore );
136  return RTEMS_SUCCESSFUL;
137 }
static __inline__ void _Thread_queue_Acquire_critical(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Acquires the thread queue control in a critical section.
Definition: threadqimpl.h:681
static __inline__ void _Objects_Allocator_unlock(void)
Unlocks the object allocator mutex.
Definition: objectimpl.h:846
Thread queue context for the thread queue methods.
Definition: threadq.h:198
static __inline__ bool _CORE_mutex_Is_locked(const CORE_mutex_Control *the_mutex)
Checks if the mutex is locked.
CORE_ceiling_mutex_Control Mutex
Definition: semdata.h:71
CORE_recursive_mutex_Control Recursive
The plain recursive mutex.
Definition: coremutex.h:87
Thread_queue_Control Wait_queue
The thread queue present in all other variants.
Definition: semdata.h:65
Objects_Control Object
The object management portion of a semaphore instance.
Definition: semdata.h:50
static __inline__ void _Objects_Allocator_lock(void)
Locks the object allocator mutex.
Definition: objectimpl.h:834
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:583
This status code indicates successful completion.
Definition: status.h:86
Classic Semaphore Manager Implementation.
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
size_t _Thread_queue_Flush_critical(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_queue_Flush_filter filter, Thread_queue_Context *queue_context)
Unblocks all threads enqueued on the thread queue.
Definition: threadqflush.c:63
Classic Status Implementation.
CORE_mutex_Control Mutex
The plain non-recursive mutex.
Definition: coremutex.h:72
static __inline__ void _Semaphore_Free(Semaphore_Control *the_semaphore)
Frees a semaphore control block to the inactive chain of free semaphore control blocks.
Definition: semimpl.h:156
Thread_Control * _Thread_queue_Flush_status_object_was_deleted(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Status object was deleted thread queue flush filter function.
Definition: threadqflush.c:37
This status code indicates that an object identifier was invalid.
Definition: status.h:106
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99
This status code indicates that the operation was illegal on a remote object.
Definition: status.h:177
Objects_Information _Semaphore_Information
The Classic Semaphore objects information.
Definition: sem.c:47
static __inline__ Status_Control _MRSP_Can_destroy(MRSP_Control *mrsp)
Checks if the MrsP control can be destroyed.
Definition: mrspimpl.h:497
static __inline__ void _MRSP_Destroy(MRSP_Control *mrsp, Thread_queue_Context *queue_context)
Destroys the MrsP control.
Definition: mrspimpl.h:512
static __inline__ void _Thread_queue_Destroy(Thread_queue_Control *the_thread_queue)
Destroys the thread queue.
Definition: threadqimpl.h:1378
void _Thread_queue_Release(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Releases the thread queue control and enables interrupts.
Definition: threadq.c:118
rtems_status_code rtems_semaphore_delete(rtems_id id)
%
Definition: semdelete.c:24
union Semaphore_Control::@8 Core_control
Semaphore_Variant
Classic semaphore variants.
Definition: semimpl.h:42
void _Objects_Close(const Objects_Information *information, Objects_Control *the_object)
Closes object.
Definition: objectclose.c:23
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100