RTEMS
coremsgsubmit.c
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 1989-2009.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  */
17 
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
23 #include <rtems/score/objectimpl.h>
24 #include <rtems/score/isr.h>
25 #include <rtems/score/threadimpl.h>
26 #include <rtems/score/statesimpl.h>
27 #include <rtems/score/wkspace.h>
28 
30  CORE_message_queue_Control *the_message_queue,
31  Thread_Control *executing,
32  const void *buffer,
33  size_t size,
35  bool wait,
36  Thread_queue_Context *queue_context
37 )
38 {
39  CORE_message_queue_Buffer *the_message;
40  Thread_Control *the_thread;
41 
42  if ( size > the_message_queue->maximum_message_size ) {
43  _CORE_message_queue_Release( the_message_queue, queue_context );
44  return STATUS_MESSAGE_INVALID_SIZE;
45  }
46 
47  /*
48  * Is there a thread currently waiting on this message queue?
49  */
50 
52  the_message_queue,
53  buffer,
54  size,
55  submit_type,
56  queue_context
57  );
58  if ( the_thread != NULL ) {
59  return STATUS_SUCCESSFUL;
60  }
61 
62  /*
63  * No one waiting on the message queue at this time, so attempt to
64  * queue the message up for a future receive.
65  */
66  the_message =
68  if ( the_message ) {
70  the_message_queue,
71  the_message,
72  buffer,
73  size,
74  submit_type
75  );
76 
77 #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
78  /*
79  * According to POSIX, does this happen before or after the message
80  * is actually enqueued. It is logical to think afterwards, because
81  * the message is actually in the queue at this point.
82  */
83  if (
84  the_message_queue->number_of_pending_messages == 1
85  && the_message_queue->notify_handler != NULL
86  ) {
87  ( *the_message_queue->notify_handler )(
88  the_message_queue,
89  queue_context
90  );
91  } else {
92  _CORE_message_queue_Release( the_message_queue, queue_context );
93  }
94 #else
95  _CORE_message_queue_Release( the_message_queue, queue_context );
96 #endif
97 
98  return STATUS_SUCCESSFUL;
99  }
100 
101  #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND)
102  _CORE_message_queue_Release( the_message_queue, queue_context );
103  return STATUS_TOO_MANY;
104  #else
105  /*
106  * No message buffers were available so we may need to return an
107  * overflow error or block the sender until the message is placed
108  * on the queue.
109  */
110  if ( !wait ) {
111  _CORE_message_queue_Release( the_message_queue, queue_context );
112  return STATUS_TOO_MANY;
113  }
114 
115  /*
116  * Do NOT block on a send if the caller is in an ISR. It is
117  * deadly to block in an ISR.
118  */
119  if ( _ISR_Is_in_progress() ) {
120  _CORE_message_queue_Release( the_message_queue, queue_context );
121  return STATUS_MESSAGE_QUEUE_WAIT_IN_ISR;
122  }
123 
124  /*
125  * WARNING!! executing should NOT be used prior to this point.
126  * Thus the unusual choice to open a new scope and declare
127  * it as a variable. Doing this emphasizes how dangerous it
128  * would be to use this variable prior to here.
129  */
130  executing->Wait.return_argument_second.immutable_object = buffer;
131  executing->Wait.option = (uint32_t) size;
132  executing->Wait.count = submit_type;
133 
135  queue_context,
137  );
139  &the_message_queue->Wait_queue.Queue,
140  the_message_queue->operations,
141  executing,
142  queue_context
143  );
144  return _Thread_Wait_get_status( executing );
145  #endif
146 }
bool _ISR_Is_in_progress(void)
Checks if an ISR in progress.
Thread_Wait_information Wait
Definition: thread.h:767
Thread queue context for the thread queue methods.
Definition: threadq.h:198
Inlined Routines in the Core Message Handler.
int CORE_message_queue_Submit_types
The modes in which a message may be submitted to a message queue.
Definition: coremsgimpl.h:69
Data Related to the Management of Processor Interrupt Levels.
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 _Thread_queue_Context_set_thread_state(Thread_queue_Context *queue_context, States_Control thread_state)
Sets the thread state for the thread to enqueue in the thread queue context.
Definition: threadqimpl.h:178
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
Inlined Routines in the Object Handler.
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
The structure is used to organize message buffers of a message queue.
Definition: coremsgbuffer.h:63
Inlined Routines Associated with Thread State Information.
#define STATES_WAITING_FOR_MESSAGE
Definition: statesimpl.h:60
Control block used to manage each message queue.
Definition: coremsg.h:96
Inlined Routines from the Thread Handler.
static __inline__ Status_Control _Thread_Wait_get_status(const Thread_Control *the_thread)
Get the status of the wait return code of the thread.
Definition: threadimpl.h:2354
Thread_Wait_information_Object_argument_type return_argument_second
Definition: thread.h:405
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_Enqueue(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Blocks the thread and places it on the thread queue.
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
Information Related to the RAM Workspace.
Thread_queue_Control Wait_queue
Definition: coremsg.h:100