source: rtems/cpukit/rtems/src/msgqreceive.c @ ef6f8a83

5
Last change on this file since ef6f8a83 was b0eba5ed, checked in by Sebastian Huber <sebastian.huber@…>, on 04/27/16 at 14:20:05

score: _CORE_message_queue_Seize()

Move lock acquire to caller of _CORE_message_queue_Seize() to allow
state checks during receive operations under lock protection.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Message Queue Receive
5 *  @ingroup ClassicMessageQueue
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
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/threadimpl.h>
26#include <rtems/score/wkspace.h>
27#include <rtems/rtems/status.h>
28#include <rtems/rtems/attrimpl.h>
29#include <rtems/rtems/messageimpl.h>
30#include <rtems/rtems/optionsimpl.h>
31#include <rtems/rtems/support.h>
32
33THREAD_WAIT_QUEUE_OBJECT_ASSERT(
34  Message_queue_Control,
35  message_queue.Wait_queue
36);
37
38rtems_status_code rtems_message_queue_receive(
39  rtems_id        id,
40  void           *buffer,
41  size_t         *size,
42  rtems_option    option_set,
43  rtems_interval  timeout
44)
45{
46  Message_queue_Control          *the_message_queue;
47  Objects_Locations               location;
48  bool                            wait;
49  Thread_Control                 *executing;
50  ISR_lock_Context                lock_context;
51
52  if ( !buffer )
53    return RTEMS_INVALID_ADDRESS;
54
55  if ( !size )
56    return RTEMS_INVALID_ADDRESS;
57
58  the_message_queue = _Message_queue_Get_interrupt_disable(
59    id,
60    &location,
61    &lock_context
62  );
63  switch ( location ) {
64
65    case OBJECTS_LOCAL:
66      if ( _Options_Is_no_wait( option_set ) )
67        wait = false;
68      else
69        wait = true;
70
71      _CORE_message_queue_Acquire_critical(
72        &the_message_queue->message_queue,
73        &lock_context
74      );
75
76      executing = _Thread_Executing;
77      _CORE_message_queue_Seize(
78        &the_message_queue->message_queue,
79        executing,
80        the_message_queue->Object.id,
81        buffer,
82        size,
83        wait,
84        timeout,
85        &lock_context
86      );
87      return _Message_queue_Translate_core_message_queue_return_code(
88        executing->Wait.return_code
89      );
90
91#if defined(RTEMS_MULTIPROCESSING)
92    case OBJECTS_REMOTE:
93      return _Message_queue_MP_Send_request_packet(
94          MESSAGE_QUEUE_MP_RECEIVE_REQUEST,
95          id,
96          buffer,
97          size,
98          option_set,
99          timeout
100        );
101#endif
102
103    case OBJECTS_ERROR:
104      break;
105  }
106
107  return RTEMS_INVALID_ID;
108}
Note: See TracBrowser for help on using the repository browser.