[3652ad35] | 1 | /* coremsg.h |
---|
| 2 | * |
---|
| 3 | * This include file contains all the constants and structures associated |
---|
| 4 | * with the Message queue Handler. |
---|
| 5 | * |
---|
| 6 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 7 | * On-Line Applications Research Corporation (OAR). |
---|
| 8 | * All rights assigned to U.S. Government, 1994. |
---|
| 9 | * |
---|
| 10 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 11 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 12 | * notice must appear in all copies of this file and its derivatives. |
---|
| 13 | * |
---|
| 14 | * $Id$ |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #ifndef __RTEMS_CORE_MESSAGE_QUEUE_h |
---|
| 18 | #define __RTEMS_CORE_MESSAGE_QUEUE_h |
---|
| 19 | |
---|
| 20 | #ifdef __cplusplus |
---|
| 21 | extern "C" { |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | #include <rtems/core/thread.h> |
---|
| 25 | #include <rtems/core/threadq.h> |
---|
| 26 | #include <rtems/core/priority.h> |
---|
| 27 | #include <rtems/core/watchdog.h> |
---|
| 28 | |
---|
| 29 | /* |
---|
| 30 | * The following type defines the callout which the API provides |
---|
| 31 | * to support global/multiprocessor operations on message_queues. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | typedef void ( *CORE_message_queue_API_mp_support_callout )( |
---|
| 35 | Thread_Control *, |
---|
| 36 | Objects_Id |
---|
| 37 | ); |
---|
| 38 | |
---|
| 39 | /* |
---|
| 40 | * The following defines the data types needed to manipulate |
---|
| 41 | * the contents of message buffers. |
---|
| 42 | * Since msgs are variable length we just make a ptr to 1. |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | typedef struct { |
---|
| 46 | unsigned32 size; |
---|
| 47 | |
---|
| 48 | #ifndef __cplusplus |
---|
| 49 | /* NOTE: [0] is gcc specific, |
---|
| 50 | * but specifically disallowed by ANSI STD C++ |
---|
| 51 | * g++ warns about it, so we #ifdef it out to |
---|
| 52 | * get rid of warnings when compiled by g++. |
---|
| 53 | */ |
---|
| 54 | unsigned32 buffer[0]; |
---|
| 55 | #endif |
---|
| 56 | |
---|
| 57 | } CORE_message_queue_Buffer; |
---|
| 58 | |
---|
| 59 | /* |
---|
| 60 | * The following records define the organization of a message |
---|
| 61 | * buffer. |
---|
| 62 | */ |
---|
| 63 | |
---|
| 64 | typedef struct { |
---|
| 65 | Chain_Node Node; |
---|
| 66 | CORE_message_queue_Buffer Contents; |
---|
| 67 | } CORE_message_queue_Buffer_control; |
---|
| 68 | |
---|
| 69 | /* |
---|
| 70 | * Blocking disciplines for a message_queue. |
---|
| 71 | */ |
---|
| 72 | |
---|
| 73 | typedef enum { |
---|
| 74 | CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO, |
---|
| 75 | CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY |
---|
| 76 | } CORE_message_queue_Disciplines; |
---|
| 77 | |
---|
| 78 | /* |
---|
| 79 | * The following enumerated type details the modes in which a message |
---|
| 80 | * may be submitted to a message queue. The message may be posted |
---|
| 81 | * in a send or urgent fashion. |
---|
| 82 | */ |
---|
| 83 | |
---|
| 84 | typedef enum { |
---|
| 85 | CORE_MESSAGE_QUEUE_SEND_REQUEST = 0, |
---|
| 86 | CORE_MESSAGE_QUEUE_URGENT_REQUEST = 1 |
---|
| 87 | } CORE_message_queue_Submit_types; |
---|
| 88 | |
---|
| 89 | /* |
---|
| 90 | * Core Message queue handler return statuses. |
---|
| 91 | */ |
---|
| 92 | |
---|
| 93 | typedef enum { |
---|
| 94 | CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL, |
---|
| 95 | CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE, |
---|
| 96 | CORE_MESSAGE_QUEUE_STATUS_TOO_MANY, |
---|
| 97 | CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED, |
---|
| 98 | CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT, |
---|
| 99 | CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED, |
---|
| 100 | CORE_MESSAGE_QUEUE_STATUS_TIMEOUT |
---|
| 101 | } CORE_message_queue_Status; |
---|
| 102 | |
---|
| 103 | /* |
---|
| 104 | * The following defines the control block used to manage the |
---|
| 105 | * attributes of each message queue. |
---|
| 106 | */ |
---|
| 107 | |
---|
| 108 | typedef struct { |
---|
| 109 | CORE_message_queue_Disciplines discipline; |
---|
| 110 | } CORE_message_queue_Attributes; |
---|
| 111 | |
---|
| 112 | /* |
---|
| 113 | * The following defines the control block used to manage each |
---|
| 114 | * counting message_queue. |
---|
| 115 | */ |
---|
| 116 | |
---|
| 117 | typedef struct { |
---|
| 118 | Thread_queue_Control Wait_queue; |
---|
| 119 | CORE_message_queue_Attributes Attributes; |
---|
| 120 | unsigned32 maximum_pending_messages; |
---|
| 121 | unsigned32 number_of_pending_messages; |
---|
| 122 | unsigned32 maximum_message_size; |
---|
| 123 | Chain_Control Pending_messages; |
---|
| 124 | CORE_message_queue_Buffer *message_buffers; |
---|
| 125 | Chain_Control Inactive_messages; |
---|
| 126 | } CORE_message_queue_Control; |
---|
| 127 | |
---|
| 128 | /* |
---|
| 129 | * _CORE_message_queue_Initialize |
---|
| 130 | * |
---|
| 131 | * DESCRIPTION: |
---|
| 132 | * |
---|
| 133 | * This routine initializes the message_queue based on the parameters passed. |
---|
| 134 | */ |
---|
| 135 | |
---|
| 136 | boolean _CORE_message_queue_Initialize( |
---|
| 137 | CORE_message_queue_Control *the_message_queue, |
---|
| 138 | Objects_Classes the_class, |
---|
| 139 | CORE_message_queue_Attributes *the_message_queue_attributes, |
---|
| 140 | unsigned32 maximum_pending_messages, |
---|
| 141 | unsigned32 maximum_message_size, |
---|
| 142 | Thread_queue_Extract_callout proxy_extract_callout |
---|
| 143 | ); |
---|
| 144 | |
---|
| 145 | /* |
---|
| 146 | * _CORE_message_queue_Close |
---|
| 147 | * |
---|
| 148 | * DESCRIPTION: |
---|
| 149 | * |
---|
| 150 | * This function closes a message by returning all allocated space and |
---|
| 151 | * flushing the message_queue's task wait queue. |
---|
| 152 | */ |
---|
| 153 | |
---|
| 154 | void _CORE_message_queue_Close( |
---|
| 155 | CORE_message_queue_Control *the_message_queue, |
---|
| 156 | Thread_queue_Flush_callout remote_extract_callout, |
---|
| 157 | unsigned32 status |
---|
| 158 | ); |
---|
| 159 | |
---|
| 160 | /* |
---|
| 161 | * |
---|
| 162 | * _CORE_message_queue_Flush |
---|
| 163 | * |
---|
| 164 | * DESCRIPTION: |
---|
| 165 | * |
---|
| 166 | * This function flushes the message_queue's task wait queue. The number |
---|
| 167 | * messages flushed from the queue is returned. |
---|
| 168 | * |
---|
| 169 | */ |
---|
| 170 | |
---|
| 171 | unsigned32 _CORE_message_queue_Flush( |
---|
| 172 | CORE_message_queue_Control *the_message_queue |
---|
| 173 | ); |
---|
| 174 | |
---|
| 175 | /* |
---|
| 176 | * _CORE_message_queue_Flush_support |
---|
| 177 | * |
---|
| 178 | * DESCRIPTION: |
---|
| 179 | * |
---|
| 180 | * This routine flushes all outstanding messages and returns |
---|
| 181 | * them to the inactive message chain. |
---|
| 182 | */ |
---|
| 183 | |
---|
| 184 | unsigned32 _CORE_message_queue_Flush_support( |
---|
| 185 | CORE_message_queue_Control *the_message_queue |
---|
| 186 | ); |
---|
| 187 | |
---|
| 188 | /* |
---|
| 189 | * _CORE_message_queue_send |
---|
| 190 | * |
---|
| 191 | * DESCRIPTION: |
---|
| 192 | * |
---|
| 193 | * This routine sends a message to the end of the specified message queue. |
---|
| 194 | * |
---|
| 195 | */ |
---|
| 196 | |
---|
| 197 | STATIC INLINE CORE_message_queue_Status _CORE_message_queue_Send( |
---|
| 198 | CORE_message_queue_Control *the_message_queue, |
---|
| 199 | void *buffer, |
---|
| 200 | unsigned32 size, |
---|
| 201 | Objects_Id id, |
---|
| 202 | CORE_message_queue_API_mp_support_callout api_message_queue_mp_support |
---|
| 203 | ); |
---|
| 204 | |
---|
| 205 | /* |
---|
| 206 | * |
---|
| 207 | * _CORE_message_queue_Urgent |
---|
| 208 | * |
---|
| 209 | * DESCRIPTION: |
---|
| 210 | * |
---|
| 211 | * This routine sends a message to the front of the specified message queue. |
---|
| 212 | * |
---|
| 213 | */ |
---|
| 214 | |
---|
| 215 | STATIC INLINE CORE_message_queue_Status _CORE_message_queue_Urgent( |
---|
| 216 | CORE_message_queue_Control *the_message_queue, |
---|
| 217 | void *buffer, |
---|
| 218 | unsigned32 size, |
---|
| 219 | Objects_Id id, |
---|
| 220 | CORE_message_queue_API_mp_support_callout api_message_queue_mp_support |
---|
| 221 | ); |
---|
| 222 | |
---|
| 223 | /* |
---|
| 224 | * |
---|
| 225 | * _CORE_message_queue_Broadcast |
---|
| 226 | * |
---|
| 227 | * DESCRIPTION: |
---|
| 228 | * |
---|
| 229 | * This function sends a message for every thread waiting on the queue and |
---|
| 230 | * returns the number of threads made ready by the message. |
---|
| 231 | * |
---|
| 232 | */ |
---|
| 233 | |
---|
| 234 | CORE_message_queue_Status _CORE_message_queue_Broadcast( |
---|
| 235 | CORE_message_queue_Control *the_message_queue, |
---|
| 236 | void *buffer, |
---|
| 237 | unsigned32 size, |
---|
| 238 | Objects_Id id, |
---|
| 239 | CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, |
---|
| 240 | unsigned32 *count |
---|
| 241 | ); |
---|
| 242 | |
---|
| 243 | /* |
---|
| 244 | * |
---|
| 245 | * _CORE_message_queue_Submit |
---|
| 246 | * |
---|
| 247 | * DESCRIPTION: |
---|
| 248 | * |
---|
| 249 | * This routine implements the send and urgent message functions. It |
---|
| 250 | * processes a message that is to be submitted to the designated |
---|
| 251 | * message queue. The message will either be processed as a |
---|
| 252 | * send message which it will be inserted at the rear of the queue |
---|
| 253 | * or it will be processed as an urgent message which will be inserted |
---|
| 254 | * at the front of the queue. |
---|
| 255 | * |
---|
| 256 | */ |
---|
| 257 | |
---|
| 258 | CORE_message_queue_Status _CORE_message_queue_Submit( |
---|
| 259 | CORE_message_queue_Control *the_message_queue, |
---|
| 260 | void *buffer, |
---|
| 261 | unsigned32 size, |
---|
| 262 | Objects_Id id, |
---|
| 263 | CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, |
---|
| 264 | CORE_message_queue_Submit_types submit_type |
---|
| 265 | ); |
---|
| 266 | |
---|
| 267 | /* |
---|
| 268 | * |
---|
| 269 | * _CORE_message_queue_Seize |
---|
| 270 | * |
---|
| 271 | * DESCRIPTION: |
---|
| 272 | * |
---|
| 273 | * This kernel routine dequeues a message, copies the message buffer to |
---|
| 274 | * a given destination buffer, and frees the message buffer to the |
---|
| 275 | * inactive message pool. The thread will be blocked if wait is TRUE, |
---|
| 276 | * otherwise an error will be given to the thread if no messages are available. |
---|
| 277 | * |
---|
| 278 | */ |
---|
| 279 | |
---|
| 280 | void _CORE_message_queue_Seize( |
---|
| 281 | CORE_message_queue_Control *the_message_queue, |
---|
| 282 | Objects_Id id, |
---|
| 283 | void *buffer, |
---|
| 284 | unsigned32 *size, |
---|
| 285 | boolean wait, |
---|
| 286 | Watchdog_Interval timeout |
---|
| 287 | ); |
---|
| 288 | |
---|
| 289 | /* |
---|
| 290 | * _CORE_message_queue_Allocate_message_buffer |
---|
| 291 | * |
---|
| 292 | * DESCRIPTION: |
---|
| 293 | * |
---|
| 294 | * This function allocates a message buffer from the inactive |
---|
| 295 | * message buffer chain. |
---|
| 296 | */ |
---|
| 297 | |
---|
| 298 | STATIC INLINE CORE_message_queue_Buffer_control * |
---|
| 299 | _CORE_message_queue_Allocate_message_buffer ( |
---|
| 300 | CORE_message_queue_Control *the_message_queue |
---|
| 301 | ); |
---|
| 302 | |
---|
| 303 | /* |
---|
| 304 | * _CORE_message_queue_Free_message_buffer |
---|
| 305 | * |
---|
| 306 | * DESCRIPTION: |
---|
| 307 | * |
---|
| 308 | * This routine frees a message buffer to the inactive |
---|
| 309 | * message buffer chain. |
---|
| 310 | */ |
---|
| 311 | |
---|
| 312 | STATIC INLINE void _CORE_message_queue_Free_message_buffer ( |
---|
| 313 | CORE_message_queue_Control *the_message_queue, |
---|
| 314 | CORE_message_queue_Buffer_control *the_message |
---|
| 315 | ); |
---|
| 316 | |
---|
| 317 | /* |
---|
| 318 | * _CORE_message_queue_Copy_buffer |
---|
| 319 | * |
---|
| 320 | * DESCRIPTION: |
---|
| 321 | * |
---|
| 322 | * This routine copies the contents of the source message buffer |
---|
| 323 | * to the destination message buffer. |
---|
| 324 | */ |
---|
| 325 | |
---|
| 326 | STATIC INLINE void _CORE_message_queue_Copy_buffer ( |
---|
| 327 | void *source, |
---|
| 328 | void *destination, |
---|
| 329 | unsigned32 size |
---|
| 330 | ); |
---|
| 331 | |
---|
| 332 | /* |
---|
| 333 | * _CORE_message_queue_Get_pending_message |
---|
| 334 | * |
---|
| 335 | * DESCRIPTION: |
---|
| 336 | * |
---|
| 337 | * This function removes the first message from the_message_queue |
---|
| 338 | * and returns a pointer to it. |
---|
| 339 | */ |
---|
| 340 | |
---|
| 341 | STATIC INLINE |
---|
| 342 | CORE_message_queue_Buffer_control *_CORE_message_queue_Get_pending_message ( |
---|
| 343 | CORE_message_queue_Control *the_message_queue |
---|
| 344 | ); |
---|
| 345 | |
---|
| 346 | /* |
---|
| 347 | * _CORE_message_queue_Is_priority |
---|
| 348 | * |
---|
| 349 | * DESCRIPTION: |
---|
| 350 | * |
---|
| 351 | * This function returns TRUE if the priority attribute is |
---|
| 352 | * enabled in the attribute_set and FALSE otherwise. |
---|
| 353 | */ |
---|
| 354 | |
---|
| 355 | STATIC INLINE boolean _CORE_message_queue_Is_priority( |
---|
| 356 | CORE_message_queue_Attributes *the_attribute |
---|
| 357 | ); |
---|
| 358 | |
---|
| 359 | /* |
---|
| 360 | * _CORE_message_queue_Append |
---|
| 361 | * |
---|
| 362 | * DESCRIPTION: |
---|
| 363 | * |
---|
| 364 | * This routine places the_message at the rear of the outstanding |
---|
| 365 | * messages on the_message_queue. |
---|
| 366 | */ |
---|
| 367 | |
---|
| 368 | STATIC INLINE void _CORE_message_queue_Append ( |
---|
| 369 | CORE_message_queue_Control *the_message_queue, |
---|
| 370 | CORE_message_queue_Buffer_control *the_message |
---|
| 371 | ); |
---|
| 372 | |
---|
| 373 | /* |
---|
| 374 | * _CORE_message_queue_Prepend |
---|
| 375 | * |
---|
| 376 | * DESCRIPTION: |
---|
| 377 | * |
---|
| 378 | * This routine places the_message at the rear of the outstanding |
---|
| 379 | * messages on the_message_queue. |
---|
| 380 | */ |
---|
| 381 | |
---|
| 382 | STATIC INLINE void _CORE_message_queue_Prepend ( |
---|
| 383 | CORE_message_queue_Control *the_message_queue, |
---|
| 384 | CORE_message_queue_Buffer_control *the_message |
---|
| 385 | ); |
---|
| 386 | |
---|
| 387 | /* |
---|
| 388 | * _CORE_message_queue_Is_null |
---|
| 389 | * |
---|
| 390 | * DESCRIPTION: |
---|
| 391 | * |
---|
| 392 | * This function places the_message at the rear of the outstanding |
---|
| 393 | * messages on the_message_queue. |
---|
| 394 | */ |
---|
| 395 | |
---|
| 396 | STATIC INLINE boolean _CORE_message_queue_Is_null ( |
---|
| 397 | CORE_message_queue_Control *the_message_queue |
---|
| 398 | ); |
---|
| 399 | |
---|
| 400 | #include <rtems/core/coremsg.inl> |
---|
| 401 | |
---|
| 402 | #ifdef __cplusplus |
---|
| 403 | } |
---|
| 404 | #endif |
---|
| 405 | |
---|
| 406 | #endif |
---|
| 407 | /* end of include file */ |
---|
| 408 | |
---|