source: rtems/cpukit/score/src/coremsgseize.c @ 439c494

4.115
Last change on this file since 439c494 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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