RTEMS  5.0.0
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/status.h>
24 #include <rtems/score/chainimpl.h>
25 #include <rtems/score/threaddispatch.h>
27 
28 #include <limits.h>
29 #include <string.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
46 #define CORE_MESSAGE_QUEUE_SEND_REQUEST INT_MAX
47 
54 #define CORE_MESSAGE_QUEUE_URGENT_REQUEST INT_MIN
55 
67 
90  CORE_message_queue_Control *the_message_queue,
92  uint32_t maximum_pending_messages,
93  size_t maximum_message_size
94 );
95 
111  CORE_message_queue_Control *the_message_queue,
112  Thread_queue_Context *queue_context
113 );
114 
131  CORE_message_queue_Control *the_message_queue,
132  Thread_queue_Context *queue_context
133 );
134 
135 #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
136 
147  void _CORE_message_queue_Flush_waiting_threads(
148  CORE_message_queue_Control *the_message_queue
149  );
150 #endif
151 
172 Status_Control _CORE_message_queue_Broadcast(
173  CORE_message_queue_Control *the_message_queue,
174  const void *buffer,
175  size_t size,
176  uint32_t *count,
177  Thread_queue_Context *queue_context
178 );
179 
201 Status_Control _CORE_message_queue_Submit(
202  CORE_message_queue_Control *the_message_queue,
203  Thread_Control *executing,
204  const void *buffer,
205  size_t size,
206  CORE_message_queue_Submit_types submit_type,
207  bool wait,
208  Thread_queue_Context *queue_context
209 );
210 
243 Status_Control _CORE_message_queue_Seize(
244  CORE_message_queue_Control *the_message_queue,
245  Thread_Control *executing,
246  void *buffer,
247  size_t *size_p,
248  bool wait,
249  Thread_queue_Context *queue_context
250 );
251 
266  CORE_message_queue_Control *the_message_queue,
268  const void *content_source,
269  size_t content_size,
270  CORE_message_queue_Submit_types submit_type
271 );
272 
273 RTEMS_INLINE_ROUTINE Status_Control _CORE_message_queue_Send(
274  CORE_message_queue_Control *the_message_queue,
275  const void *buffer,
276  size_t size,
277  bool wait,
278  Thread_queue_Context *queue_context
279 )
280 {
282  the_message_queue,
283  _Thread_Executing,
284  buffer,
285  size,
287  wait,
288  queue_context
289  );
290 }
291 
292 RTEMS_INLINE_ROUTINE Status_Control _CORE_message_queue_Urgent(
293  CORE_message_queue_Control *the_message_queue,
294  const void *buffer,
295  size_t size,
296  bool wait,
297  Thread_queue_Context *queue_context
298 )
299 {
301  the_message_queue,
302  _Thread_Executing,
303  buffer,
304  size,
306  wait,
307  queue_context
308  );
309 }
310 
311 RTEMS_INLINE_ROUTINE void _CORE_message_queue_Acquire(
312  CORE_message_queue_Control *the_message_queue,
313  Thread_queue_Context *queue_context
314 )
315 {
316  _Thread_queue_Acquire( &the_message_queue->Wait_queue, queue_context );
317 }
318 
319 RTEMS_INLINE_ROUTINE void _CORE_message_queue_Acquire_critical(
320  CORE_message_queue_Control *the_message_queue,
321  Thread_queue_Context *queue_context
322 )
323 {
324  _Thread_queue_Acquire_critical( &the_message_queue->Wait_queue, queue_context );
325 }
326 
327 RTEMS_INLINE_ROUTINE void _CORE_message_queue_Release(
328  CORE_message_queue_Control *the_message_queue,
329  Thread_queue_Context *queue_context
330 )
331 {
332  _Thread_queue_Release( &the_message_queue->Wait_queue, queue_context );
333 }
334 
340  const void *source,
341  void *destination,
342  size_t size
343 )
344 {
345  memcpy(destination, source, size);
346 }
347 
354  CORE_message_queue_Control *the_message_queue
355 )
356 {
358  _Chain_Get_unprotected( &the_message_queue->Inactive_messages );
359 }
360 
366  CORE_message_queue_Control *the_message_queue,
368 )
369 {
370  _Chain_Append_unprotected( &the_message_queue->Inactive_messages, &the_message->Node );
371 }
372 
380  const CORE_message_queue_Buffer_control *the_message
381 )
382 {
383  #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
384  return the_message->priority;
385  #else
386  return 0;
387  #endif
388 }
389 
396  CORE_message_queue_Control *the_message_queue
397 )
398 {
400  _Chain_Get_unprotected( &the_message_queue->Pending_messages );
401 }
402 
403 #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
404 
408  RTEMS_INLINE_ROUTINE bool _CORE_message_queue_Is_notify_enabled (
409  CORE_message_queue_Control *the_message_queue
410  )
411  {
412  return (the_message_queue->notify_handler != NULL);
413  }
414 #endif
415 
420 #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
422  CORE_message_queue_Control *the_message_queue,
423  CORE_message_queue_Notify_Handler the_handler
424  )
425  {
426  the_message_queue->notify_handler = the_handler;
427  }
428 #else
429  /* turn it into nothing if not enabled */
430  #define _CORE_message_queue_Set_notify( the_message_queue, the_handler ) \
431  do { } while ( 0 )
432 #endif
433 
434 RTEMS_INLINE_ROUTINE Thread_Control *_CORE_message_queue_Dequeue_receiver(
435  CORE_message_queue_Control *the_message_queue,
436  const void *buffer,
437  size_t size,
438  CORE_message_queue_Submit_types submit_type,
439  Thread_queue_Context *queue_context
440 )
441 {
442  Thread_Control *the_thread;
443 
444  /*
445  * If there are pending messages, then there can't be threads
446  * waiting for us to send them a message.
447  *
448  * NOTE: This check is critical because threads can block on
449  * send and receive and this ensures that we are broadcasting
450  * the message to threads waiting to receive -- not to send.
451  */
452  if ( the_message_queue->number_of_pending_messages != 0 ) {
453  return NULL;
454  }
455 
456  /*
457  * There must be no pending messages if there is a thread waiting to
458  * receive a message.
459  */
460  the_thread = _Thread_queue_First_locked(
461  &the_message_queue->Wait_queue,
462  the_message_queue->operations
463  );
464  if ( the_thread == NULL ) {
465  return NULL;
466  }
467 
468  *(size_t *) the_thread->Wait.return_argument = size;
469  the_thread->Wait.count = (uint32_t) submit_type;
470 
472  buffer,
473  the_thread->Wait.return_argument_second.mutable_object,
474  size
475  );
476 
478  &the_message_queue->Wait_queue.Queue,
479  the_message_queue->operations,
480  the_thread,
481  queue_context
482  );
483 
484  return the_thread;
485 }
486 
489 #ifdef __cplusplus
490 }
491 #endif
492 
493 #endif
494 /* end of include file */
RTEMS_INLINE_ROUTINE void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Append a node (unprotected).
Definition: chainimpl.h:679
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)
Submit a message to the message queue.
Definition: coremsgsubmit.c:29
void _CORE_message_queue_Close(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Close a message queue.
Definition: coremsgclose.c:35
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:971
Thread_Wait_information Wait
Definition: thread.h:770
Thread queue context for the thread queue methods.
Definition: threadq.h:193
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)
Size a message from the message queue.
Definition: coremsgseize.c:27
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)
Broadcast a message to the message queue.
Definition: coremsgbroadcast.c:24
Chain_Control Inactive_messages
Definition: coremsg.h:171
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
void * return_argument
Definition: thread.h:405
Chain_Node Node
Definition: coremsg.h:89
int CORE_message_queue_Submit_types
The modes in which a message may be submitted to a message queue.
Definition: coremsgimpl.h:66
The organization of a message buffer.
Definition: coremsg.h:87
int priority
Definition: coremsg.h:92
const Thread_queue_Operations * operations
The thread queue operations according to the blocking discipline.
Definition: coremsg.h:140
uint32_t number_of_pending_messages
Definition: coremsg.h:148
RTEMS_INLINE_ROUTINE void _CORE_message_queue_Free_message_buffer(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Buffer_control *the_message)
Definition: coremsgimpl.h:365
RTEMS_INLINE_ROUTINE int _CORE_message_queue_Get_message_priority(const CORE_message_queue_Buffer_control *the_message)
Definition: coremsgimpl.h:379
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:578
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)
Insert a message into the message queue.
Definition: coremsginsert.c:40
Definition: thread.h:728
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_Get_unprotected(Chain_Control *the_chain)
Get the first node (unprotected).
Definition: chainimpl.h:629
RTEMS_INLINE_ROUTINE CORE_message_queue_Buffer_control * _CORE_message_queue_Get_pending_message(CORE_message_queue_Control *the_message_queue)
Definition: coremsgimpl.h:395
#define CORE_MESSAGE_QUEUE_URGENT_REQUEST
Used when prepending messages onto a message queue.
Definition: coremsgimpl.h:54
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:599
Chain_Control Pending_messages
Definition: coremsg.h:156
#define CORE_MESSAGE_QUEUE_SEND_REQUEST
Used when appending messages onto a message queue.
Definition: coremsgimpl.h:46
Chain Handler API.
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)
Initialize a message queue.
Definition: coremsg.c:45
uint32_t count
Definition: thread.h:403
Constants and Structures Associated with the Message Queue Handler.
Control block used to manage each message queue.
Definition: coremsg.h:131
RTEMS_INLINE_ROUTINE void _CORE_message_queue_Copy_buffer(const void *source, void *destination, size_t size)
Definition: coremsgimpl.h:339
Thread_Wait_information_Object_argument_type return_argument_second
Definition: thread.h:408
CORE_message_queue_Disciplines
The possible blocking disciplines for a message queue.
Definition: coremsg.h:104
uint32_t _CORE_message_queue_Flush(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Flush pending messages.
Definition: coremsgflush.c:24
unsigned size
Definition: tte.h:74
Thread_queue_Control Wait_queue
Definition: coremsg.h:135
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
#define _CORE_message_queue_Set_notify(the_message_queue, the_handler)
Definition: coremsgimpl.h:430
RTEMS_INLINE_ROUTINE CORE_message_queue_Buffer_control * _CORE_message_queue_Allocate_message_buffer(CORE_message_queue_Control *the_message_queue)
Definition: coremsgimpl.h:353