source: rtems/cpukit/posix/src/mqueuesendsupp.c @ 631b3c8

5
Last change on this file since 631b3c8 was 631b3c8, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/16 at 09:40:18

score: Move thread queue MP callout to context

Drop the multiprocessing (MP) dependent callout parameter from the
thread queue extract, dequeue, flush and unblock methods. Merge this
parameter with the lock context into new structure Thread_queue_Context.
This helps to gets rid of the conditionally compiled method call
helpers.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Message Queue and Send Support
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  NOTE:  The structure of the routines is identical to that of POSIX
10 *         Message_queues to leave the option of having unnamed message
11 *         queues at a future date.  They are currently not part of the
12 *         POSIX standard but unnamed message_queues are.  This is also
13 *         the reason for the apparently unnecessary tracking of
14 *         the process_shared attribute.  [In addition to the fact that
15 *         it would be trivial to add pshared to the mq_attr structure
16 *         and have process private message queues.]
17 *
18 *         This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
19 *         time.
20 *
21 *  COPYRIGHT (c) 1989-2008.
22 *  On-Line Applications Research Corporation (OAR).
23 *
24 *  The license and distribution terms for this file may be
25 *  found in the file LICENSE in this distribution or at
26 *  http://www.rtems.org/license/LICENSE.
27 */
28
29#if HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <rtems/posix/mqueueimpl.h>
34
35#include <fcntl.h>
36
37int _POSIX_Message_queue_Send_support(
38  mqd_t               mqdes,
39  const char         *msg_ptr,
40  size_t              msg_len,
41  unsigned int        msg_prio,
42  bool                wait,
43  Watchdog_Interval   timeout
44)
45{
46  POSIX_Message_queue_Control *the_mq;
47  Thread_queue_Context         queue_context;
48  CORE_message_queue_Status    msg_status;
49  bool                         do_wait;
50  Thread_Control              *executing;
51
52  /*
53   * Validate the priority.
54   * XXX - Do not validate msg_prio is not less than 0.
55   */
56
57  if ( msg_prio > MQ_PRIO_MAX ) {
58    rtems_set_errno_and_return_minus_one( EINVAL );
59  }
60
61  the_mq = _POSIX_Message_queue_Get( mqdes, &queue_context );
62
63  if ( the_mq == NULL ) {
64    rtems_set_errno_and_return_minus_one( EBADF );
65  }
66
67  if ( ( the_mq->oflag & O_ACCMODE ) == O_RDONLY ) {
68    _ISR_lock_ISR_enable( &queue_context.Lock_context );
69    rtems_set_errno_and_return_minus_one( EBADF );
70  }
71
72  /*
73   *  A timed receive with a bad time will do a poll regardless.
74   */
75  if ( wait ) {
76    do_wait = ( the_mq->oflag & O_NONBLOCK ) == 0;
77  } else {
78    do_wait = wait;
79  }
80
81  _CORE_message_queue_Acquire_critical(
82    &the_mq->Message_queue,
83    &queue_context
84  );
85
86  if ( the_mq->open_count == 0 ) {
87    _CORE_message_queue_Release( &the_mq->Message_queue, &queue_context );
88    rtems_set_errno_and_return_minus_one( EBADF );
89  }
90
91  /*
92   *  Now perform the actual message receive
93   */
94  executing = _Thread_Executing;
95  msg_status = _CORE_message_queue_Submit(
96    &the_mq->Message_queue,
97    executing,
98    msg_ptr,
99    msg_len,
100    _POSIX_Message_queue_Priority_to_core( msg_prio ),
101    do_wait,
102    timeout,
103    &queue_context
104  );
105
106  if ( msg_status != CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL ) {
107    rtems_set_errno_and_return_minus_one(
108      _POSIX_Message_queue_Translate_core_message_queue_return_code(
109        msg_status
110      )
111    );
112  }
113
114  return 0;
115}
Note: See TracBrowser for help on using the repository browser.