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

4.104.115
Last change on this file since b094233 was aae7f1a1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/22/08 at 05:52:32

Eliminate TRUE/FALSE.

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