RTEMS
semrelease.c
Go to the documentation of this file.
1 
12 /*
13  * COPYRIGHT (c) 1989-2014.
14  * On-Line Applications Research Corporation (OAR).
15  *
16  * The license and distribution terms for this file may be
17  * found in the file LICENSE in this distribution or at
18  * http://www.rtems.org/license/LICENSE.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <rtems/rtems/semimpl.h>
26 #include <rtems/rtems/statusimpl.h>
27 
29 {
30  Semaphore_Control *the_semaphore;
31  Thread_queue_Context queue_context;
32  Thread_Control *executing;
33  uintptr_t flags;
34  Semaphore_Variant variant;
35  Status_Control status;
36 
37  the_semaphore = _Semaphore_Get( id, &queue_context );
38 
39  if ( the_semaphore == NULL ) {
40 #if defined(RTEMS_MULTIPROCESSING)
41  return _Semaphore_MP_Release( id );
42 #else
43  return RTEMS_INVALID_ID;
44 #endif
45  }
46 
47  executing = _Thread_Executing;
48 
50  &queue_context,
51  _Semaphore_Core_mutex_mp_support
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:
59  &the_semaphore->Core_control.Mutex.Recursive,
60  CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
61  executing,
62  &queue_context
63  );
64  break;
65  case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
67  &the_semaphore->Core_control.Mutex,
68  executing,
69  &queue_context
70  );
71  break;
72  case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
74  &the_semaphore->Core_control.Mutex.Recursive,
75  _Semaphore_Get_operations( flags ),
76  executing,
77  &queue_context
78  );
79  break;
80  case SEMAPHORE_VARIANT_SIMPLE_BINARY:
82  &the_semaphore->Core_control.Semaphore,
83  _Semaphore_Get_operations( flags ),
84  1,
85  &queue_context
86  );
87  _Assert(
88  status == STATUS_SUCCESSFUL
89  || status == STATUS_MAXIMUM_COUNT_EXCEEDED
90  );
91  status = STATUS_SUCCESSFUL;
92  break;
93 #if defined(RTEMS_SMP)
94  case SEMAPHORE_VARIANT_MRSP:
95  status = _MRSP_Surrender(
96  &the_semaphore->Core_control.MRSP,
97  executing,
98  &queue_context
99  );
100  break;
101 #endif
102  default:
103  _Assert( variant == SEMAPHORE_VARIANT_COUNTING );
104  status = _CORE_semaphore_Surrender(
105  &the_semaphore->Core_control.Semaphore,
106  _Semaphore_Get_operations( flags ),
107  UINT32_MAX,
108  &queue_context
109  );
110  break;
111  }
112 
113  return _Status_Get( status );
114 }
Thread queue context for the thread queue methods.
Definition: threadq.h:198
#define _Thread_queue_Context_set_MP_callout(queue_context, mp_callout)
Sets the MP callout in the thread queue context.
Definition: threadqimpl.h:456
static __inline__ Status_Control _CORE_semaphore_Surrender(CORE_semaphore_Control *the_semaphore, const Thread_queue_Operations *operations, uint32_t maximum_count, Thread_queue_Context *queue_context)
Surrenders a unit to the semaphore.
Definition: coresemimpl.h:131
CORE_ceiling_mutex_Control Mutex
Definition: semdata.h:71
CORE_recursive_mutex_Control Recursive
The plain recursive mutex.
Definition: coremutex.h:87
rtems_status_code rtems_semaphore_release(rtems_id id)
%
Definition: semrelease.c:28
Classic Semaphore Manager Implementation.
static __inline__ Status_Control _CORE_ceiling_mutex_Surrender(CORE_ceiling_mutex_Control *the_mutex, Thread_Control *executing, Thread_queue_Context *queue_context)
Surrenders the ceiling mutex.
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
Classic Status Implementation.
static __inline__ Status_Control _MRSP_Surrender(MRSP_Control *mrsp, Thread_Control *executing, Thread_queue_Context *queue_context)
Surrenders the MrsP control.
Definition: mrspimpl.h:445
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
CORE_semaphore_Control Semaphore
Definition: semdata.h:77
union Semaphore_Control::@8 Core_control
Semaphore_Variant
Classic semaphore variants.
Definition: semimpl.h:42
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
static __inline__ Status_Control _CORE_recursive_mutex_Surrender(CORE_recursive_mutex_Control *the_mutex, const Thread_queue_Operations *operations, Thread_Control *executing, Thread_queue_Context *queue_context)
Surrenders the recursive mutex.