source: rtems/cpukit/score/src/coremsgseize.c @ 97312fcc

5
Last change on this file since 97312fcc was 97312fcc, checked in by Sebastian Huber <sebastian.huber@…>, on 04/05/16 at 12:36:30

score: Delete Thread_Wait_information::id

This field was only by the monitor in non-multiprocessing
configurations. Add new field Thread_Wait_information::remote_id in
multiprocessing configurations and use it for the remote procedure call
thread queue.

Add _Thread_Wait_get_id() to obtain the object identifier for debug and
system information tools. Ensure the object layout via static asserts.
Add test cases to sptests/spthreadq01.

  • Property mode set to 100644
File size: 4.3 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/statesimpl.h>
27#include <rtems/score/wkspace.h>
28
29void _CORE_message_queue_Seize(
30  CORE_message_queue_Control      *the_message_queue,
31  Thread_Control                  *executing,
32  Objects_Id                       id,
33  void                            *buffer,
34  size_t                          *size_p,
35  bool                             wait,
36  Watchdog_Interval                timeout,
37  ISR_lock_Context                *lock_context
38)
39{
40  CORE_message_queue_Buffer_control *the_message;
41
42  executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
43  _CORE_message_queue_Acquire_critical( the_message_queue, lock_context );
44  the_message = _CORE_message_queue_Get_pending_message( the_message_queue );
45  if ( the_message != NULL ) {
46    the_message_queue->number_of_pending_messages -= 1;
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      _CORE_message_queue_Release( the_message_queue, lock_context );
64      return;
65    #else
66    {
67      Thread_Control   *the_thread;
68
69      /*
70       *  There could be a thread waiting to send a message.  If there
71       *  is not, then we can go ahead and free the buffer.
72       *
73       *  NOTE: If we note that the queue was not full before this receive,
74       *  then we can avoid this dequeue.
75       */
76      the_thread = _Thread_queue_First_locked(
77        &the_message_queue->Wait_queue,
78        the_message_queue->operations
79      );
80      if ( the_thread == NULL ) {
81        _CORE_message_queue_Free_message_buffer(
82          the_message_queue,
83          the_message
84        );
85        _CORE_message_queue_Release( the_message_queue, lock_context );
86        return;
87      }
88
89      /*
90       *  There was a thread waiting to send a message.  This code
91       *  puts the messages in the message queue on behalf of the
92       *  waiting task.
93       */
94      _CORE_message_queue_Set_message_priority(
95        the_message,
96        the_thread->Wait.count
97      );
98      the_message->Contents.size = (size_t) the_thread->Wait.option;
99      _CORE_message_queue_Copy_buffer(
100        the_thread->Wait.return_argument_second.immutable_object,
101        the_message->Contents.buffer,
102        the_message->Contents.size
103      );
104
105      _CORE_message_queue_Insert_message(
106         the_message_queue,
107         the_message,
108         _CORE_message_queue_Get_message_priority( the_message )
109      );
110      _Thread_queue_Extract_critical(
111        &the_message_queue->Wait_queue.Queue,
112        the_message_queue->operations,
113        the_thread,
114        lock_context
115      );
116      #if defined(RTEMS_MULTIPROCESSING)
117        _Thread_Dispatch_enable( _Per_CPU_Get() );
118      #endif
119      return;
120    }
121    #endif
122  }
123
124  if ( !wait ) {
125    _CORE_message_queue_Release( the_message_queue, lock_context );
126    executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT;
127    return;
128  }
129
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
134  _Thread_queue_Enqueue_critical(
135    &the_message_queue->Wait_queue.Queue,
136    the_message_queue->operations,
137    executing,
138    STATES_WAITING_FOR_MESSAGE,
139    timeout,
140    CORE_MESSAGE_QUEUE_STATUS_TIMEOUT,
141    lock_context
142  );
143  #if defined(RTEMS_MULTIPROCESSING)
144    _Thread_Dispatch_enable( _Per_CPU_Get() );
145  #endif
146}
Note: See TracBrowser for help on using the repository browser.