RTEMS
coremsgseize.c
Go to the documentation of this file.
1 
8 /*
9  * COPYRIGHT (c) 1989-2007.
10  * On-Line Applications Research Corporation (OAR).
11  *
12  * The license and distribution terms for this file may be
13  * found in the file LICENSE in this distribution or at
14  * http://www.rtems.org/license/LICENSE.
15  */
16 
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <rtems/score/chain.h>
22 #include <rtems/score/isr.h>
24 #include <rtems/score/threadimpl.h>
25 #include <rtems/score/statesimpl.h>
26 
28  CORE_message_queue_Control *the_message_queue,
29  Thread_Control *executing,
30  void *buffer,
31  size_t *size_p,
32  bool wait,
33  Thread_queue_Context *queue_context
34 )
35 {
36  CORE_message_queue_Buffer *the_message;
37 
38  the_message = _CORE_message_queue_Get_pending_message( the_message_queue );
39  if ( the_message != NULL ) {
40  the_message_queue->number_of_pending_messages -= 1;
41 
42  *size_p = the_message->size;
43  executing->Wait.count =
45  _CORE_message_queue_Copy_buffer( the_message->buffer, buffer, *size_p );
46 
47  #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND)
48  /*
49  * There is not an API with blocking sends enabled.
50  * So return immediately.
51  */
52  _CORE_message_queue_Free_message_buffer(the_message_queue, the_message);
53  _CORE_message_queue_Release( the_message_queue, queue_context );
54  return STATUS_SUCCESSFUL;
55  #else
56  {
57  Thread_Control *the_thread;
58 
59  /*
60  * There could be a thread waiting to send a message. If there
61  * is not, then we can go ahead and free the buffer.
62  *
63  * NOTE: If we note that the queue was not full before this receive,
64  * then we can avoid this dequeue.
65  */
66  the_thread = _Thread_queue_First_locked(
67  &the_message_queue->Wait_queue,
68  the_message_queue->operations
69  );
70  if ( the_thread == NULL ) {
72  the_message_queue,
73  the_message
74  );
75  _CORE_message_queue_Release( the_message_queue, queue_context );
76  return STATUS_SUCCESSFUL;
77  }
78 
79  /*
80  * There was a thread waiting to send a message. This code
81  * puts the messages in the message queue on behalf of the
82  * waiting task.
83  */
85  the_message_queue,
86  the_message,
87  the_thread->Wait.return_argument_second.immutable_object,
88  (size_t) the_thread->Wait.option,
90  );
92  &the_message_queue->Wait_queue.Queue,
93  the_message_queue->operations,
94  the_thread,
95  queue_context
96  );
97  return STATUS_SUCCESSFUL;
98  }
99  #endif
100  }
101 
102  if ( !wait ) {
103  _CORE_message_queue_Release( the_message_queue, queue_context );
104  return STATUS_UNSATISFIED;
105  }
106 
107  executing->Wait.return_argument_second.mutable_object = buffer;
108  executing->Wait.return_argument = size_p;
109  /* Wait.count will be filled in with the message priority */
110 
112  queue_context,
114  );
116  &the_message_queue->Wait_queue.Queue,
117  the_message_queue->operations,
118  executing,
119  queue_context
120  );
121  return _Thread_Wait_get_status( executing );
122 }
static __inline__ CORE_message_queue_Buffer * _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:546
static __inline__ 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: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.
static __inline__ void _CORE_message_queue_Free_message_buffer(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Buffer *the_message)
Frees a message buffer to inactive message buffer chain.
Definition: coremsgimpl.h:502
static __inline__ 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:464
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
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
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
size_t size
This member defines the size of this message.
Definition: coremsgbuffer.h:71
size_t buffer[RTEMS_ZERO_LENGTH_ARRAY]
This member contains the actual message.
Definition: coremsgbuffer.h:87
static __inline__ int _CORE_message_queue_Get_message_priority(const CORE_message_queue_Buffer *the_message)
Gets message priority.
Definition: coremsgimpl.h:523
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
Chain Handler API.
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
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
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.
Thread_queue_Control Wait_queue
Definition: coremsg.h:100