RTEMS 6.1-rc7
Loading...
Searching...
No Matches
coremsgimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
13/*
14 * COPYRIGHT (c) 1989-2009.
15 * On-Line Applications Research Corporation (OAR).
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifndef _RTEMS_SCORE_COREMSGIMPL_H
40#define _RTEMS_SCORE_COREMSGIMPL_H
41
42#include <rtems/score/coremsg.h>
43#include <rtems/score/status.h>
47
48#include <limits.h>
49#include <string.h>
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
67#define CORE_MESSAGE_QUEUE_SEND_REQUEST INT_MAX
68
75#define CORE_MESSAGE_QUEUE_URGENT_REQUEST INT_MIN
76
88
107typedef void *( *CORE_message_queue_Allocate_buffers )(
108 CORE_message_queue_Control *the_message_queue,
109 size_t size,
110 const void *arg
111);
112
132 CORE_message_queue_Control *the_message_queue,
133 size_t size,
134 const void *arg
135);
136
164 CORE_message_queue_Control *the_message_queue,
166 uint32_t maximum_pending_messages,
167 size_t maximum_message_size,
169 const void *arg
170);
171
187 CORE_message_queue_Control *the_message_queue,
188 Thread_queue_Context *queue_context
189);
190
207 CORE_message_queue_Control *the_message_queue,
208 Thread_queue_Context *queue_context
209);
210
211#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
224 void _CORE_message_queue_Flush_waiting_threads(
225 CORE_message_queue_Control *the_message_queue
226 );
227#endif
228
251 CORE_message_queue_Control *the_message_queue,
252 const void *buffer,
253 size_t size,
254 uint32_t *count,
255 Thread_queue_Context *queue_context
256);
257
286 CORE_message_queue_Control *the_message_queue,
287 Thread_Control *executing,
288 const void *buffer,
289 size_t size,
291 bool wait,
292 Thread_queue_Context *queue_context
293);
294
329 CORE_message_queue_Control *the_message_queue,
330 Thread_Control *executing,
331 void *buffer,
332 size_t *size_p,
333 bool wait,
334 Thread_queue_Context *queue_context
335);
336
351 CORE_message_queue_Control *the_message_queue,
352 CORE_message_queue_Buffer *the_message,
353 const void *content_source,
354 size_t content_size,
356);
357
375static inline Status_Control _CORE_message_queue_Send(
376 CORE_message_queue_Control *the_message_queue,
377 const void *buffer,
378 size_t size,
379 bool wait,
380 Thread_queue_Context *queue_context
381)
382{
384 the_message_queue,
385 _Thread_Executing,
386 buffer,
387 size,
389 wait,
390 queue_context
391 );
392}
393
411static inline Status_Control _CORE_message_queue_Urgent(
412 CORE_message_queue_Control *the_message_queue,
413 const void *buffer,
414 size_t size,
415 bool wait,
416 Thread_queue_Context *queue_context
417)
418{
420 the_message_queue,
421 _Thread_Executing,
422 buffer,
423 size,
425 wait,
426 queue_context
427 );
428}
429
436static inline void _CORE_message_queue_Acquire(
437 CORE_message_queue_Control *the_message_queue,
438 Thread_queue_Context *queue_context
439)
440{
441 _Thread_queue_Acquire( &the_message_queue->Wait_queue, queue_context );
442}
443
450static inline void _CORE_message_queue_Acquire_critical(
451 CORE_message_queue_Control *the_message_queue,
452 Thread_queue_Context *queue_context
453)
454{
455 _Thread_queue_Acquire_critical( &the_message_queue->Wait_queue, queue_context );
456}
457
464static inline void _CORE_message_queue_Release(
465 CORE_message_queue_Control *the_message_queue,
466 Thread_queue_Context *queue_context
467)
468{
469 _Thread_queue_Release( &the_message_queue->Wait_queue, queue_context );
470}
471
482static inline void _CORE_message_queue_Copy_buffer (
483 const void *source,
484 void *destination,
485 size_t size
486)
487{
488 memcpy(destination, source, size);
489}
490
502static inline CORE_message_queue_Buffer *
503_CORE_message_queue_Allocate_message_buffer (
504 CORE_message_queue_Control *the_message_queue
505)
506{
508 _Chain_Get_unprotected( &the_message_queue->Inactive_messages );
509}
510
520static inline void _CORE_message_queue_Free_message_buffer (
521 CORE_message_queue_Control *the_message_queue,
522 CORE_message_queue_Buffer *the_message
523)
524{
525 _Chain_Append_unprotected( &the_message_queue->Inactive_messages, &the_message->Node );
526}
527
541static inline int _CORE_message_queue_Get_message_priority (
542 const CORE_message_queue_Buffer *the_message
543)
544{
545 #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
546 return the_message->priority;
547 #else
548 return 0;
549 #endif
550}
551
563static inline
564 CORE_message_queue_Buffer *_CORE_message_queue_Get_pending_message (
565 CORE_message_queue_Control *the_message_queue
566)
567{
569 _Chain_Get_unprotected( &the_message_queue->Pending_messages );
570}
571
572#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
584 static inline bool _CORE_message_queue_Is_notify_enabled (
585 CORE_message_queue_Control *the_message_queue
586 )
587 {
588 return (the_message_queue->notify_handler != NULL);
589 }
590#endif
591
601#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
602 static inline void _CORE_message_queue_Set_notify (
603 CORE_message_queue_Control *the_message_queue,
604 CORE_message_queue_Notify_Handler the_handler
605 )
606 {
607 the_message_queue->notify_handler = the_handler;
608 }
609#else
610 /* turn it into nothing if not enabled */
611 #define _CORE_message_queue_Set_notify( the_message_queue, the_handler ) \
612 do { } while ( 0 )
613#endif
614
630static inline Thread_Control *_CORE_message_queue_Dequeue_receiver(
631 CORE_message_queue_Control *the_message_queue,
632 const void *buffer,
633 size_t size,
635 Thread_queue_Context *queue_context
636)
637{
638 Thread_queue_Heads *heads;
639 Thread_Control *the_thread;
640
641 /*
642 * If there are pending messages, then there can't be threads
643 * waiting for us to send them a message.
644 *
645 * NOTE: This check is critical because threads can block on
646 * send and receive and this ensures that we are broadcasting
647 * the message to threads waiting to receive -- not to send.
648 */
649 if ( the_message_queue->number_of_pending_messages != 0 ) {
650 return NULL;
651 }
652
653 /*
654 * There must be no pending messages if there is a thread waiting to
655 * receive a message.
656 */
657 heads = the_message_queue->Wait_queue.Queue.heads;
658 if ( heads == NULL ) {
659 return NULL;
660 }
661
662 the_thread = ( *the_message_queue->operations->surrender )(
663 &the_message_queue->Wait_queue.Queue,
664 heads,
665 NULL,
666 queue_context
667 );
668
669 *(size_t *) the_thread->Wait.return_argument = size;
670 the_thread->Wait.count = (uint32_t) submit_type;
671
672 _CORE_message_queue_Copy_buffer(
673 buffer,
674 the_thread->Wait.return_argument_second.mutable_object,
675 size
676 );
677
679 &the_message_queue->Wait_queue.Queue,
680 the_thread,
681 queue_context
682 );
683
684 return the_thread;
685}
686
689#ifdef __cplusplus
690}
691#endif
692
693#endif
694/* end of include file */
This header file provides interfaces of the Chain Handler which are only used by the implementation.
This header file provides interfaces of the Message Queue Handler which are only used by the implemen...
#define CORE_MESSAGE_QUEUE_URGENT_REQUEST
Used when prepending messages onto a message queue.
Definition: coremsgimpl.h:75
int CORE_message_queue_Submit_types
The modes in which a message may be submitted to a message queue.
Definition: coremsgimpl.h:87
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:107
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:63
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:48
#define CORE_MESSAGE_QUEUE_SEND_REQUEST
Used when appending messages onto a message queue.
Definition: coremsgimpl.h:67
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:48
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:54
void _CORE_message_queue_Close(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Closes a message queue.
Definition: coremsgclose.c:55
#define _CORE_message_queue_Set_notify(the_message_queue, the_handler)
Initializes notification information.
Definition: coremsgimpl.h:611
CORE_message_queue_Disciplines
The possible blocking disciplines for a message queue.
Definition: coremsg.h:86
uint32_t _CORE_message_queue_Flush(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Flushes pending messages.
Definition: coremsgflush.c:44
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:45
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.
Definition: coremsgwkspace.c:44
Status_Control
Status codes.
Definition: status.h:111
void _Thread_queue_Resume(Thread_queue_Queue *queue, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Resumes the extracted or surrendered thread.
Definition: threadqenqueue.c:663
This header file provides the interfaces of the Operation Status Support.
The structure is used to organize message buffers of a message queue.
Definition: coremsgbuffer.h:64
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:69
int priority
This member defines the priority of this message.
Definition: coremsgbuffer.h:76
Control block used to manage each message queue.
Definition: coremsg.h:113
Chain_Control Inactive_messages
Definition: coremsg.h:163
const Thread_queue_Operations * operations
The thread queue operations according to the blocking discipline.
Definition: coremsg.h:122
uint32_t number_of_pending_messages
Definition: coremsg.h:130
Thread_queue_Control Wait_queue
Definition: coremsg.h:117
Chain_Control Pending_messages
Definition: coremsg.h:138
uint32_t count
Definition: thread.h:468
Thread_Wait_information_Object_argument_type return_argument_second
Definition: thread.h:473
void * return_argument
Definition: thread.h:470
Thread queue context for the thread queue methods.
Definition: threadq.h:216
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:640
Thread_queue_Surrender_operation surrender
This operation is used to dequeue the thread from the thread queue and optionally surrender the threa...
Definition: threadq.h:593
Thread_queue_Heads * heads
The thread queue heads.
Definition: threadq.h:451
Definition: thread.h:837
Thread_Wait_information Wait
Definition: thread.h:877
Thread queue heads.
Definition: threadq.h:385
This header file provides the interfaces of the Thread Handler related to thread dispatching.
This header file provides interfaces of the Thread Queue Handler which are only used by the implement...