source: rtems/cpukit/score/src/coremsgseize.c @ 507d382

4.104.115
Last change on this file since 507d382 was 507d382, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 11, 2009 at 8:00:30 PM

2009-09-11 Joel Sherrill <joel.sherrill@…>

  • score/include/rtems/score/coremsg.h, score/inline/rtems/score/coremsg.inl, score/src/coremsg.c, score/src/coremsginsert.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c, score/src/objectnametoidstring.c: Disable the Core Message Queue features of notification, priority messages, and blocking sends when no API requires them.
  • Property mode set to 100644
File size: 4.8 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
72  executing = _Thread_Executing;
73  executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
74  _ISR_Disable( level );
75  the_message = _CORE_message_queue_Get_pending_message( the_message_queue );
76  if ( the_message != NULL ) {
77    the_message_queue->number_of_pending_messages -= 1;
78    _ISR_Enable( level );
79
80    *size_p = the_message->Contents.size;
81    #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
82      _Thread_Executing->Wait.count = the_message->priority;
83    #endif
84    _CORE_message_queue_Copy_buffer(the_message->Contents.buffer,buffer,*size_p);
85
86    #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND)
87      /*
88       *  There is not an API with blocking sends enabled.  So return immediately.
89       */
90      _CORE_message_queue_Free_message_buffer( the_message_queue, the_message );
91      return;
92    #else
93    {
94      Thread_Control   *the_thread;
95
96      /*
97       *  There could be a thread waiting to send a message.  If there
98       *  is not, then we can go ahead and free the buffer.
99       *
100       *  NOTE: If we note that the queue was not full before this receive,
101       *  then we can avoid this dequeue.
102       */
103      the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
104      if ( !the_thread ) {
105        _CORE_message_queue_Free_message_buffer( the_message_queue, the_message );
106        return;
107      }
108
109      /*
110       *  There was a thread waiting to send a message.  This code
111       *  puts the messages in the message queue on behalf of the
112       *  waiting task.
113       */
114      #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
115        the_message->priority  = the_thread->Wait.count;
116      #endif
117      the_message->Contents.size = (size_t) the_thread->Wait.option;
118      _CORE_message_queue_Copy_buffer(
119        the_thread->Wait.return_argument_second.immutable_object,
120        the_message->Contents.buffer,
121        the_message->Contents.size
122      );
123
124      _CORE_message_queue_Insert_message(
125         the_message_queue,
126         the_message,
127         #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
128           the_message->priority,
129         #else
130           0
131         #endif
132      );
133      return;
134    }
135    #endif
136  }
137
138  if ( !wait ) {
139    _ISR_Enable( level );
140    executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT;
141    return;
142  }
143
144  _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
145  executing->Wait.queue = &the_message_queue->Wait_queue;
146  executing->Wait.id = id;
147  executing->Wait.return_argument_second.mutable_object = buffer;
148  executing->Wait.return_argument = size_p;
149  /* Wait.count will be filled in with the message priority */
150  _ISR_Enable( level );
151
152  _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
153}
Note: See TracBrowser for help on using the repository browser.