source: rtems/cpukit/rtems/src/msgqsend.c @ cc18d7b

4.115
Last change on this file since cc18d7b was cc18d7b, checked in by Sebastian Huber <sebastian.huber@…>, on 04/30/15 at 11:12:54

score: Fine grained locking for message queues

Aggregate several critical sections into a bigger one. Sending and
receiving messages is now protected by an ISR lock. Thread dispatching
is only disabled in case a blocking operation is necessary. The message
copy procedure is done inside the critical section (interrupts
disabled). Thus this change may have a negative impact on the interrupt
latency in case very large messages are transferred.

Update #2273.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief rtems_message_queue_send
5 * @ingroup ClassicMessageQueue Message Queues
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/thread.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/options.h>
31#include <rtems/rtems/support.h>
32
33/*
34 *
35 *  rtems_message_queue_send
36 *
37 *  This routine implements the directive rtems_message_queue_send.  It sends a
38 *  message to the specified message queue.
39 *
40 *  Input parameters:
41 *    id     - pointer to message queue
42 *    buffer - pointer to message buffer
43 *    size   - size of message to send
44 *
45 *  Output parameters:
46 *    RTEMS_SUCCESSFUL - if successful
47 *    error code       - if unsuccessful
48 */
49
50#if defined(RTEMS_MULTIPROCESSING)
51#define MESSAGE_QUEUE_MP_HANDLER _Message_queue_Core_message_queue_mp_support
52#else
53#define MESSAGE_QUEUE_MP_HANDLER NULL
54#endif
55
56rtems_status_code rtems_message_queue_send(
57  rtems_id    id,
58  const void *buffer,
59  size_t      size
60)
61{
62  Message_queue_Control           *the_message_queue;
63  Objects_Locations                location;
64  CORE_message_queue_Status        status;
65  ISR_lock_Context                 lock_context;
66
67  if ( !buffer )
68    return RTEMS_INVALID_ADDRESS;
69
70  the_message_queue = _Message_queue_Get_interrupt_disable(
71    id,
72    &location,
73    &lock_context
74  );
75  switch ( location ) {
76
77    case OBJECTS_LOCAL:
78      status = _CORE_message_queue_Send(
79        &the_message_queue->message_queue,
80        buffer,
81        size,
82        id,
83        MESSAGE_QUEUE_MP_HANDLER,
84        false,   /* sender does not block */
85        0,       /* no timeout */
86        &lock_context
87      );
88
89      /*
90       *  Since this API does not allow for blocking sends, we can directly
91       *  return the returned status.
92       */
93
94      return _Message_queue_Translate_core_message_queue_return_code(status);
95
96#if defined(RTEMS_MULTIPROCESSING)
97    case OBJECTS_REMOTE:
98      return _Message_queue_MP_Send_request_packet(
99        MESSAGE_QUEUE_MP_SEND_REQUEST,
100        id,
101        buffer,
102        &size,
103        0,                               /* option_set */
104        MPCI_DEFAULT_TIMEOUT
105      );
106      break;
107#endif
108
109    case OBJECTS_ERROR:
110      break;
111  }
112  return RTEMS_INVALID_ID;
113}
Note: See TracBrowser for help on using the repository browser.