source: rtems/cpukit/rtems/src/semrelease.c @ 0b713f89

Last change on this file since 0b713f89 was 0b713f89, checked in by Sebastian Huber <sebastian.huber@…>, on May 30, 2016 at 4:59:55 AM

score: Rework CORE inherit priority mutex

Provide dedicated seize and surrender methods for inherit priority
mutexes. This eliminates CORE_mutex_Attributes.

  • 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#if defined(RTEMS_SMP)
53    case SEMAPHORE_VARIANT_MRSP:
54      status = _MRSP_Surrender(
55        &the_semaphore->Core_control.mrsp,
56        executing,
57        &queue_context
58      );
59      break;
60#endif
61    case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
62      status = _CORE_recursive_mutex_Surrender(
63        &the_semaphore->Core_control.Mutex.Recursive,
64        executing,
65        &queue_context
66      );
67      break;
68    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
69      status = _CORE_ceiling_mutex_Surrender(
70        &the_semaphore->Core_control.Mutex,
71        executing,
72        &queue_context
73      );
74      break;
75    case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
76      _CORE_recursive_mutex_Surrender_no_protocol_classic(
77        &the_semaphore->Core_control.Mutex.Recursive,
78        _Semaphore_Get_operations( the_semaphore ),
79        &queue_context
80      );
81      status = STATUS_SUCCESSFUL;
82      break;
83    case SEMAPHORE_VARIANT_SIMPLE_BINARY:
84      status = _CORE_semaphore_Surrender(
85        &the_semaphore->Core_control.semaphore,
86        _Semaphore_Get_operations( the_semaphore ),
87        1,
88        &queue_context
89      );
90      _Assert(
91        status == STATUS_SUCCESSFUL
92          || status == STATUS_MAXIMUM_COUNT_EXCEEDED
93      );
94      status = STATUS_SUCCESSFUL;
95      break;
96    default:
97      _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
98      status = _CORE_semaphore_Surrender(
99        &the_semaphore->Core_control.semaphore,
100        _Semaphore_Get_operations( the_semaphore ),
101        UINT32_MAX,
102        &queue_context
103      );
104      break;
105  }
106
107  return _Status_Get( status );
108}
Note: See TracBrowser for help on using the repository browser.