RTEMS  5.1
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 
92  CORE_message_queue_Control *the_message_queue,
94  uint32_t maximum_pending_messages,
95  size_t maximum_message_size
96 );
97 
113  CORE_message_queue_Control *the_message_queue,
114  Thread_queue_Context *queue_context
115 );
116 
133  CORE_message_queue_Control *the_message_queue,
134  Thread_queue_Context *queue_context
135 );
136 
137 #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
138 
150  void _CORE_message_queue_Flush_waiting_threads(
151  CORE_message_queue_Control *the_message_queue
152  );
153 #endif
154 
176 Status_Control _CORE_message_queue_Broadcast(
177  CORE_message_queue_Control *the_message_queue,
178  const void *buffer,
179  size_t size,
180  uint32_t *count,
181  Thread_queue_Context *queue_context
182 );
183 
211 Status_Control _CORE_message_queue_Submit(
212  CORE_message_queue_Control *the_message_queue,
213  Thread_Control *executing,
214  const void *buffer,
215  size_t size,
217  bool wait,
218  Thread_queue_Context *queue_context
219 );
220 
254 Status_Control _CORE_message_queue_Seize(
255  CORE_message_queue_Control *the_message_queue,
256  Thread_Control *executing,
257  void *buffer,
258  size_t *size_p,
259  bool wait,
260  Thread_queue_Context *queue_context
261 );
262 
277  CORE_message_queue_Control *the_message_queue,
279  const void *content_source,
280  size_t content_size,
282 );
283 
302  CORE_message_queue_Control *the_message_queue,
303  const void *buffer,
304  size_t size,
305  bool wait,
306  Thread_queue_Context *queue_context
307 )
308 {
310  the_message_queue,
311  _Thread_Executing,
312  buffer,
313  size,
315  wait,
316  queue_context
317  );
318 }
319 
338  CORE_message_queue_Control *the_message_queue,
339  const void *buffer,
340  size_t size,
341  bool wait,
342  Thread_queue_Context *queue_context
343 )
344 {
346  the_message_queue,
347  _Thread_Executing,
348  buffer,
349  size,
351  wait,
352  queue_context
353  );
354 }
355 
363  CORE_message_queue_Control *the_message_queue,
364  Thread_queue_Context *queue_context
365 )
366 {
367  _Thread_queue_Acquire( &the_message_queue->Wait_queue, queue_context );
368 }
369 
377  CORE_message_queue_Control *the_message_queue,
378  Thread_queue_Context *queue_context
379 )
380 {
381  _Thread_queue_Acquire_critical( &the_message_queue->Wait_queue, queue_context );
382 }
383 
391  CORE_message_queue_Control *the_message_queue,
392  Thread_queue_Context *queue_context
393 )
394 {
395  _Thread_queue_Release( &the_message_queue->Wait_queue, queue_context );
396 }
397 
409  const void *source,
410  void *destination,
411  size_t size
412 )
413 {
414  memcpy(destination, source, size);
415 }
416 
430  CORE_message_queue_Control *the_message_queue
431 )
432 {
434  _Chain_Get_unprotected( &the_message_queue->Inactive_messages );
435 }
436 
447  CORE_message_queue_Control *the_message_queue,
449 )
450 {
451  _Chain_Append_unprotected( &the_message_queue->Inactive_messages, &the_message->Node );
452 }
453 
468  const CORE_message_queue_Buffer_control *the_message
469 )
470 {
471  #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
472  return the_message->priority;
473  #else
474  return 0;
475  #endif
476 }
477 
491  CORE_message_queue_Control *the_message_queue
492 )
493 {
495  _Chain_Get_unprotected( &the_message_queue->Pending_messages );
496 }
497 
498 #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
499 
510  RTEMS_INLINE_ROUTINE bool _CORE_message_queue_Is_notify_enabled (
511  CORE_message_queue_Control *the_message_queue
512  )
513  {
514  return (the_message_queue->notify_handler != NULL);
515  }
516 #endif
517 
527 #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
529  CORE_message_queue_Control *the_message_queue,
530  CORE_message_queue_Notify_Handler the_handler
531  )
532  {
533  the_message_queue->notify_handler = the_handler;
534  }
535 #else
536  /* turn it into nothing if not enabled */
537  #define _CORE_message_queue_Set_notify( the_message_queue, the_handler ) \
538  do { } while ( 0 )
539 #endif
540 
557  CORE_message_queue_Control *the_message_queue,
558  const void *buffer,
559  size_t size,
561  Thread_queue_Context *queue_context
562 )
563 {
564  Thread_Control *the_thread;
565 
566  /*
567  * If there are pending messages, then there can't be threads
568  * waiting for us to send them a message.
569  *
570  * NOTE: This check is critical because threads can block on
571  * send and receive and this ensures that we are broadcasting
572  * the message to threads waiting to receive -- not to send.
573  */
574  if ( the_message_queue->number_of_pending_messages != 0 ) {
575  return NULL;
576  }
577 
578  /*
579  * There must be no pending messages if there is a thread waiting to
580  * receive a message.
581  */
582  the_thread = _Thread_queue_First_locked(
583  &the_message_queue->Wait_queue,
584  the_message_queue->operations
585  );
586  if ( the_thread == NULL ) {
587  return NULL;
588  }
589 
590  *(size_t *) the_thread->Wait.return_argument = size;
591  the_thread->Wait.count = (uint32_t) submit_type;
592 
594  buffer,
595  the_thread->Wait.return_argument_second.mutable_object,
596  size
597  );
598 
600  &the_message_queue->Wait_queue.Queue,
601  the_message_queue->operations,
602  the_thread,
603  queue_context
604  );
605 
606  return the_thread;
607 }
608 
611 #ifdef __cplusplus
612 }
613 #endif
614 
615 #endif
616 /* end of include file */
RTEMS_INLINE_ROUTINE 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:774
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:35
Chain_Control Inactive_messages
Definition: coremsg.h:176
RTEMS_INLINE_ROUTINE 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:556
Constants and Structures Related with Thread Dispatch.
RTEMS_INLINE_ROUTINE void _CORE_message_queue_Free_message_buffer(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Buffer_control *the_message)
Frees a message buffer to inactive message buffer chain.
Definition: coremsgimpl.h:446
void * return_argument
Definition: thread.h:409
Chain_Node Node
Definition: coremsg.h:94
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
The organization of a message buffer.
Definition: coremsg.h:92
#define _CORE_message_queue_Set_notify(the_message_queue, the_handler)
Initializes notification information.
Definition: coremsgimpl.h:537
RTEMS_INLINE_ROUTINE void _CORE_message_queue_Release(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Releases the message queue.
Definition: coremsgimpl.h:390
void _CORE_message_queue_Insert_message(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Buffer_control *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
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
int priority
Definition: coremsg.h:97
const Thread_queue_Operations * operations
The thread queue operations according to the blocking discipline.
Definition: coremsg.h:145
uint32_t number_of_pending_messages
Definition: coremsg.h:153
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:583
#define CORE_MESSAGE_QUEUE_SEND_REQUEST
Used when appending messages onto a message queue.
Definition: coremsgimpl.h:49
Definition: thread.h:732
RTEMS_INLINE_ROUTINE CORE_message_queue_Buffer_control * _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:429
RTEMS_INLINE_ROUTINE 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:408
Constants and Structures Associated with the Manipulation of Objects.
RTEMS_INLINE_ROUTINE 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:301
Chain_Control Pending_messages
Definition: coremsg.h:161
RTEMS_INLINE_ROUTINE 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:376
#define CORE_MESSAGE_QUEUE_URGENT_REQUEST
Used when prepending messages onto a message queue.
Definition: coremsgimpl.h:57
Chain Handler API.
RTEMS_INLINE_ROUTINE void _CORE_message_queue_Acquire(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Acquires the message queue.
Definition: coremsgimpl.h:362
RTEMS_INLINE_ROUTINE int _CORE_message_queue_Get_message_priority(const CORE_message_queue_Buffer_control *the_message)
Gets message priority.
Definition: coremsgimpl.h:467
CORE_message_queue_Disciplines
The possible blocking disciplines for a message queue.
Definition: coremsg.h:109
RTEMS_INLINE_ROUTINE CORE_message_queue_Buffer_control * _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:490
RTEMS_INLINE_ROUTINE 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:337
RTEMS_INLINE_ROUTINE 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
RTEMS_INLINE_ROUTINE void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Appends a node (unprotected).
Definition: chainimpl.h:680
uint32_t count
Definition: thread.h:407
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.
Definition: coremsgbroadcast.c:24
Constants and Structures Associated with the Message Queue Handler.
Control block used to manage each message queue.
Definition: coremsg.h:136
Thread_Wait_information_Object_argument_type return_argument_second
Definition: thread.h:412
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
RTEMS_INLINE_ROUTINE void _Thread_queue_Release(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Releases the thread queue control and enables interrupts.
Definition: threadqimpl.h:787
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_Get_unprotected(Chain_Control *the_chain)
Gets the first node (unprotected).
Definition: chainimpl.h:630
unsigned size
Definition: tte.h:74
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.
Definition: threadqenqueue.c:600
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
RTEMS_INLINE_ROUTINE 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: threadqimpl.h:704
Thread_queue_Control Wait_queue
Definition: coremsg.h:140
bool _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)
Initializes a message queue.
Definition: coremsg.c:45
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77