source: rtems/cpukit/score/include/rtems/score/coremsg.h @ d8cd045c

4.115
Last change on this file since d8cd045c was d8cd045c, checked in by Joel Sherrill <joel.sherrill@…>, on 06/17/11 at 15:40:09

2011-06-17 Joel Sherrill <joel.sherrill@…>

  • rtems/include/rtems/rtems/types.h, score/include/rtems/score/address.h, score/include/rtems/score/apiext.h, score/include/rtems/score/bitfield.h, score/include/rtems/score/context.h, score/include/rtems/score/corebarrier.h, score/include/rtems/score/coremsg.h, score/include/rtems/score/coremutex.h, score/include/rtems/score/corerwlock.h, score/include/rtems/score/coresem.h, score/include/rtems/score/corespinlock.h, score/include/rtems/score/interr.h, score/include/rtems/score/isr.h, score/include/rtems/score/mpci.h, score/include/rtems/score/mppkt.h, score/include/rtems/score/objectmp.h, score/include/rtems/score/percpu.h, score/include/rtems/score/priority.h, score/include/rtems/score/rbtree.h, score/include/rtems/score/scheduler.h, score/include/rtems/score/smp.h, score/include/rtems/score/smplock.h, score/include/rtems/score/stack.h, score/include/rtems/score/states.h, score/include/rtems/score/thread.h, score/include/rtems/score/threadq.h, score/include/rtems/score/threadsync.h, score/include/rtems/score/timespec.h, score/include/rtems/score/timestamp.h, score/include/rtems/score/timestamp64.h, score/include/rtems/score/tod.h, score/include/rtems/score/tqdata.h, score/include/rtems/score/watchdog.h, score/include/rtems/score/wkspace.h: Mark Score files as in Score Group to improve Doxygen output.
  • Property mode set to 100644
File size: 16.0 KB
Line 
1/**
2 *  @file  rtems/score/coremsg.h
3 *
4 *  This include file contains all the constants and structures associated
5 *  with the Message queue Handler.
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2009.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#ifndef _RTEMS_SCORE_COREMSG_H
20#define _RTEMS_SCORE_COREMSG_H
21
22/**
23 *  @defgroup ScoreMessageQueue Message Queue Handler
24 *
25 *  @ingroup Score
26 *
27 *  This handler encapsulates functionality which provides the foundation
28 *  Message Queue services used in all of the APIs supported by RTEMS.
29 */
30/**@{*/
31
32#include <limits.h>
33#include <rtems/score/thread.h>
34#include <rtems/score/threadq.h>
35#include <rtems/score/priority.h>
36#include <rtems/score/watchdog.h>
37
38#if defined(RTEMS_POSIX_API)
39  #define RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY
40#endif
41
42#if defined(RTEMS_POSIX_API)
43  #define RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION
44#endif
45
46#if defined(RTEMS_POSIX_API)
47  #define RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND
48#endif
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54/**
55 *  @brief  Message Queue MP Callback Prototype
56 *
57 *  The following type defines the callout which the API provides
58 *  to support global/multiprocessor operations on message_queues.
59 */
60typedef void ( *CORE_message_queue_API_mp_support_callout )(
61                 Thread_Control *,
62                 Objects_Id
63             );
64
65/**
66 *  @brief Message Buffer Contents Management Structure
67 *
68 *  The following defines the data types needed to manipulate
69 *  the contents of message buffers.
70 *
71 *  @note  The buffer field is normally longer than a single uint32_t
72 *         but since messages are variable length we just make a ptr to 1.
73 */
74typedef struct {
75  /** This field is the size of this message. */
76  size_t      size;
77  /** This field contains the actual message. */
78  uint32_t    buffer[1];
79} CORE_message_queue_Buffer;
80
81/**
82 *  @brief Message Structure
83 *
84 *  The following records define the organization of a message
85 *  buffer.
86 */
87typedef struct {
88  /** This element allows this structure to be placed on chains. */
89  Chain_Node                 Node;
90  #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
91    /** This field is the priority of this message. */
92    int                        priority;
93  #endif
94  /** This field points to the contents of the message. */
95  CORE_message_queue_Buffer  Contents;
96}   CORE_message_queue_Buffer_control;
97
98/**
99 *  @brief Message Queue Blocking Disciplines
100 *
101 *  This enumerated types defines the possible blocking disciplines
102 *  for a message queue.
103 */
104typedef enum {
105  /** This value indicates that blocking tasks are in FIFO order. */
106  CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO,
107  /** This value indicates that blocking tasks are in priority order. */
108  CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY
109}   CORE_message_queue_Disciplines;
110
111/**
112 *  @brief Message Priority for Appending
113 *
114 *  This is the priority constant used when appending messages onto
115 *  a message queue.
116 */
117#define  CORE_MESSAGE_QUEUE_SEND_REQUEST   INT_MAX
118
119/**
120 *  @brief Message Priority for Prepending
121 *
122 *  This is the priority constant used when prepending messages onto
123 *  a message queue.
124 */
125#define  CORE_MESSAGE_QUEUE_URGENT_REQUEST INT_MIN
126
127/**
128 *  @brief Message Insertion Operation Types
129 *
130 *  The following type details the modes in which a message
131 *  may be submitted to a message queue.  The message may be posted
132 *  in a send or urgent fashion.
133 *
134 *  @note  All other values are message priorities.  Numerically smaller
135 *         priorities indicate higher priority messages.
136 */
137typedef int CORE_message_queue_Submit_types;
138
139/**
140 *  @brief Core Message Queue Return Statuses
141 *
142 *  This enumerated type defines the possible set of Core Message
143 *  Queue handler return statuses.
144 */
145typedef enum {
146  /** This value indicates the operation completed sucessfully. */
147  CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL,
148  /** This value indicates that the message was too large for this queue. */
149  CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE,
150  /** This value indicates that there are too many messages pending. */
151  CORE_MESSAGE_QUEUE_STATUS_TOO_MANY,
152  /** This value indicates that a receive was unsuccessful. */
153  CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED,
154  /** This value indicates that a blocking send was unsuccessful. */
155  CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT,
156  /** This value indicates that the message queue being blocked upon
157   *  was deleted while the thread was waiting.
158   */
159  CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED,
160  /** This value indicates that the thread had to timeout while waiting
161   *  to receive a message because one did not become available.
162   */
163  CORE_MESSAGE_QUEUE_STATUS_TIMEOUT,
164  /** This value indicates that a blocking receive was unsuccessful. */
165  CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT
166}   CORE_message_queue_Status;
167
168/**
169 *  @brief Core Message Queue Last Status
170 *
171 *  This is the last status value.
172 */
173#define CORE_MESSAGE_QUEUE_STATUS_LAST CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT
174
175/**
176 *  @brief Message Queue Attributes Type
177 *
178 *  The following defines the control block used to manage the
179 *  attributes of each message queue.
180 */
181typedef struct {
182  /** This field specifies the order in which blocking tasks will be ordered. */
183  CORE_message_queue_Disciplines  discipline;
184}   CORE_message_queue_Attributes;
185
186#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
187  /**
188   *  @brief Message Queue Notification Callback Prototype
189   *
190   *  The following defines the type for a Notification handler.  A
191   *  notification handler is invoked when the message queue makes a
192   *  0->1 transition on pending messages.
193   */
194  typedef void (*CORE_message_queue_Notify_Handler)( void * );
195#endif
196
197/**
198 *  @brief Core Message Queue Control Structure
199 *
200 *  The following defines the control block used to manage each
201 *  Message Queue
202 */
203typedef struct {
204  /** This field is the Waiting Queue used to manage the set of tasks
205   *  which are blocked waiting to receive a message from this queue.
206   */
207  Thread_queue_Control               Wait_queue;
208  /** This element is the set of attributes which define this instance's
209   *  behavior.
210   */
211  CORE_message_queue_Attributes      Attributes;
212  /** This element is maximum number of messages which may be pending
213   *  at any given time.
214   */
215  uint32_t                           maximum_pending_messages;
216  /** This element is the number of messages which are currently pending.
217   */
218  uint32_t                           number_of_pending_messages;
219  /** This is the size in bytes of the largest message which may be
220   *  sent via this queue.
221   */
222  size_t                             maximum_message_size;
223  /** This chain is the set of pending messages.  It may be ordered by
224   *  message priority or in FIFO order.
225   */
226  Chain_Control                      Pending_messages;
227  /** This is the address of the memory allocated for message buffers.
228   *  It is allocated are part of message queue initialization and freed
229   *  as part of destroying it.
230   */
231  CORE_message_queue_Buffer         *message_buffers;
232  #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
233    /** This is the routine invoked when the message queue transitions
234     *  from zero (0) messages pending to one (1) message pending.
235     */
236    CORE_message_queue_Notify_Handler  notify_handler;
237    /** This field is the argument passed to the @ref notify_argument. */
238    void                              *notify_argument;
239  #endif
240  /** This chain is the set of inactive messages.  A message is inactive
241   *  when it does not contain a pending message.
242   */
243  Chain_Control                      Inactive_messages;
244}   CORE_message_queue_Control;
245
246/**
247 *  @brief Initialize a Message Queue
248 *
249 *  This routine initializes @a the_message_queue based on the parameters passed.
250 *
251 *  @param[in] the_message_queue points to the message queue to initialize
252 *  @param[in] the_message_queue_attributes points to the attributes that
253 *         will be used with this message queue instance
254 *  @param[in] maximum_pending_messages is the maximum number of messages
255 *         that will be allowed to pend at any given time
256 *  @param[in] maximum_message_size is the size of largest message that
257 *         may be sent to this message queue instance
258 *
259 *  @return true if the message queue can be initialized.  In general,
260 *         false will only be returned if memory for the pending
261 *         messages cannot be allocated.
262 */
263bool _CORE_message_queue_Initialize(
264  CORE_message_queue_Control    *the_message_queue,
265  CORE_message_queue_Attributes *the_message_queue_attributes,
266  uint32_t                       maximum_pending_messages,
267  size_t                         maximum_message_size
268);
269
270/**
271 *  @brief Close a Message Queue
272 *
273 *  This function closes a message by returning all allocated space and
274 *  flushing @a the_message_queue's task wait queue.
275 *
276 *  @param[in] the_message_queue points to the message queue to close
277 *  @param[in] remote_extract_callout is the routine to call for each thread
278 *         that is extracted from the set of waiting threads
279 *  @param[in] status is the status that each waiting thread will return
280 *         from it's blocking service
281 */
282void _CORE_message_queue_Close(
283  CORE_message_queue_Control *the_message_queue,
284  Thread_queue_Flush_callout  remote_extract_callout,
285  uint32_t                    status
286);
287
288/**
289 *  @brief Flush Pending Messages
290 *
291 *  This function flushes @a the_message_queue's pending message queue.  The
292 *  number of messages flushed from the queue is returned.
293 *
294 *  @param[in] the_message_queue points to the message queue to flush
295 *
296 *  @return This method returns the number of message pending messages flushed.
297 */
298uint32_t   _CORE_message_queue_Flush(
299  CORE_message_queue_Control *the_message_queue
300);
301
302/**
303 *  @brief Flush Messages Support Routine
304 *
305 *  This routine flushes all outstanding messages and returns
306 *  them to the inactive message chain.
307 *
308 *  @param[in] the_message_queue points to the message queue to flush
309 *
310 *  @return This method returns the number of message pending messages flushed.
311 */
312uint32_t   _CORE_message_queue_Flush_support(
313  CORE_message_queue_Control *the_message_queue
314);
315
316#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
317  /**
318   *  @brief Flush Waiting Threads.
319   *
320   *  This function flushes the threads which are blocked on
321   *  @a the_message_queue's pending message queue.  They are
322   *  unblocked whether blocked sending or receiving.
323   *
324   *  @param[in] the_message_queue points to the message queue to flush
325   */
326  void _CORE_message_queue_Flush_waiting_threads(
327    CORE_message_queue_Control *the_message_queue
328  );
329#endif
330
331/**
332 *  @brief Broadcast a Message to the Message Queue
333 *
334 *  This function sends a message for every thread waiting on the queue and
335 *  returns the number of threads made ready by the message.
336 *
337 *  @param[in] the_message_queue points to the message queue
338 *  @param[in] buffer is the starting address of the message to broadcast
339 *  @param[in] size is the size of the message being broadcast
340 *  @param[in] id is the RTEMS object Id associated with this message queue.
341 *         It is used when unblocking a remote thread.
342 *  @param[in] api_message_queue_mp_support is the routine to invoke if
343 *         a thread that is unblocked is actually a remote thread.
344 *  @param[out] count points to the variable that will contain the
345 *         number of tasks that are sent this message
346 *  @return @a *count will contain the number of messages sent
347 *  @return indication of the successful completion or reason for failure
348 */
349CORE_message_queue_Status _CORE_message_queue_Broadcast(
350  CORE_message_queue_Control                *the_message_queue,
351  const void                                *buffer,
352  size_t                                     size,
353  Objects_Id                                 id,
354  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
355  uint32_t                                  *count
356);
357
358/**
359 *  @brief Submit a Message to the Message Queue
360 *
361 *  This routine implements the send and urgent message functions. It
362 *  processes a message that is to be submitted to the designated
363 *  message queue.  The message will either be processed as a
364 *  send message which it will be inserted at the rear of the queue
365 *  or it will be processed as an urgent message which will be inserted
366 *  at the front of the queue.
367 *
368 *  @param[in] the_message_queue points to the message queue
369 *  @param[in] buffer is the starting address of the message to send
370 *  @param[in] size is the size of the message being send
371 *  @param[in] id is the RTEMS object Id associated with this message queue.
372 *         It is used when unblocking a remote thread.
373 *  @param[in] api_message_queue_mp_support is the routine to invoke if
374 *         a thread that is unblocked is actually a remote thread.
375 *  @param[in] submit_type determines whether the message is prepended,
376 *         appended, or enqueued in priority order.
377 *  @param[in] wait indicates whether the calling thread is willing to block
378 *         if the message queue is full.
379 *  @param[in] timeout is the maximum number of clock ticks that the calling
380 *         thread is willing to block if the message queue is full.
381 *  @return indication of the successful completion or reason for failure
382 */
383CORE_message_queue_Status _CORE_message_queue_Submit(
384  CORE_message_queue_Control                *the_message_queue,
385  const void                                *buffer,
386  size_t                                     size,
387  Objects_Id                                 id,
388  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
389  CORE_message_queue_Submit_types            submit_type,
390  bool                                       wait,
391  Watchdog_Interval                          timeout
392);
393
394/**
395 *  @brief Size a Message from the Message Queue
396 *
397 *  This kernel routine dequeues a message, copies the message buffer to
398 *  a given destination buffer, and frees the message buffer to the
399 *  inactive message pool.  The thread will be blocked if wait is true,
400 *  otherwise an error will be given to the thread if no messages are available.
401 *
402 *  @param[in] the_message_queue points to the message queue
403 *  @param[in] id is the RTEMS object Id associated with this message queue.
404 *         It is used when unblocking a remote thread.
405 *  @param[in] buffer is the starting address of the message buffer to
406 *         to be filled in with a message
407 *  @param[in] size is the size of the @a buffer and indicates the maximum
408 *         size message that the caller can receive.
409 *  @param[in] wait indicates whether the calling thread is willing to block
410 *         if the message queue is empty.
411 *  @param[in] timeout is the maximum number of clock ticks that the calling
412 *         thread is willing to block if the message queue is empty.
413 *
414 *  @return indication of the successful completion or reason for failure
415 *  @note Returns message priority via return are in TCB.
416 */
417void _CORE_message_queue_Seize(
418  CORE_message_queue_Control      *the_message_queue,
419  Objects_Id                       id,
420  void                            *buffer,
421  size_t                          *size_p,
422  bool                             wait,
423  Watchdog_Interval                timeout
424);
425
426/**
427 *  This kernel routine inserts the specified message into the
428 *  message queue.  It is assumed that the message has been filled
429 *  in before this routine is called.
430 *
431 *  @param[in] the_message_queue points to the message queue
432 *  @param[in] the_message is the message to enqueue
433 *  @param[in] submit_type determines whether the message is prepended,
434 *         appended, or enqueued in priority order.
435 */
436void _CORE_message_queue_Insert_message(
437  CORE_message_queue_Control        *the_message_queue,
438  CORE_message_queue_Buffer_control *the_message,
439  CORE_message_queue_Submit_types    submit_type
440);
441
442#ifndef __RTEMS_APPLICATION__
443#include <rtems/score/coremsg.inl>
444#endif
445
446#ifdef __cplusplus
447}
448#endif
449
450/**@}*/
451
452#endif
453/*  end of include file */
Note: See TracBrowser for help on using the repository browser.