source: rtems/cpukit/posix/src/mqueuetimedreceive.c @ dbb30e26

5
Last change on this file since dbb30e26 was b5bfaaf9, checked in by Gedare Bloom <gedare@…>, on 06/23/16 at 20:55:38

posix: cond_timedwait remember and use clock from condattr

updates #2745

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Receive Message from Message Queue
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
22/*
23 *  COPYRIGHT (c) 1989-2008.
24 *  On-Line Applications Research Corporation (OAR).
25 *
26 *  The license and distribution terms for this file may be
27 *  found in the file LICENSE in this distribution or at
28 *  http://www.rtems.org/license/LICENSE.
29 */
30
31#if HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include <stdarg.h>
36
37#include <pthread.h>
38#include <limits.h>
39#include <errno.h>
40#include <fcntl.h>
41#include <mqueue.h>
42
43#include <rtems/system.h>
44#include <rtems/score/todimpl.h>
45#include <rtems/seterr.h>
46#include <rtems/posix/mqueueimpl.h>
47
48/*
49 *  15.2.5 Receive a Message From a Message Queue, P1003.1b-1993, p. 279
50 *
51 *  NOTE: P1003.4b/D8, p. 45 adds mq_timedreceive().
52 */
53
54ssize_t mq_timedreceive(
55  mqd_t                  mqdes,
56  char                  *__restrict msg_ptr,
57  size_t                 msg_len,
58  unsigned int          *__restrict msg_prio,
59  const struct timespec *__restrict abstime
60)
61{
62  Watchdog_Interval                            ticks;
63  bool                                         do_wait = true;
64  TOD_Absolute_timeout_conversion_results  status;
65
66  /*
67   *  POSIX requires that blocking calls with timeouts that take
68   *  an absolute timeout must ignore issues with the absolute
69   *  time provided if the operation would otherwise succeed.
70   *  So we check the abstime provided, and hold on to whether it
71   *  is valid or not.  If it isn't correct and in the future,
72   *  then we do a polling operation and convert the UNSATISFIED
73   *  status into the appropriate error.
74   *
75   *  If the status is TOD_ABSOLUTE_TIMEOUT_INVALID,
76   *  TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
77   *  then we should not wait.
78   */
79  status = _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks );
80  if ( status != TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
81    do_wait = false;
82
83  return _POSIX_Message_queue_Receive_support(
84    mqdes,
85    msg_ptr,
86    msg_len,
87    msg_prio,
88    do_wait,
89    ticks
90  );
91}
Note: See TracBrowser for help on using the repository browser.