source: rtems/cpukit/posix/src/mqueuesendsupp.c @ 1d572eba

5
Last change on this file since 1d572eba was c3105894, checked in by Sebastian Huber <sebastian.huber@…>, on 10/19/17 at 11:47:57

score: Move thread queue timeout handling

Update #3117.
Update #3182.

  • Property mode set to 100644
File size: 2.8 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  const struct timespec        *abstime,
43  Thread_queue_Enqueue_callout  enqueue_callout
44)
45{
46  POSIX_Message_queue_Control *the_mq;
47  Thread_queue_Context         queue_context;
48  Status_Control               status;
49  Thread_Control              *executing;
50
51  /*
52   * Validate the priority.
53   * XXX - Do not validate msg_prio is not less than 0.
54   */
55
56  if ( msg_prio > MQ_PRIO_MAX ) {
57    rtems_set_errno_and_return_minus_one( EINVAL );
58  }
59
60  the_mq = _POSIX_Message_queue_Get( mqdes, &queue_context );
61
62  if ( the_mq == NULL ) {
63    rtems_set_errno_and_return_minus_one( EBADF );
64  }
65
66  if ( ( the_mq->oflag & O_ACCMODE ) == O_RDONLY ) {
67    _ISR_lock_ISR_enable( &queue_context.Lock_context.Lock_context );
68    rtems_set_errno_and_return_minus_one( EBADF );
69  }
70
71  _Thread_queue_Context_set_enqueue_callout( &queue_context, enqueue_callout );
72  _Thread_queue_Context_set_timeout_argument( &queue_context, abstime );
73
74  _CORE_message_queue_Acquire_critical(
75    &the_mq->Message_queue,
76    &queue_context
77  );
78
79  if ( the_mq->open_count == 0 ) {
80    _CORE_message_queue_Release( &the_mq->Message_queue, &queue_context );
81    rtems_set_errno_and_return_minus_one( EBADF );
82  }
83
84  /*
85   *  Now perform the actual message receive
86   */
87  executing = _Thread_Executing;
88  status = _CORE_message_queue_Submit(
89    &the_mq->Message_queue,
90    executing,
91    msg_ptr,
92    msg_len,
93    _POSIX_Message_queue_Priority_to_core( msg_prio ),
94    ( the_mq->oflag & O_NONBLOCK ) == 0,
95    &queue_context
96  );
97  return _POSIX_Zero_or_minus_one_plus_errno( status );
98}
Note: See TracBrowser for help on using the repository browser.