source: rtems/cpukit/include/rtems/posix/mqueueimpl.h @ a660e9dc

Last change on this file since a660e9dc 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.9 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @brief Private Inlined Routines for POSIX Message Queue
7 *
8 * This include file contains the static inline implementation of the private
9 * inlined routines for POSIX Message Queue.
10 */
11
12/*
13 *  COPYRIGHT (c) 1989-2013.
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#ifndef _RTEMS_POSIX_MQUEUE_INL
39#define _RTEMS_POSIX_MQUEUE_INL
40
41#include <rtems/posix/mqueue.h>
42#include <rtems/posix/posixapi.h>
43#include <rtems/score/coremsgimpl.h>
44#include <rtems/score/threadqimpl.h>
45
46#include <rtems/seterr.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 * @brief Delete a POSIX Message Queue
54 *
55 * This routine supports the mq_unlink and mq_close routines by
56 * doing most of the work involved with removing a message queue.
57 */
58void _POSIX_Message_queue_Delete(
59  POSIX_Message_queue_Control *the_mq,
60  Thread_queue_Context        *queue_context
61);
62
63/*@
64 *  @brief POSIX Message Queue Receive Support
65 *
66 *  This routine supports the various flavors of receiving a message.
67 *
68 *  @note The structure of the routines is identical to that of POSIX
69 *        Message_queues to leave the option of having unnamed message
70 *        queues at a future date.  They are currently not part of the
71 *        POSIX standard but unnamed message_queues are.  This is also
72 *        the reason for the apparently unnecessary tracking of
73 *        the process_shared attribute.  [In addition to the fact that
74 *        it would be trivial to add pshared to the mq_attr structure
75 *        and have process private message queues.]
76 *
77 * @note This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open time.
78 */
79ssize_t _POSIX_Message_queue_Receive_support(
80  mqd_t                         mqdes,
81  char                         *msg_ptr,
82  size_t                        msg_len,
83  unsigned int                 *msg_prio,
84  const struct timespec        *abstime,
85  Thread_queue_Enqueue_callout  enqueue_callout
86);
87
88/**
89 *  @brief POSIX Message Queue Send Support
90 *
91 *  This routine posts a message to a specified message queue.
92 */
93int _POSIX_Message_queue_Send_support(
94  mqd_t                         mqdes,
95  const char                   *msg_ptr,
96  size_t                        msg_len,
97  unsigned int                  msg_prio,
98  const struct timespec        *abstime,
99  Thread_queue_Enqueue_callout  enqueue_callout
100);
101
102static inline POSIX_Message_queue_Control *
103  _POSIX_Message_queue_Allocate_unprotected( void )
104{
105  return (POSIX_Message_queue_Control *)
106    _Objects_Allocate_unprotected( &_POSIX_Message_queue_Information );
107}
108
109/**
110 *  @brief POSIX Message Queue Free
111 *
112 *  This routine frees a message queue control block to the
113 *  inactive chain of free message queue control blocks.
114 */
115static inline void _POSIX_Message_queue_Free(
116  POSIX_Message_queue_Control *the_mq
117)
118{
119  _Objects_Free( &_POSIX_Message_queue_Information, &the_mq->Object );
120}
121
122
123static inline POSIX_Message_queue_Control *_POSIX_Message_queue_Get(
124  Objects_Id            id,
125  Thread_queue_Context *queue_context
126)
127{
128  _Thread_queue_Context_initialize( queue_context );
129  return (POSIX_Message_queue_Control *) _Objects_Get(
130    id,
131    &queue_context->Lock_context.Lock_context,
132    &_POSIX_Message_queue_Information
133  );
134}
135
136/*
137 *  @brief POSIX Message Queue Convert Message Priority to Score
138 *
139 *  This method converts a POSIX message priority to the priorities used
140 *  by the Score.
141 */
142static inline CORE_message_queue_Submit_types
143  _POSIX_Message_queue_Priority_to_core(
144  unsigned int priority
145)
146{
147  return (CORE_message_queue_Submit_types) priority * -1;
148}
149
150
151/*
152 *  @brief POSIX Message Queue Convert Message Priority from Score
153 *
154 *  This method converts a POSIX message priority from the priorities used
155 *  by the Score.
156 */
157static inline unsigned int _POSIX_Message_queue_Priority_from_core(
158  CORE_message_queue_Submit_types priority
159)
160{
161  /* absolute value without a library dependency */
162  return (unsigned int) ((priority >= 0) ? priority : -priority);
163}
164
165/**
166 *  @brief POSIX Message Queue Remove from Namespace
167 */
168static inline void _POSIX_Message_queue_Namespace_remove (
169  POSIX_Message_queue_Control *the_mq
170)
171{
172  _Objects_Namespace_remove_string(
173    &_POSIX_Message_queue_Information,
174    &the_mq->Object
175  );
176}
177
178static inline POSIX_Message_queue_Control *
179_POSIX_Message_queue_Get_by_name(
180  const char                *name,
181  size_t                    *name_length_p,
182  Objects_Get_by_name_error *error
183)
184{
185  return (POSIX_Message_queue_Control *) _Objects_Get_by_name(
186    &_POSIX_Message_queue_Information,
187    name,
188    name_length_p,
189    error
190  );
191}
192
193#ifdef __cplusplus
194}
195#endif
196
197#endif
198/*  end of include file */
Note: See TracBrowser for help on using the repository browser.