source: rtems/cpukit/score/src/coremsgseize.c @ 62181b21

4.115
Last change on this file since 62181b21 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  CORE Message Queue Handler
3 *
4 *  DESCRIPTION:
5 *
6 *  This package is the implementation of the CORE Message Queue Handler.
7 *  This core object provides task synchronization and communication functions
8 *  via messages passed to queue objects.
9 *
10 *  COPYRIGHT (c) 1989-2007.
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.com/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/system.h>
23#include <rtems/score/chain.h>
24#include <rtems/score/isr.h>
25#include <rtems/score/object.h>
26#include <rtems/score/coremsg.h>
27#include <rtems/score/states.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/wkspace.h>
30
31/*
32 *  _CORE_message_queue_Seize
33 *
34 *  This kernel routine dequeues a message, copies the message buffer to
35 *  a given destination buffer, and frees the message buffer to the
36 *  inactive message pool.  The thread will be blocked if wait is true,
37 *  otherwise an error will be given to the thread if no messages are available.
38 *
39 *  Input parameters:
40 *    the_message_queue - pointer to message queue
41 *    id                - id of object we are waitig on
42 *    buffer            - pointer to message buffer to be filled
43 *    size_p            - pointer to the size of buffer to be filled
44 *    wait              - true if wait is allowed, false otherwise
45 *    timeout           - time to wait for a message
46 *
47 *  Output parameters:  NONE
48 *
49 *  NOTE: Dependent on BUFFER_LENGTH
50 *
51 *  INTERRUPT LATENCY:
52 *    available
53 *    wait
54 */
55
56void _CORE_message_queue_Seize(
57  CORE_message_queue_Control      *the_message_queue,
58  Objects_Id                       id,
59  void                            *buffer,
60  size_t                          *size_p,
61  bool                             wait,
62  Watchdog_Interval                timeout
63)
64{
65  ISR_Level                          level;
66  CORE_message_queue_Buffer_control *the_message;
67  Thread_Control                    *executing;
68
69  executing = _Thread_Executing;
70  executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
71  _ISR_Disable( level );
72  the_message = _CORE_message_queue_Get_pending_message( the_message_queue );
73  if ( the_message != NULL ) {
74    the_message_queue->number_of_pending_messages -= 1;
75    _ISR_Enable( level );
76
77    *size_p = the_message->Contents.size;
78    _Thread_Executing->Wait.count =
79      _CORE_message_queue_Get_message_priority( the_message );
80    _CORE_message_queue_Copy_buffer(
81      the_message->Contents.buffer,
82      buffer,
83      *size_p
84    );
85
86    #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND)
87      /*
88       *  There is not an API with blocking sends enabled.
89       *  So return immediately.
90       */
91      _CORE_message_queue_Free_message_buffer(the_message_queue, the_message);
92      return;
93    #else
94    {
95      Thread_Control   *the_thread;
96
97      /*
98       *  There could be a thread waiting to send a message.  If there
99       *  is not, then we can go ahead and free the buffer.
100       *
101       *  NOTE: If we note that the queue was not full before this receive,
102       *  then we can avoid this dequeue.
103       */
104      the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
105      if ( !the_thread ) {
106        _CORE_message_queue_Free_message_buffer(
107          the_message_queue,
108          the_message
109        );
110        return;
111      }
112
113      /*
114       *  There was a thread waiting to send a message.  This code
115       *  puts the messages in the message queue on behalf of the
116       *  waiting task.
117       */
118      _CORE_message_queue_Set_message_priority(
119        the_message,
120        the_thread->Wait.count
121      );
122      the_message->Contents.size = (size_t) the_thread->Wait.option;
123      _CORE_message_queue_Copy_buffer(
124        the_thread->Wait.return_argument_second.immutable_object,
125        the_message->Contents.buffer,
126        the_message->Contents.size
127      );
128
129      _CORE_message_queue_Insert_message(
130         the_message_queue,
131         the_message,
132         _CORE_message_queue_Get_message_priority( the_message )
133      );
134      return;
135    }
136    #endif
137  }
138
139  if ( !wait ) {
140    _ISR_Enable( level );
141    executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT;
142    return;
143  }
144
145  _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
146  executing->Wait.queue = &the_message_queue->Wait_queue;
147  executing->Wait.id = id;
148  executing->Wait.return_argument_second.mutable_object = buffer;
149  executing->Wait.return_argument = size_p;
150  /* Wait.count will be filled in with the message priority */
151  _ISR_Enable( level );
152
153  _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
154}
Note: See TracBrowser for help on using the repository browser.