source: rtems/cpukit/score/include/rtems/score/coremsgimpl.h @ 4cd55724

4.115
Last change on this file since 4cd55724 was 4cd55724, checked in by Sebastian Huber <sebastian.huber@…>, on 07/26/14 at 10:52:22

Delete unused *_Is_null() functions

  • Property mode set to 100644
File size: 19.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief Inlined Routines in the Core Message Handler
5 *
6 * This include file contains the static inline implementation of all
7 * inlined routines in the Core Message Handler.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2009.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_COREMSGIMPL_H
20#define _RTEMS_SCORE_COREMSGIMPL_H
21
22#include <rtems/score/coremsg.h>
23#include <rtems/score/chainimpl.h>
24#include <rtems/score/threadqimpl.h>
25
26#include <limits.h>
27#include <string.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/**
34 * @addtogroup ScoreMessageQueue
35 */
36/**@{**/
37
38/**
39 *  @brief Used when appending messages onto a message queue.
40 *
41 *  This is the priority constant used when appending messages onto
42 *  a message queue.
43 */
44#define  CORE_MESSAGE_QUEUE_SEND_REQUEST   INT_MAX
45
46/**
47 *  @brief Used when prepending messages onto a message queue.
48 *
49 *  This is the priority constant used when prepending messages onto
50 *  a message queue.
51 */
52#define  CORE_MESSAGE_QUEUE_URGENT_REQUEST INT_MIN
53
54/**
55 *  @brief The modes in which a message may be submitted to a message queue.
56 *
57 *  The following type details the modes in which a message
58 *  may be submitted to a message queue.  The message may be posted
59 *  in a send or urgent fashion.
60 *
61 *  @note  All other values are message priorities.  Numerically smaller
62 *         priorities indicate higher priority messages.
63 */
64typedef int CORE_message_queue_Submit_types;
65
66/**
67 *  @brief The possible set of Core Message Queue handler return statuses.
68 *
69 *  This enumerated type defines the possible set of Core Message
70 *  Queue handler return statuses.
71 */
72typedef enum {
73  /** This value indicates the operation completed sucessfully. */
74  CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL,
75  /** This value indicates that the message was too large for this queue. */
76  CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE,
77  /** This value indicates that there are too many messages pending. */
78  CORE_MESSAGE_QUEUE_STATUS_TOO_MANY,
79  /** This value indicates that a receive was unsuccessful. */
80  CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED,
81  /** This value indicates that a blocking send was unsuccessful. */
82  CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT,
83  /** This value indicates that the message queue being blocked upon
84   *  was deleted while the thread was waiting.
85   */
86  CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED,
87  /** This value indicates that the thread had to timeout while waiting
88   *  to receive a message because one did not become available.
89   */
90  CORE_MESSAGE_QUEUE_STATUS_TIMEOUT,
91  /** This value indicates that a blocking receive was unsuccessful. */
92  CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT
93}   CORE_message_queue_Status;
94
95/**
96 *  @brief Core message queue last status value.
97 *
98 *  This is the last status value.
99 */
100#define CORE_MESSAGE_QUEUE_STATUS_LAST CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT
101
102/**
103 *  @brief Callout provides to support global/multiprocessor operations.
104 *
105 *  The following type defines the callout which the API provides
106 *  to support global/multiprocessor operations on message_queues.
107 */
108typedef void ( *CORE_message_queue_API_mp_support_callout )(
109                 Thread_Control *,
110                 Objects_Id
111             );
112
113/**
114 *  @brief Initialize a message queue.
115 *
116 *  DESCRIPTION:
117 *
118 *  This package is the implementation of the CORE Message Queue Handler.
119 *  This core object provides task synchronization and communication functions
120 *  via messages passed to queue objects.
121 *
122 *  This routine initializes @a the_message_queue
123 *      based on the parameters passed.
124 *
125 *  @param[in] the_message_queue points to the message queue to initialize
126 *  @param[in] the_message_queue_attributes points to the attributes that
127 *         will be used with this message queue instance
128 *  @param[in] maximum_pending_messages is the maximum number of messages
129 *         that will be allowed to pend at any given time
130 *  @param[in] maximum_message_size is the size of largest message that
131 *         may be sent to this message queue instance
132 *
133 *  @retval true if the message queue can be initialized.  In general,
134 *         false will only be returned if memory for the pending
135 *         messages cannot be allocated.
136 */
137bool _CORE_message_queue_Initialize(
138  CORE_message_queue_Control    *the_message_queue,
139  CORE_message_queue_Attributes *the_message_queue_attributes,
140  uint32_t                       maximum_pending_messages,
141  size_t                         maximum_message_size
142);
143
144/**
145 *  @brief Close a message queue.
146 *
147 *  DESCRIPTION:
148 *  This package is the implementation of the CORE Message Queue Handler.
149 *  This core object provides task synchronization and communication functions
150 *  via messages passed to queue objects
151 *
152 *  This function closes a message by returning all allocated space and
153 *  flushing @a the_message_queue's task wait queue.
154 *
155 *  @param[in] the_message_queue points to the message queue to close
156 *  @param[in] remote_extract_callout is the routine to call for each thread
157 *         that is extracted from the set of waiting threads
158 *  @param[in] status is the status that each waiting thread will return
159 *         from it's blocking service
160 */
161void _CORE_message_queue_Close(
162  CORE_message_queue_Control *the_message_queue,
163  Thread_queue_Flush_callout  remote_extract_callout,
164  uint32_t                    status
165);
166
167/**
168 *  @brief Flush pending messages.
169 *
170 *  DESCRIPTION:
171 *  This package is the implementation of the CORE Message Queue Handler.
172 *  This core object provides task synchronization and communication functions
173 *  via messages passed to queue objects.
174 *
175 *  This function flushes @a the_message_queue's pending message queue.  The
176 *  number of messages flushed from the queue is returned.
177 *
178 *  @param[in] the_message_queue points to the message queue to flush
179 *
180 *  @retval This method returns the number of message pending messages flushed.
181 */
182uint32_t   _CORE_message_queue_Flush(
183  CORE_message_queue_Control *the_message_queue
184);
185
186/**
187 *  @brief Flush all outstanding messages.
188 *
189 *  This routine flushes all outstanding messages and returns
190 *  them to the inactive message chain.
191 *
192 *  @param[in] the_message_queue points to the message queue to flush
193 *
194 *  @retval This method returns the number of pending messages flushed.
195 *
196 *  - INTERRUPT LATENCY:
197 *    + single case
198 */
199uint32_t   _CORE_message_queue_Flush_support(
200  CORE_message_queue_Control *the_message_queue
201);
202
203#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
204/**
205 *  @brief Flush waiting threads.
206 *
207 *  This function flushes the threads which are blocked on
208 *  @a the_message_queue's pending message queue.  They are
209 *  unblocked whether blocked sending or receiving. It returns
210 *  the number of messages flushed from the queue.
211 *
212 *  @param[in] the_message_queue points to the message queue to flush
213 *  @retval number of messages flushed from the queue
214 */
215  void _CORE_message_queue_Flush_waiting_threads(
216    CORE_message_queue_Control *the_message_queue
217  );
218#endif
219
220/**
221 *  @brief Broadcast a message to the message queue.
222 *
223 *  DESCRIPTION:
224 *  This package is the implementation of the CORE Message Queue Handler.
225 *  This core object provides task synchronization and communication functions
226 *  via messages passed to queue objects.
227 *
228 *  This function sends a message for every thread waiting on the queue and
229 *  returns the number of threads made ready by the message.
230 *
231 *  @param[in] the_message_queue points to the message queue
232 *  @param[in] buffer is the starting address of the message to broadcast
233 *  @param[in] size is the size of the message being broadcast
234 *  @param[in] id is the RTEMS object Id associated with this message queue.
235 *         It is used when unblocking a remote thread.
236 *  @param[in] api_message_queue_mp_support is the routine to invoke if
237 *         a thread that is unblocked is actually a remote thread.
238 *  @param[out] count points to the variable that will contain the
239 *         number of tasks that are sent this message
240 *  @retval @a *count will contain the number of messages sent
241 *  @retval indication of the successful completion or reason for failure
242 */
243CORE_message_queue_Status _CORE_message_queue_Broadcast(
244  CORE_message_queue_Control                *the_message_queue,
245  const void                                *buffer,
246  size_t                                     size,
247  Objects_Id                                 id,
248  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
249  uint32_t                                  *count
250);
251
252/**
253 *  @brief Submit a message to the message queue.
254 *
255 *  This routine implements the send and urgent message functions. It
256 *  processes a message that is to be submitted to the designated
257 *  message queue.  The message will either be processed as a
258 *  send message which it will be inserted at the rear of the queue
259 *  or it will be processed as an urgent message which will be inserted
260 *  at the front of the queue.
261 *
262 *  @param[in] the_message_queue points to the message queue
263 *  @param[in] buffer is the starting address of the message to send
264 *  @param[in] size is the size of the message being send
265 *  @param[in] id is the RTEMS object Id associated with this message queue.
266 *         It is used when unblocking a remote thread.
267 *  @param[in] api_message_queue_mp_support is the routine to invoke if
268 *         a thread that is unblocked is actually a remote thread.
269 *  @param[in] submit_type determines whether the message is prepended,
270 *         appended, or enqueued in priority order.
271 *  @param[in] wait indicates whether the calling thread is willing to block
272 *         if the message queue is full.
273 *  @param[in] timeout is the maximum number of clock ticks that the calling
274 *         thread is willing to block if the message queue is full.
275 *  @retval indication of the successful completion or reason for failure
276 */
277CORE_message_queue_Status _CORE_message_queue_Submit(
278  CORE_message_queue_Control                *the_message_queue,
279  Thread_Control                            *executing,
280  const void                                *buffer,
281  size_t                                     size,
282  Objects_Id                                 id,
283  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
284  CORE_message_queue_Submit_types            submit_type,
285  bool                                       wait,
286  Watchdog_Interval                          timeout
287);
288
289/**
290 *  @brief Size a message from the message queue.
291 *
292 *  DESCRIPTION:
293 *  This package is the implementation of the CORE Message Queue Handler.
294 *  This core object provides task synchronization and communication functions
295 *  via messages passed to queue objects.
296 *
297 *  This kernel routine dequeues a message, copies the message buffer to
298 *  a given destination buffer, and frees the message buffer to the
299 *  inactive message pool.  The thread will be blocked if wait is true,
300 *  otherwise an error will be given to the thread if no messages are available.
301 *
302 *  @param[in] the_message_queue points to the message queue
303 *  @param[in] id is the RTEMS object Id associated with this message queue.
304 *         It is used when unblocking a remote thread.
305 *  @param[in] buffer is the starting address of the message buffer to
306 *         to be filled in with a message
307 *  @param[in] size_p is a pointer to the size of the @a buffer and
308 *         indicates the maximum size message that the caller can receive.
309 *  @param[in] wait indicates whether the calling thread is willing to block
310 *         if the message queue is empty.
311 *  @param[in] timeout is the maximum number of clock ticks that the calling
312 *         thread is willing to block if the message queue is empty.
313 *
314 *  @retval indication of the successful completion or reason for failure.
315 *          On success, the location pointed to @a size_p will contain the
316 *          size of the received message.
317 *
318 *  @note Returns message priority via return area in TCB.
319 *
320 *  - INTERRUPT LATENCY:
321 *    + available
322 *    + wait
323 */
324void _CORE_message_queue_Seize(
325  CORE_message_queue_Control      *the_message_queue,
326  Thread_Control                  *executing,
327  Objects_Id                       id,
328  void                            *buffer,
329  size_t                          *size_p,
330  bool                             wait,
331  Watchdog_Interval                timeout
332);
333
334/**
335 *  @brief Insert a message into the message queue.
336 *
337 *  This kernel routine inserts the specified message into the
338 *  message queue.  It is assumed that the message has been filled
339 *  in before this routine is called.
340 *
341 *  @param[in] the_message_queue points to the message queue
342 *  @param[in] the_message is the message to enqueue
343 *  @param[in] submit_type determines whether the message is prepended,
344 *         appended, or enqueued in priority order.
345 *
346 *  - INTERRUPT LATENCY:
347 *    + insert
348 */
349void _CORE_message_queue_Insert_message(
350  CORE_message_queue_Control        *the_message_queue,
351  CORE_message_queue_Buffer_control *the_message,
352  CORE_message_queue_Submit_types    submit_type
353);
354
355/**
356 * This routine sends a message to the end of the specified message queue.
357 */
358RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Send(
359  CORE_message_queue_Control                *the_message_queue,
360  const void                                *buffer,
361  size_t                                     size,
362  Objects_Id                                 id,
363  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
364  bool                                    wait,
365  Watchdog_Interval                          timeout
366)
367{
368  return _CORE_message_queue_Submit(
369    the_message_queue,
370    _Thread_Executing,
371    buffer,
372    size,
373    id,
374    api_message_queue_mp_support,
375    CORE_MESSAGE_QUEUE_SEND_REQUEST,
376    wait,     /* sender may block */
377    timeout   /* timeout interval */
378  );
379}
380
381/**
382 * This routine sends a message to the front of the specified message queue.
383 */
384RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Urgent(
385  CORE_message_queue_Control                *the_message_queue,
386  const void                                *buffer,
387  size_t                                     size,
388  Objects_Id                                 id,
389  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
390  bool                                    wait,
391  Watchdog_Interval                          timeout
392)
393{
394  return _CORE_message_queue_Submit(
395    the_message_queue,
396    _Thread_Executing,
397    buffer,
398    size,
399    id,
400    api_message_queue_mp_support,
401    CORE_MESSAGE_QUEUE_URGENT_REQUEST,
402    wait,     /* sender may block */
403    timeout   /* timeout interval */
404 );
405}
406
407/**
408 * This routine copies the contents of the source message buffer
409 * to the destination message buffer.
410 */
411RTEMS_INLINE_ROUTINE void _CORE_message_queue_Copy_buffer (
412  const void *source,
413  void       *destination,
414  size_t      size
415)
416{
417  memcpy(destination, source, size);
418}
419
420/**
421 * This function allocates a message buffer from the inactive
422 * message buffer chain.
423 */
424RTEMS_INLINE_ROUTINE CORE_message_queue_Buffer_control *
425_CORE_message_queue_Allocate_message_buffer (
426    CORE_message_queue_Control *the_message_queue
427)
428{
429   return (CORE_message_queue_Buffer_control *)
430     _Chain_Get( &the_message_queue->Inactive_messages );
431}
432
433/**
434 * This routine frees a message buffer to the inactive
435 * message buffer chain.
436 */
437RTEMS_INLINE_ROUTINE void _CORE_message_queue_Free_message_buffer (
438  CORE_message_queue_Control        *the_message_queue,
439  CORE_message_queue_Buffer_control *the_message
440)
441{
442  _Chain_Append( &the_message_queue->Inactive_messages, &the_message->Node );
443}
444
445/**
446 * This function returns the priority of @a the_message.
447 *
448 * @note It encapsulates the optional behavior that message priority is
449 *       disabled if no API requires it.
450 */
451RTEMS_INLINE_ROUTINE int _CORE_message_queue_Get_message_priority (
452  CORE_message_queue_Buffer_control *the_message
453)
454{
455  #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
456    return the_message->priority;
457  #else
458    return 0;
459  #endif
460}
461
462/**
463 * This function sets the priority of @a the_message.
464 *
465 * @note It encapsulates the optional behavior that message priority is
466 *       disabled if no API requires it.
467 */
468RTEMS_INLINE_ROUTINE void _CORE_message_queue_Set_message_priority (
469  CORE_message_queue_Buffer_control *the_message,
470  int                                priority
471)
472{
473  #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
474    the_message->priority = priority;
475  #endif
476}
477
478/**
479 * This function removes the first message from the_message_queue
480 * and returns a pointer to it.
481 */
482RTEMS_INLINE_ROUTINE
483  CORE_message_queue_Buffer_control *_CORE_message_queue_Get_pending_message (
484  CORE_message_queue_Control *the_message_queue
485)
486{
487  return (CORE_message_queue_Buffer_control *)
488    _Chain_Get_unprotected( &the_message_queue->Pending_messages );
489}
490
491/**
492 * This function returns true if the priority attribute is
493 * enabled in the attribute_set and false otherwise.
494 */
495RTEMS_INLINE_ROUTINE bool _CORE_message_queue_Is_priority(
496  CORE_message_queue_Attributes *the_attribute
497)
498{
499  return
500    (the_attribute->discipline == CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY);
501}
502
503/**
504 * This routine places the_message at the rear of the outstanding
505 * messages on the_message_queue.
506 */
507RTEMS_INLINE_ROUTINE void _CORE_message_queue_Append_unprotected (
508  CORE_message_queue_Control        *the_message_queue,
509  CORE_message_queue_Buffer_control *the_message
510)
511{
512  _Chain_Append_unprotected(
513    &the_message_queue->Pending_messages,
514    &the_message->Node
515  );
516}
517
518/**
519 * This routine places the_message at the front of the outstanding
520 * messages on the_message_queue.
521 */
522RTEMS_INLINE_ROUTINE void _CORE_message_queue_Prepend_unprotected (
523  CORE_message_queue_Control        *the_message_queue,
524  CORE_message_queue_Buffer_control *the_message
525)
526{
527  _Chain_Prepend_unprotected(
528    &the_message_queue->Pending_messages,
529    &the_message->Node
530  );
531}
532
533#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
534  /**
535   * This function returns true if notification is enabled on this message
536   * queue and false otherwise.
537   */
538  RTEMS_INLINE_ROUTINE bool _CORE_message_queue_Is_notify_enabled (
539    CORE_message_queue_Control *the_message_queue
540  )
541  {
542    return (the_message_queue->notify_handler != NULL);
543  }
544#endif
545
546/**
547 * This routine initializes the notification information for
548 * @a the_message_queue.
549 */
550#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
551  RTEMS_INLINE_ROUTINE void _CORE_message_queue_Set_notify (
552    CORE_message_queue_Control        *the_message_queue,
553    CORE_message_queue_Notify_Handler  the_handler,
554    void                              *the_argument
555  )
556  {
557    the_message_queue->notify_handler  = the_handler;
558    the_message_queue->notify_argument = the_argument;
559  }
560#else
561  /* turn it into nothing if not enabled */
562  #define _CORE_message_queue_Set_notify( \
563           the_message_queue, the_handler, the_argument )
564#endif
565
566/** @} */
567
568#ifdef __cplusplus
569}
570#endif
571
572#endif
573/* end of include file */
Note: See TracBrowser for help on using the repository browser.