source: rtems/cpukit/score/src/coremsgseize.c @ f5d6c8b

4.115
Last change on this file since f5d6c8b was f5d6c8b, checked in by Sebastian Huber <sebastian.huber@…>, on 04/27/15 at 14:25:52

score: Delete Thread_queue_Control::timeout_status

Use a parameter for _Thread_queue_Enqueue() instead to reduce memory
usage.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Size a Message from the Message Queue
5 *  @ingroup ScoreMessageQueue
6 */
7
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#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/score/chain.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/coremsgimpl.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/statesimpl.h>
27#include <rtems/score/wkspace.h>
28
29void _CORE_message_queue_Seize(
30  CORE_message_queue_Control      *the_message_queue,
31  Thread_Control                  *executing,
32  Objects_Id                       id,
33  void                            *buffer,
34  size_t                          *size_p,
35  bool                             wait,
36  Watchdog_Interval                timeout
37)
38{
39  ISR_lock_Context                   lock_context;
40  CORE_message_queue_Buffer_control *the_message;
41
42  executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
43  _Thread_queue_Acquire( &the_message_queue->Wait_queue, &lock_context );
44  the_message = _CORE_message_queue_Get_pending_message( the_message_queue );
45  if ( the_message != NULL ) {
46    the_message_queue->number_of_pending_messages -= 1;
47    _Thread_queue_Release( &the_message_queue->Wait_queue, &lock_context );
48
49    *size_p = the_message->Contents.size;
50    executing->Wait.count =
51      _CORE_message_queue_Get_message_priority( the_message );
52    _CORE_message_queue_Copy_buffer(
53      the_message->Contents.buffer,
54      buffer,
55      *size_p
56    );
57
58    #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND)
59      /*
60       *  There is not an API with blocking sends enabled.
61       *  So return immediately.
62       */
63      _CORE_message_queue_Free_message_buffer(the_message_queue, the_message);
64      return;
65    #else
66    {
67      Thread_Control   *the_thread;
68
69      /*
70       *  There could be a thread waiting to send a message.  If there
71       *  is not, then we can go ahead and free the buffer.
72       *
73       *  NOTE: If we note that the queue was not full before this receive,
74       *  then we can avoid this dequeue.
75       */
76      the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
77      if ( !the_thread ) {
78        _CORE_message_queue_Free_message_buffer(
79          the_message_queue,
80          the_message
81        );
82        return;
83      }
84
85      /*
86       *  There was a thread waiting to send a message.  This code
87       *  puts the messages in the message queue on behalf of the
88       *  waiting task.
89       */
90      _CORE_message_queue_Set_message_priority(
91        the_message,
92        the_thread->Wait.count
93      );
94      the_message->Contents.size = (size_t) the_thread->Wait.option;
95      _CORE_message_queue_Copy_buffer(
96        the_thread->Wait.return_argument_second.immutable_object,
97        the_message->Contents.buffer,
98        the_message->Contents.size
99      );
100
101      _CORE_message_queue_Insert_message(
102         the_message_queue,
103         the_message,
104         _CORE_message_queue_Get_message_priority( the_message )
105      );
106      return;
107    }
108    #endif
109  }
110
111  if ( !wait ) {
112    _Thread_queue_Release( &the_message_queue->Wait_queue, &lock_context );
113    executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT;
114    return;
115  }
116
117  executing->Wait.id = id;
118  executing->Wait.return_argument_second.mutable_object = buffer;
119  executing->Wait.return_argument = size_p;
120  /* Wait.count will be filled in with the message priority */
121
122  _Thread_queue_Enqueue_critical(
123    &the_message_queue->Wait_queue,
124    executing,
125    STATES_WAITING_FOR_MESSAGE,
126    timeout,
127    CORE_MESSAGE_QUEUE_STATUS_TIMEOUT,
128    &lock_context
129  );
130}
Note: See TracBrowser for help on using the repository browser.