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

4.115
Last change on this file since e655f7e was e655f7e, checked in by Alex Ivanov <alexivanov97@…>, on 11/29/12 at 18:39:19

score misc: Score misc: Clean up Doxygen #5

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