source: rtems/cpukit/rtems/src/semrelease.c

Last change on this file was b3b6d21e, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 22:28:59

cpukit/rtems/src/[s-z]*.c: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSImplClassicSemaphore
7 *
8 * @brief This source file contains the implementation of
9 *   rtems_semaphore_release().
10 */
11
12/*
13 *  COPYRIGHT (c) 1989-2014.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 *    notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 *    notice, this list of conditions and the following disclaimer in the
23 *    documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifdef HAVE_CONFIG_H
39#include "config.h"
40#endif
41
42#include <rtems/rtems/semimpl.h>
43#include <rtems/rtems/statusimpl.h>
44
45rtems_status_code rtems_semaphore_release( rtems_id id )
46{
47  Semaphore_Control    *the_semaphore;
48  Thread_queue_Context  queue_context;
49  Thread_Control       *executing;
50  uintptr_t             flags;
51  Semaphore_Variant     variant;
52  Status_Control        status;
53
54  the_semaphore = _Semaphore_Get( id, &queue_context );
55
56  if ( the_semaphore == NULL ) {
57#if defined(RTEMS_MULTIPROCESSING)
58    return _Semaphore_MP_Release( id );
59#else
60    return RTEMS_INVALID_ID;
61#endif
62  }
63
64  executing = _Thread_Executing;
65
66  _Thread_queue_Context_set_MP_callout(
67    &queue_context,
68    _Semaphore_Core_mutex_mp_support
69  );
70  flags = _Semaphore_Get_flags( the_semaphore );
71  variant = _Semaphore_Get_variant( flags );
72
73  switch ( variant ) {
74    case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
75      status = _CORE_recursive_mutex_Surrender(
76        &the_semaphore->Core_control.Mutex.Recursive,
77        CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
78        executing,
79        &queue_context
80      );
81      break;
82    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
83      status = _CORE_ceiling_mutex_Surrender(
84        &the_semaphore->Core_control.Mutex,
85        executing,
86        &queue_context
87      );
88      break;
89    case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
90      status = _CORE_recursive_mutex_Surrender(
91        &the_semaphore->Core_control.Mutex.Recursive,
92        _Semaphore_Get_operations( flags ),
93        executing,
94        &queue_context
95      );
96      break;
97    case SEMAPHORE_VARIANT_SIMPLE_BINARY:
98      status = _CORE_semaphore_Surrender(
99        &the_semaphore->Core_control.Semaphore,
100        _Semaphore_Get_operations( flags ),
101        1,
102        &queue_context
103      );
104      _Assert(
105        status == STATUS_SUCCESSFUL
106          || status == STATUS_MAXIMUM_COUNT_EXCEEDED
107      );
108      (void) status;
109      status = STATUS_SUCCESSFUL;
110      break;
111#if defined(RTEMS_SMP)
112    case SEMAPHORE_VARIANT_MRSP:
113      status = _MRSP_Surrender(
114        &the_semaphore->Core_control.MRSP,
115        executing,
116        &queue_context
117      );
118      break;
119#endif
120    default:
121      _Assert( variant == SEMAPHORE_VARIANT_COUNTING );
122      status = _CORE_semaphore_Surrender(
123        &the_semaphore->Core_control.Semaphore,
124        _Semaphore_Get_operations( flags ),
125        UINT32_MAX,
126        &queue_context
127      );
128      break;
129  }
130
131  return _Status_Get( status );
132}
Note: See TracBrowser for help on using the repository browser.