source: rtems/cpukit/rtems/src/semrelease.c @ 66cb142

Last change on this file since 66cb142 was 8797c76, checked in by Sebastian Huber <sebastian.huber@…>, on Sep 27, 2016 at 1:23:00 PM

score: Unify CORE mutex seize/surrender

Use the Thread_Control::resource_count for the no protocol mutexes.
Merge the no protocol and priority inherit CORE mutex seize/surrender
operations.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS Semaphore Release
5 * @ingroup ClassicSem Semaphores
6 *
7 * This file contains the implementation of the Classic API directive
8 * rtems_semaphore_release().
9 */
10
11/*
12 *  COPYRIGHT (c) 1989-2014.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <rtems/rtems/semimpl.h>
25#include <rtems/rtems/statusimpl.h>
26
27rtems_status_code rtems_semaphore_release( rtems_id id )
28{
29  Semaphore_Control    *the_semaphore;
30  Thread_queue_Context  queue_context;
31  Thread_Control       *executing;
32  Status_Control        status;
33
34  the_semaphore = _Semaphore_Get( id, &queue_context );
35
36  if ( the_semaphore == NULL ) {
37#if defined(RTEMS_MULTIPROCESSING)
38    return _Semaphore_MP_Release( id );
39#else
40    return RTEMS_INVALID_ID;
41#endif
42  }
43
44  executing = _Thread_Executing;
45
46  _Thread_queue_Context_set_MP_callout(
47    &queue_context,
48    _Semaphore_Core_mutex_mp_support
49  );
50
51  switch ( the_semaphore->variant ) {
52    case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
53      status = _CORE_recursive_mutex_Surrender(
54        &the_semaphore->Core_control.Mutex.Recursive,
55        CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
56        executing,
57        &queue_context
58      );
59      break;
60    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
61      status = _CORE_ceiling_mutex_Surrender(
62        &the_semaphore->Core_control.Mutex,
63        executing,
64        &queue_context
65      );
66      break;
67    case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
68      status = _CORE_recursive_mutex_Surrender(
69        &the_semaphore->Core_control.Mutex.Recursive,
70        _Semaphore_Get_operations( the_semaphore ),
71        executing,
72        &queue_context
73      );
74      break;
75    case SEMAPHORE_VARIANT_SIMPLE_BINARY:
76      status = _CORE_semaphore_Surrender(
77        &the_semaphore->Core_control.Semaphore,
78        _Semaphore_Get_operations( the_semaphore ),
79        1,
80        &queue_context
81      );
82      _Assert(
83        status == STATUS_SUCCESSFUL
84          || status == STATUS_MAXIMUM_COUNT_EXCEEDED
85      );
86      status = STATUS_SUCCESSFUL;
87      break;
88#if defined(RTEMS_SMP)
89    case SEMAPHORE_VARIANT_MRSP:
90      status = _MRSP_Surrender(
91        &the_semaphore->Core_control.MRSP,
92        executing,
93        &queue_context
94      );
95      break;
96#endif
97    default:
98      _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
99      status = _CORE_semaphore_Surrender(
100        &the_semaphore->Core_control.Semaphore,
101        _Semaphore_Get_operations( the_semaphore ),
102        UINT32_MAX,
103        &queue_context
104      );
105      break;
106  }
107
108  return _Status_Get( status );
109}
Note: See TracBrowser for help on using the repository browser.