RTEMS CPU Kit with SuperCore  4.11.2
coremsgimpl.h
Go to the documentation of this file.
1 
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>
26 
27 #include <limits.h>
28 #include <string.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
45 #define CORE_MESSAGE_QUEUE_SEND_REQUEST INT_MAX
46 
53 #define CORE_MESSAGE_QUEUE_URGENT_REQUEST INT_MIN
54 
66 
73 typedef enum {
95 
101 #define CORE_MESSAGE_QUEUE_STATUS_LAST CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT
102 
110  Thread_Control *,
111  Objects_Id
112  );
113 
137  CORE_message_queue_Control *the_message_queue,
138  CORE_message_queue_Attributes *the_message_queue_attributes,
139  uint32_t maximum_pending_messages,
140  size_t maximum_message_size
141 );
142 
160  CORE_message_queue_Control *the_message_queue,
161  Thread_queue_Flush_callout remote_extract_callout,
162  uint32_t status
163 );
164 
181  CORE_message_queue_Control *the_message_queue,
182  ISR_lock_Context *lock_context
183 );
184 
185 #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
186 
197  void _CORE_message_queue_Flush_waiting_threads(
198  CORE_message_queue_Control *the_message_queue
199  );
200 #endif
201 
225 CORE_message_queue_Status _CORE_message_queue_Broadcast(
226  CORE_message_queue_Control *the_message_queue,
227  const void *buffer,
228  size_t size,
229  Objects_Id id,
230  CORE_message_queue_API_mp_support_callout api_message_queue_mp_support,
231  uint32_t *count,
232  ISR_lock_Context *lock_context
233 );
234 
261 CORE_message_queue_Status _CORE_message_queue_Submit(
262  CORE_message_queue_Control *the_message_queue,
263  Thread_Control *executing,
264  const void *buffer,
265  size_t size,
266  Objects_Id id,
267  CORE_message_queue_API_mp_support_callout api_message_queue_mp_support,
268  CORE_message_queue_Submit_types submit_type,
269  bool wait,
270  Watchdog_Interval timeout,
271  ISR_lock_Context *lock_context
272 );
273 
310  CORE_message_queue_Control *the_message_queue,
311  Thread_Control *executing,
312  Objects_Id id,
313  void *buffer,
314  size_t *size_p,
315  bool wait,
316  Watchdog_Interval timeout,
317  ISR_lock_Context *lock_context
318 );
319 
336  CORE_message_queue_Control *the_message_queue,
338  CORE_message_queue_Submit_types submit_type
339 );
340 
345  CORE_message_queue_Control *the_message_queue,
346  const void *buffer,
347  size_t size,
348  Objects_Id id,
349  CORE_message_queue_API_mp_support_callout api_message_queue_mp_support,
350  bool wait,
351  Watchdog_Interval timeout,
352  ISR_lock_Context *lock_context
353 )
354 {
356  the_message_queue,
357  _Thread_Executing,
358  buffer,
359  size,
360  id,
361  api_message_queue_mp_support,
363  wait, /* sender may block */
364  timeout, /* timeout interval */
365  lock_context
366  );
367 }
368 
373  CORE_message_queue_Control *the_message_queue,
374  const void *buffer,
375  size_t size,
376  Objects_Id id,
377  CORE_message_queue_API_mp_support_callout api_message_queue_mp_support,
378  bool wait,
379  Watchdog_Interval timeout,
380  ISR_lock_Context *lock_context
381 )
382 {
384  the_message_queue,
385  _Thread_Executing,
386  buffer,
387  size,
388  id,
389  api_message_queue_mp_support,
391  wait, /* sender may block */
392  timeout, /* timeout interval */
393  lock_context
394  );
395 }
396 
397 RTEMS_INLINE_ROUTINE void _CORE_message_queue_Acquire(
398  CORE_message_queue_Control *the_message_queue,
399  ISR_lock_Context *lock_context
400 )
401 {
402  _Thread_queue_Acquire( &the_message_queue->Wait_queue, lock_context );
403 }
404 
405 RTEMS_INLINE_ROUTINE void _CORE_message_queue_Acquire_critical(
406  CORE_message_queue_Control *the_message_queue,
407  ISR_lock_Context *lock_context
408 )
409 {
410  _Thread_queue_Acquire_critical( &the_message_queue->Wait_queue, lock_context );
411 
412  #if defined(RTEMS_MULTIPROCESSING)
413  /*
414  * In case RTEMS_MULTIPROCESSING is enabled, then we have to prevent
415  * deletion of the executing thread after the thread queue operations.
416  */
418  #endif
419 }
420 
421 RTEMS_INLINE_ROUTINE void _CORE_message_queue_Release(
422  CORE_message_queue_Control *the_message_queue,
423  ISR_lock_Context *lock_context
424 )
425 {
426  _Thread_queue_Release( &the_message_queue->Wait_queue, lock_context );
427  #if defined(RTEMS_MULTIPROCESSING)
428  _Thread_Dispatch_enable( _Per_CPU_Get() );
429  #endif
430 }
431 
437  const void *source,
438  void *destination,
439  size_t size
440 )
441 {
442  memcpy(destination, source, size);
443 }
444 
451  CORE_message_queue_Control *the_message_queue
452 )
453 {
455  _Chain_Get_unprotected( &the_message_queue->Inactive_messages );
456 }
457 
463  CORE_message_queue_Control *the_message_queue,
465 )
466 {
467  _Chain_Append_unprotected( &the_message_queue->Inactive_messages, &the_message->Node );
468 }
469 
477  const CORE_message_queue_Buffer_control *the_message
478 )
479 {
480  #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
481  return the_message->priority;
482  #else
483  return 0;
484  #endif
485 }
486 
495  int priority
496 )
497 {
498  #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
499  the_message->priority = priority;
500  #endif
501 }
502 
509  CORE_message_queue_Control *the_message_queue
510 )
511 {
513  _Chain_Get_unprotected( &the_message_queue->Pending_messages );
514 }
515 
521  CORE_message_queue_Attributes *the_attribute
522 )
523 {
524  return
526 }
527 
528 #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
529 
533  RTEMS_INLINE_ROUTINE bool _CORE_message_queue_Is_notify_enabled (
534  CORE_message_queue_Control *the_message_queue
535  )
536  {
537  return (the_message_queue->notify_handler != NULL);
538  }
539 #endif
540 
545 #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
547  CORE_message_queue_Control *the_message_queue,
548  CORE_message_queue_Notify_Handler the_handler,
549  void *the_argument
550  )
551  {
552  the_message_queue->notify_handler = the_handler;
553  the_message_queue->notify_argument = the_argument;
554  }
555 #else
556  /* turn it into nothing if not enabled */
557  #define _CORE_message_queue_Set_notify( \
558  the_message_queue, the_handler, the_argument )
559 #endif
560 
561 RTEMS_INLINE_ROUTINE Thread_Control *_CORE_message_queue_Dequeue_receiver(
562  CORE_message_queue_Control *the_message_queue,
563  const void *buffer,
564  size_t size,
565  CORE_message_queue_Submit_types submit_type,
566  ISR_lock_Context *lock_context
567 )
568 {
569  Thread_Control *the_thread;
570 
571  /*
572  * If there are pending messages, then there can't be threads
573  * waiting for us to send them a message.
574  *
575  * NOTE: This check is critical because threads can block on
576  * send and receive and this ensures that we are broadcasting
577  * the message to threads waiting to receive -- not to send.
578  */
579  if ( the_message_queue->number_of_pending_messages != 0 ) {
580  return NULL;
581  }
582 
583  /*
584  * There must be no pending messages if there is a thread waiting to
585  * receive a message.
586  */
587  the_thread = _Thread_queue_First_locked( &the_message_queue->Wait_queue );
588  if ( the_thread == NULL ) {
589  return NULL;
590  }
591 
592  *(size_t *) the_thread->Wait.return_argument = size;
593  the_thread->Wait.count = (uint32_t) submit_type;
594 
596  buffer,
597  the_thread->Wait.return_argument_second.mutable_object,
598  size
599  );
600 
602  &the_message_queue->Wait_queue,
603  the_thread,
604  lock_context
605  );
606 
607  return the_thread;
608 }
609 
612 #ifdef __cplusplus
613 }
614 #endif
615 
616 #endif
617 /* end of include file */
This value indicates that a blocking send was unsuccessful.
Definition: coremsgimpl.h:83
RTEMS_INLINE_ROUTINE void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Append a node (unprotected).
Definition: chainimpl.h:743
RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Urgent(CORE_message_queue_Control *the_message_queue, const void *buffer, size_t size, Objects_Id id, CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, bool wait, Watchdog_Interval timeout, ISR_lock_Context *lock_context)
This routine sends a message to the front of the specified message queue.
Definition: coremsgimpl.h:372
CORE_message_queue_Status
The possible set of Core Message Queue handler return statuses.
Definition: coremsgimpl.h:73
#define _CORE_message_queue_Set_notify(the_message_queue, the_handler, the_argument)
This routine initializes the notification information for the_message_queue.
Definition: coremsgimpl.h:557
This value indicates that the thread had to timeout while waiting to receive a message because one di...
Definition: coremsgimpl.h:91
uint32_t _CORE_message_queue_Flush(CORE_message_queue_Control *the_message_queue, ISR_lock_Context *lock_context)
Flush pending messages.
Definition: coremsgflush.c:24
Chain_Control Inactive_messages
This chain is the set of inactive messages.
Definition: coremsg.h:180
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
This value indicates that a receive was unsuccessful.
Definition: coremsgimpl.h:81
RTEMS_INLINE_ROUTINE void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
Definition: threaddispatch.h:304
CORE_message_queue_Status _CORE_message_queue_Broadcast(CORE_message_queue_Control *the_message_queue, const void *buffer, size_t size, Objects_Id id, CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, uint32_t *count, ISR_lock_Context *lock_context)
Broadcast a message to the message queue.
Definition: coremsgbroadcast.c:24
CORE_message_queue_Status _CORE_message_queue_Submit(CORE_message_queue_Control *the_message_queue, Thread_Control *executing, const void *buffer, size_t size, Objects_Id id, CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, CORE_message_queue_Submit_types submit_type, bool wait, Watchdog_Interval timeout, ISR_lock_Context *lock_context)
Submit a message to the message queue.
Definition: coremsgsubmit.c:28
void * return_argument
This field is for a pointer to a user return argument.
Definition: thread.h:306
Control block used to manage the attributes of each message queue.
Definition: coremsg.h:118
Chain_Node Node
This element allows this structure to be placed on chains.
Definition: coremsg.h:90
int CORE_message_queue_Submit_types
The modes in which a message may be submitted to a message queue.
Definition: coremsgimpl.h:65
The organization of a message buffer.
Definition: coremsg.h:88
This value indicates that a blocking receive was unsuccessful.
Definition: coremsgimpl.h:93
RTEMS_INLINE_ROUTINE Per_CPU_Control * _Thread_Dispatch_disable(void)
Disables thread dispatching.
Definition: threaddispatch.h:277
uint32_t number_of_pending_messages
This element is the number of messages which are currently pending.
Definition: coremsg.h:155
RTEMS_INLINE_ROUTINE void _CORE_message_queue_Free_message_buffer(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Buffer_control *the_message)
This routine frees a message buffer to the inactive message buffer chain.
Definition: coremsgimpl.h:462
RTEMS_INLINE_ROUTINE int _CORE_message_queue_Get_message_priority(const CORE_message_queue_Buffer_control *the_message)
This function returns the priority of the_message.
Definition: coremsgimpl.h:476
void _Thread_queue_Extract_critical(Thread_queue_Control *the_thread_queue, Thread_Control *the_thread, ISR_lock_Context *lock_context)
Extracts the thread from the thread queue and unblocks it.
Definition: threadqenqueue.c:152
RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Send(CORE_message_queue_Control *the_message_queue, const void *buffer, size_t size, Objects_Id id, CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, bool wait, Watchdog_Interval timeout, ISR_lock_Context *lock_context)
This routine sends a message to the end of the specified message queue.
Definition: coremsgimpl.h:344
void(* CORE_message_queue_API_mp_support_callout)(Thread_Control *, Objects_Id)
Callout provides to support global/multiprocessor operations.
Definition: coremsgimpl.h:109
void _CORE_message_queue_Close(CORE_message_queue_Control *the_message_queue, Thread_queue_Flush_callout remote_extract_callout, uint32_t status)
Close a message queue.
Definition: coremsgclose.c:24
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_Get_unprotected(Chain_Control *the_chain)
Get the first node (unprotected).
Definition: chainimpl.h:695
RTEMS_INLINE_ROUTINE CORE_message_queue_Buffer_control * _CORE_message_queue_Get_pending_message(CORE_message_queue_Control *the_message_queue)
This function removes the first message from the_message_queue and returns a pointer to it...
Definition: coremsgimpl.h:508
This structure defines the Thread Control Block (TCB).
Definition: thread.h:671
RTEMS_INLINE_ROUTINE bool _CORE_message_queue_Is_priority(CORE_message_queue_Attributes *the_attribute)
This function returns true if the priority attribute is enabled in the attribute_set and false otherw...
Definition: coremsgimpl.h:520
#define CORE_MESSAGE_QUEUE_URGENT_REQUEST
Used when prepending messages onto a message queue.
Definition: coremsgimpl.h:53
This value indicates that there are too many messages pending.
Definition: coremsgimpl.h:79
CORE_message_queue_Disciplines discipline
This field specifies the order in which blocking tasks will be ordered.
Definition: coremsg.h:120
This value indicates that the message was too large for this queue.
Definition: coremsgimpl.h:77
Constants and Structures Associated with the Manipulation of Objects.
This value indicates the operation completed sucessfully.
Definition: coremsgimpl.h:75
Chain_Control Pending_messages
This chain is the set of pending messages.
Definition: coremsg.h:163
RTEMS_INLINE_ROUTINE void _CORE_message_queue_Set_message_priority(CORE_message_queue_Buffer_control *the_message, int priority)
This function sets the priority of the_message.
Definition: coremsgimpl.h:493
#define CORE_MESSAGE_QUEUE_SEND_REQUEST
Used when appending messages onto a message queue.
Definition: coremsgimpl.h:45
Chain Handler API.
This value indicates that the message queue being blocked upon was deleted while the thread was waiti...
Definition: coremsgimpl.h:87
uint32_t Watchdog_Interval
Type is used to specify the length of intervals.
Definition: watchdog.h:47
uint32_t count
This field is used to return an integer while when blocked.
Definition: thread.h:304
bool _CORE_message_queue_Initialize(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Attributes *the_message_queue_attributes, uint32_t maximum_pending_messages, size_t maximum_message_size)
Initialize a message queue.
Definition: coremsg.c:45
Constants and Structures Associated with the Message Queue Handler.
Control block used to manage each message queue.
Definition: coremsg.h:140
RTEMS_INLINE_ROUTINE void _CORE_message_queue_Copy_buffer(const void *source, void *destination, size_t size)
This routine copies the contents of the source message buffer to the destination message buffer...
Definition: coremsgimpl.h:436
Thread_Wait_information_Object_argument_type return_argument_second
This field is for a pointer to a second user return argument.
Definition: thread.h:309
This value indicates that blocking tasks are in priority order.
Definition: coremsg.h:109
void _CORE_message_queue_Seize(CORE_message_queue_Control *the_message_queue, Thread_Control *executing, Objects_Id id, void *buffer, size_t *size_p, bool wait, Watchdog_Interval timeout, ISR_lock_Context *lock_context)
Size a message from the message queue.
Definition: coremsgseize.c:29
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
RTEMS_INLINE_ROUTINE Thread_Control * _Thread_queue_First_locked(Thread_queue_Control *the_thread_queue)
Returns the first thread on the thread queue if it exists, otherwise NULL.
Definition: threadqimpl.h:293
uint32_t Objects_Id
The following type defines the control block used to manage object IDs.
Definition: object.h:122
void _CORE_message_queue_Insert_message(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Buffer_control *the_message, CORE_message_queue_Submit_types submit_type)
Insert a message into the message queue.
Definition: coremsginsert.c:40
Thread_Wait_information Wait
This field is the blocking information for this thread.
Definition: thread.h:715
void(* Thread_queue_Flush_callout)(Thread_Control *)
The following type defines the callout used when a remote task is extracted from a local thread queue...
Definition: threadqimpl.h:65
Thread_queue_Control Wait_queue
This field is the Waiting Queue used to manage the set of tasks which are blocked waiting to receive ...
Definition: coremsg.h:144
RTEMS_INLINE_ROUTINE CORE_message_queue_Buffer_control * _CORE_message_queue_Allocate_message_buffer(CORE_message_queue_Control *the_message_queue)
This function allocates a message buffer from the inactive message buffer chain.
Definition: coremsgimpl.h:450