source: rtems/cpukit/include/rtems/rtems/semimpl.h

Last change on this file was a660e9dc, checked in by Sebastian Huber <sebastian.huber@…>, on 09/08/22 at 08:37:05

Do not use RTEMS_INLINE_ROUTINE

Directly use "static inline" which is available in C99 and later. This brings
the RTEMS implementation closer to standard C.

Close #3935.

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSImplClassicSemaphore
7 *
8 * @brief This header file provides the implementation interfaces of
9 *   the @ref RTEMSImplClassicSemaphore.
10 */
11
12/*  COPYRIGHT (c) 1989-2008.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_RTEMS_SEMIMPL_H
38#define _RTEMS_RTEMS_SEMIMPL_H
39
40#include <rtems/rtems/semdata.h>
41#include <rtems/score/coremuteximpl.h>
42#include <rtems/score/coresemimpl.h>
43#include <rtems/score/mrspimpl.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * @defgroup RTEMSImplClassicSemaphore Semaphore Manager
51 *
52 * @ingroup RTEMSImplClassic
53 *
54 * @brief This group contains the Semaphore Manager implementation.
55 *
56 * @{
57 */
58
59/**
60 * @brief Classic semaphore variants.
61 *
62 * Must be in synchronization with Semaphore_Control::variant.
63 */
64typedef enum {
65  SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY,
66  SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING,
67  SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL,
68  SEMAPHORE_VARIANT_SIMPLE_BINARY,
69  SEMAPHORE_VARIANT_COUNTING
70#if defined(RTEMS_SMP)
71  ,
72  SEMAPHORE_VARIANT_MRSP
73#endif
74} Semaphore_Variant;
75
76typedef enum {
77  SEMAPHORE_DISCIPLINE_PRIORITY,
78  SEMAPHORE_DISCIPLINE_FIFO
79} Semaphore_Discipline;
80
81static inline uintptr_t _Semaphore_Get_flags(
82  const Semaphore_Control *the_semaphore
83)
84{
85  _Assert( _Chain_Is_node_off_chain( &the_semaphore->Object.Node ) );
86  return (uintptr_t) the_semaphore->Object.Node.previous;
87}
88
89static inline void _Semaphore_Set_flags(
90  Semaphore_Control *the_semaphore,
91  uintptr_t          flags
92)
93{
94  _Assert( _Chain_Is_node_off_chain( &the_semaphore->Object.Node ) );
95  the_semaphore->Object.Node.previous = (Chain_Node *) flags;
96}
97
98static inline Semaphore_Variant _Semaphore_Get_variant(
99  uintptr_t flags
100)
101{
102  return (Semaphore_Variant) ( flags & 0x7 );
103}
104
105static inline uintptr_t _Semaphore_Set_variant(
106  uintptr_t         flags,
107  Semaphore_Variant variant
108)
109{
110  return flags | variant;
111}
112
113static inline Semaphore_Discipline _Semaphore_Get_discipline(
114  uintptr_t flags
115)
116{
117  return (Semaphore_Discipline) ( ( flags >> 3 ) & 0x1 );
118}
119
120static inline uintptr_t _Semaphore_Set_discipline(
121  uintptr_t            flags,
122  Semaphore_Discipline discipline
123)
124{
125  return flags | ( discipline << 3 );
126}
127
128#if defined(RTEMS_MULTIPROCESSING)
129static inline bool _Semaphore_Is_global(
130  uintptr_t flags
131)
132{
133  return ( flags & 0x10 ) != 0;
134}
135
136static inline uintptr_t _Semaphore_Make_global( uintptr_t flags )
137{
138  return flags | 0x10;
139}
140#endif
141
142static inline const Thread_queue_Operations *_Semaphore_Get_operations(
143  uintptr_t flags
144)
145{
146  if (
147    _Semaphore_Get_variant( flags ) == SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY
148  ) {
149    return &_Thread_queue_Operations_priority_inherit;
150  }
151
152  if ( _Semaphore_Get_discipline( flags ) == SEMAPHORE_DISCIPLINE_PRIORITY ) {
153    return &_Thread_queue_Operations_priority;
154  }
155
156  return &_Thread_queue_Operations_FIFO;
157}
158
159/**
160 *  @brief Allocates a semaphore control block from
161 *  the inactive chain of free semaphore control blocks.
162 *
163 *  This function allocates a semaphore control block from
164 *  the inactive chain of free semaphore control blocks.
165 */
166static inline Semaphore_Control *_Semaphore_Allocate( void )
167{
168  return (Semaphore_Control *) _Objects_Allocate( &_Semaphore_Information );
169}
170
171/**
172 *  @brief Frees a semaphore control block to the
173 *  inactive chain of free semaphore control blocks.
174 *
175 *  This routine frees a semaphore control block to the
176 *  inactive chain of free semaphore control blocks.
177 */
178static inline void _Semaphore_Free (
179  Semaphore_Control *the_semaphore
180)
181{
182  _Objects_Free( &_Semaphore_Information, &the_semaphore->Object );
183}
184
185static inline Semaphore_Control *_Semaphore_Get(
186  Objects_Id            id,
187  Thread_queue_Context *queue_context
188)
189{
190  _Thread_queue_Context_initialize( queue_context );
191  return (Semaphore_Control *) _Objects_Get(
192    id,
193    &queue_context->Lock_context.Lock_context,
194    &_Semaphore_Information
195  );
196}
197
198/** @} */
199
200#ifdef __cplusplus
201}
202#endif
203
204#ifdef RTEMS_MULTIPROCESSING
205#include <rtems/rtems/semmp.h>
206#endif
207
208#endif
209/*  end of include file */
Note: See TracBrowser for help on using the repository browser.