RTEMS
coremsgimpl.h
Go to the documentation of this file.
1 
12 /*
13  * COPYRIGHT (c) 1989-2009.
14  * On-Line Applications Research Corporation (OAR).
15  *
16  * The license and distribution terms for this file may be
17  * found in the file LICENSE in this distribution or at
18  * http://www.rtems.org/license/LICENSE.
19  */
20 
21 #ifndef _RTEMS_SCORE_COREMSGIMPL_H
22 #define _RTEMS_SCORE_COREMSGIMPL_H
23 
24 #include <rtems/score/coremsg.h>
25 #include <rtems/score/status.h>
26 #include <rtems/score/chainimpl.h>
29 
30 #include <limits.h>
31 #include <string.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
49 #define CORE_MESSAGE_QUEUE_SEND_REQUEST INT_MAX
50 
57 #define CORE_MESSAGE_QUEUE_URGENT_REQUEST INT_MIN
58 
70 
89 typedef void *( *CORE_message_queue_Allocate_buffers )(
90  CORE_message_queue_Control *the_message_queue,
91  size_t size,
92  const void *arg
93 );
94 
114  CORE_message_queue_Control *the_message_queue,
115  size_t size,
116  const void *arg
117 );
118 
145 Status_Control _CORE_message_queue_Initialize(
146  CORE_message_queue_Control *the_message_queue,
148  uint32_t maximum_pending_messages,
149  size_t maximum_message_size,
150  CORE_message_queue_Allocate_buffers allocate_buffers,
151  const void *arg
152 );
153 
169  CORE_message_queue_Control *the_message_queue,
170  Thread_queue_Context *queue_context
171 );
172 
189  CORE_message_queue_Control *the_message_queue,
190  Thread_queue_Context *queue_context
191 );
192 
193 #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
194 
206  void _CORE_message_queue_Flush_waiting_threads(
207  CORE_message_queue_Control *the_message_queue
208  );
209 #endif
210 
232 Status_Control _CORE_message_queue_Broadcast(
233  CORE_message_queue_Control *the_message_queue,
234  const void *buffer,
235  size_t size,
236  uint32_t *count,
237  Thread_queue_Context *queue_context
238 );
239 
267 Status_Control _CORE_message_queue_Submit(
268  CORE_message_queue_Control *the_message_queue,
269  Thread_Control *executing,
270  const void *buffer,
271  size_t size,
273  bool wait,
274  Thread_queue_Context *queue_context
275 );
276 
310 Status_Control _CORE_message_queue_Seize(
311  CORE_message_queue_Control *the_message_queue,
312  Thread_Control *executing,
313  void *buffer,
314  size_t *size_p,
315  bool wait,
316  Thread_queue_Context *queue_context
317 );
318 
333  CORE_message_queue_Control *the_message_queue,
334  CORE_message_queue_Buffer *the_message,
335  const void *content_source,
336  size_t content_size,
338 );
339 
358  CORE_message_queue_Control *the_message_queue,
359  const void *buffer,
360  size_t size,
361  bool wait,
362  Thread_queue_Context *queue_context
363 )
364 {
366  the_message_queue,
367  _Thread_Executing,
368  buffer,
369  size,
371  wait,
372  queue_context
373  );
374 }
375 
394  CORE_message_queue_Control *the_message_queue,
395  const void *buffer,
396  size_t size,
397  bool wait,
398  Thread_queue_Context *queue_context
399 )
400 {
402  the_message_queue,
403  _Thread_Executing,
404  buffer,
405  size,
407  wait,
408  queue_context
409  );
410 }
411 
419  CORE_message_queue_Control *the_message_queue,
420  Thread_queue_Context *queue_context
421 )
422 {
423  _Thread_queue_Acquire( &the_message_queue->Wait_queue, queue_context );
424 }
425 
433  CORE_message_queue_Control *the_message_queue,
434  Thread_queue_Context *queue_context
435 )
436 {
437  _Thread_queue_Acquire_critical( &the_message_queue->Wait_queue, queue_context );
438 }
439 
447  CORE_message_queue_Control *the_message_queue,
448  Thread_queue_Context *queue_context
449 )
450 {
451  _Thread_queue_Release( &the_message_queue->Wait_queue, queue_context );
452 }
453 
465  const void *source,
466  void *destination,
467  size_t size
468 )
469 {
470  memcpy(destination, source, size);
471 }
472 
486  CORE_message_queue_Control *the_message_queue
487 )
488 {
489  return (CORE_message_queue_Buffer *)
490  _Chain_Get_unprotected( &the_message_queue->Inactive_messages );
491 }
492 
503  CORE_message_queue_Control *the_message_queue,
504  CORE_message_queue_Buffer *the_message
505 )
506 {
507  _Chain_Append_unprotected( &the_message_queue->Inactive_messages, &the_message->Node );
508 }
509 
524  const CORE_message_queue_Buffer *the_message
525 )
526 {
527  #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
528  return the_message->priority;
529  #else
530  return 0;
531  #endif
532 }
533 
547  CORE_message_queue_Control *the_message_queue
548 )
549 {
550  return (CORE_message_queue_Buffer *)
551  _Chain_Get_unprotected( &the_message_queue->Pending_messages );
552 }
553 
554 #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
555 
566  RTEMS_INLINE_ROUTINE bool _CORE_message_queue_Is_notify_enabled (
567  CORE_message_queue_Control *the_message_queue
568  )
569  {
570  return (the_message_queue->notify_handler != NULL);
571  }
572 #endif
573 
583 #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
585  CORE_message_queue_Control *the_message_queue,
586  CORE_message_queue_Notify_Handler the_handler
587  )
588  {
589  the_message_queue->notify_handler = the_handler;
590  }
591 #else
592  /* turn it into nothing if not enabled */
593  #define _CORE_message_queue_Set_notify( the_message_queue, the_handler ) \
594  do { } while ( 0 )
595 #endif
596 
613  CORE_message_queue_Control *the_message_queue,
614  const void *buffer,
615  size_t size,
617  Thread_queue_Context *queue_context
618 )
619 {
620  Thread_Control *the_thread;
621 
622  /*
623  * If there are pending messages, then there can't be threads
624  * waiting for us to send them a message.
625  *
626  * NOTE: This check is critical because threads can block on
627  * send and receive and this ensures that we are broadcasting
628  * the message to threads waiting to receive -- not to send.
629  */
630  if ( the_message_queue->number_of_pending_messages != 0 ) {
631  return NULL;
632  }
633 
634  /*
635  * There must be no pending messages if there is a thread waiting to
636  * receive a message.
637  */
638  the_thread = _Thread_queue_First_locked(
639  &the_message_queue->Wait_queue,
640  the_message_queue->operations
641  );
642  if ( the_thread == NULL ) {
643  return NULL;
644  }
645 
646  *(size_t *) the_thread->Wait.return_argument = size;
647  the_thread->Wait.count = (uint32_t) submit_type;
648 
650  buffer,
651  the_thread->Wait.return_argument_second.mutable_object,
652  size
653  );
654 
656  &the_message_queue->Wait_queue.Queue,
657  the_message_queue->operations,
658  the_thread,
659  queue_context
660  );
661 
662  return the_thread;
663 }
664 
667 #ifdef __cplusplus
668 }
669 #endif
670 
671 #endif
672 /* end of include file */
static __inline__ void _Thread_queue_Acquire_critical(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Acquires the thread queue control in a critical section.
Definition: threadqimpl.h:681
static __inline__ CORE_message_queue_Buffer * _CORE_message_queue_Get_pending_message(CORE_message_queue_Control *the_message_queue)
Gets first message of message queue and removes it.
Definition: coremsgimpl.h:546
static __inline__ Thread_Control * _Thread_queue_First_locked(Thread_queue_Control *the_thread_queue, const Thread_queue_Operations *operations)
Returns the first thread on the thread queue if it exists, otherwise NULL.
Definition: threadqimpl.h:1173
Thread_Wait_information Wait
Definition: thread.h:767
Thread queue context for the thread queue methods.
Definition: threadq.h:198
int CORE_message_queue_Submit_types
The modes in which a message may be submitted to a message queue.
Definition: coremsgimpl.h:69
void _CORE_message_queue_Close(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Closes a message queue.
Definition: coremsgclose.c:34
Chain_Control Inactive_messages
Definition: coremsg.h:146
static __inline__ void _CORE_message_queue_Free_message_buffer(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Buffer *the_message)
Frees a message buffer to inactive message buffer chain.
Definition: coremsgimpl.h:502
void _Thread_queue_Acquire(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Acquires the thread queue control in a critical section.
Definition: threadq.c:87
Constants and Structures Related with Thread Dispatch.
static __inline__ void _CORE_message_queue_Copy_buffer(const void *source, void *destination, size_t size)
Copies the source message buffer to the destination message buffer.
Definition: coremsgimpl.h:464
void *(* CORE_message_queue_Allocate_buffers)(CORE_message_queue_Control *the_message_queue, size_t size, const void *arg)
This handler shall allocate the message buffer storage area for a message queue.
Definition: coremsgimpl.h:89
static __inline__ Status_Control _CORE_message_queue_Urgent(CORE_message_queue_Control *the_message_queue, const void *buffer, size_t size, bool wait, Thread_queue_Context *queue_context)
Sends an urgent message to the message queue.
Definition: coremsgimpl.h:393
uint32_t _CORE_message_queue_Flush(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Flushes pending messages.
Definition: coremsgflush.c:24
#define _CORE_message_queue_Set_notify(the_message_queue, the_handler)
Initializes notification information.
Definition: coremsgimpl.h:593
Status_Control _CORE_message_queue_Seize(CORE_message_queue_Control *the_message_queue, Thread_Control *executing, void *buffer, size_t *size_p, bool wait, Thread_queue_Context *queue_context)
Seizes a message from the message queue.
Definition: coremsgseize.c:27
const Thread_queue_Operations * operations
The thread queue operations according to the blocking discipline.
Definition: coremsg.h:105
uint32_t number_of_pending_messages
Definition: coremsg.h:113
static __inline__ CORE_message_queue_Buffer * _CORE_message_queue_Allocate_message_buffer(CORE_message_queue_Control *the_message_queue)
Allocates a message buffer from the inactive message buffer chain.
Definition: coremsgimpl.h:485
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:583
static __inline__ void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Appends a node (unprotected).
Definition: chainimpl.h:680
void _CORE_message_queue_Insert_message(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Buffer *the_message, const void *content_source, size_t content_size, CORE_message_queue_Submit_types submit_type)
Inserts a message into the message queue.
Definition: coremsginsert.c:41
#define CORE_MESSAGE_QUEUE_SEND_REQUEST
Used when appending messages onto a message queue.
Definition: coremsgimpl.h:49
static __inline__ Thread_Control * _CORE_message_queue_Dequeue_receiver(CORE_message_queue_Control *the_message_queue, const void *buffer, size_t size, CORE_message_queue_Submit_types submit_type, Thread_queue_Context *queue_context)
Gets the first locked thread waiting to receive and dequeues it.
Definition: coremsgimpl.h:612
Constants and Structures Associated with the Manipulation of Objects.
static __inline__ int _CORE_message_queue_Get_message_priority(const CORE_message_queue_Buffer *the_message)
Gets message priority.
Definition: coremsgimpl.h:523
Chain_Control Pending_messages
Definition: coremsg.h:121
#define CORE_MESSAGE_QUEUE_URGENT_REQUEST
Used when prepending messages onto a message queue.
Definition: coremsgimpl.h:57
The structure is used to organize message buffers of a message queue.
Definition: coremsgbuffer.h:63
Chain Handler API.
CORE_message_queue_Disciplines
The possible blocking disciplines for a message queue.
Definition: coremsg.h:69
Status_Control _CORE_message_queue_Initialize(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Disciplines discipline, uint32_t maximum_pending_messages, size_t maximum_message_size, CORE_message_queue_Allocate_buffers allocate_buffers, const void *arg)
Initializes a message queue.
Definition: coremsg.c:33
static __inline__ Status_Control _CORE_message_queue_Send(CORE_message_queue_Control *the_message_queue, const void *buffer, size_t size, bool wait, Thread_queue_Context *queue_context)
Sends a message to the message queue.
Definition: coremsgimpl.h:357
Status_Control _CORE_message_queue_Broadcast(CORE_message_queue_Control *the_message_queue, const void *buffer, size_t size, uint32_t *count, Thread_queue_Context *queue_context)
Broadcasts a message to the message queue.
int priority
This member defines the priority of this message.
Definition: coremsgbuffer.h:75
Constants and Structures Associated with the Message Queue Handler.
Control block used to manage each message queue.
Definition: coremsg.h:96
Thread_Wait_information_Object_argument_type return_argument_second
Definition: thread.h:405
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
Definition: basedefs.h:683
Status_Control _CORE_message_queue_Submit(CORE_message_queue_Control *the_message_queue, Thread_Control *executing, const void *buffer, size_t size, CORE_message_queue_Submit_types submit_type, bool wait, Thread_queue_Context *queue_context)
Submits a message to the message queue.
Definition: coremsgsubmit.c:29
void _Thread_queue_Release(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Releases the thread queue control and enables interrupts.
Definition: threadq.c:118
static __inline__ void _CORE_message_queue_Release(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Releases the message queue.
Definition: coremsgimpl.h:446
void _Thread_queue_Extract_critical(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Extracts the thread from the thread queue and unblocks it.
void * _CORE_message_queue_Workspace_allocate(CORE_message_queue_Control *the_message_queue, size_t size, const void *arg)
This handler allocates the message buffer storage area for a message queue from the RTEMS Workspace...
Chain_Node Node
This member is used to enqueue the buffer in the pending or free buffer queue of a message queue...
Definition: coremsgbuffer.h:68
Thread_queue_Control Wait_queue
Definition: coremsg.h:100
static __inline__ void _CORE_message_queue_Acquire_critical(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Acquires the message queue critical.
Definition: coremsgimpl.h:432
static __inline__ Chain_Node * _Chain_Get_unprotected(Chain_Control *the_chain)
Gets the first node (unprotected).
Definition: chainimpl.h:630
static __inline__ void _CORE_message_queue_Acquire(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Acquires the message queue.
Definition: coremsgimpl.h:418