source: rtems/cpukit/posix/src/mqueuetimedsend.c @ 6a0898b

4.104.114.95
Last change on this file since 6a0898b was 6a0898b, checked in by Joel Sherrill <joel.sherrill@…>, on 07/18/08 at 18:45:56

2008-07-18 Joel Sherrill <joel.sherrill@…>

PR 1291/cpukit

  • itron/inline/rtems/itron/semaphore.inl, itron/src/twai_sem.c, posix/include/mqueue.h, posix/include/rtems/posix/mqueue.h, posix/include/rtems/posix/semaphore.h, posix/include/rtems/posix/time.h, posix/src/condtimedwait.c, posix/src/mqueuereceive.c, posix/src/mqueuerecvsupp.c, posix/src/mqueuesend.c, posix/src/mqueuesendsupp.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c, posix/src/mutextranslatereturncode.c, posix/src/posixtimespecabsolutetimeout.c, posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c, posix/src/semaphoretranslatereturncode.c, posix/src/semaphorewaitsupp.c, posix/src/semtimedwait.c, posix/src/semtrywait.c, posix/src/semwait.c, posix/src/sigtimedwait.c, posix/src/timersettime.c, posix/src/ualarm.c, rtems/src/semobtain.c, rtems/src/semtranslatereturncode.c, score/include/rtems/score/coremutex.h, score/include/rtems/score/coresem.h, score/src/coresemseize.c: This patch addresses issues on implementation of the timeout on the following POSIX services. Some of these services incorrectly took a timeout as a relative time. Others would compute a 0 delta to timeout if the absolute time and the current time were equal and thus incorrectly block the caller forever. The root of the confusion is that POSIX specifies that if the timeout is incorrect (e.g. in the past, is now, or is numerically invalid), that it does not matter if the call would succeed without blocking. This is in contrast to RTEMS programming style where all errors are checked before any critical sections are entered. This fix implemented a more uniform way of handling POSIX absolute time timeouts.

+ pthread_cond_timedwait - could block forever
+ mq_timedreceive - used relative not absolute time
+ mq_timedsend - used relative not absolute time
+ pthread_mutex_timedlock - used relative not absolute time
+ pthread_rwlock_timedrdlock- used relative not absolute time
+ pthread_rwlock_timedwrlock- used relative not absolute time
+ sem_timedwait - could block forever

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 *  NOTE:  The structure of the routines is identical to that of POSIX
3 *         Message_queues to leave the option of having unnamed message
4 *         queues at a future date.  They are currently not part of the
5 *         POSIX standard but unnamed message_queues are.  This is also
6 *         the reason for the apparently unnecessary tracking of
7 *         the process_shared attribute.  [In addition to the fact that
8 *         it would be trivial to add pshared to the mq_attr structure
9 *         and have process private message queues.]
10 *
11 *         This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
12 *         time.
13 */
14
15/*
16 *  COPYRIGHT (c) 1989-2008.
17 *  On-Line Applications Research Corporation (OAR).
18 *
19 *  The license and distribution terms for this file may be
20 *  found in the file LICENSE in this distribution or at
21 *  http://www.rtems.com/license/LICENSE.
22 *
23 *  $Id$
24 */
25
26#if HAVE_CONFIG_H
27#include "config.h"
28#endif
29
30#include <stdarg.h>
31
32#include <pthread.h>
33#include <limits.h>
34#include <errno.h>
35#include <fcntl.h>
36#include <mqueue.h>
37
38#include <rtems/system.h>
39#include <rtems/score/watchdog.h>
40#include <rtems/seterr.h>
41#include <rtems/posix/mqueue.h>
42#include <rtems/posix/time.h>
43
44/*PAGE
45 *
46 *  15.2.4 Send a Message to a Message Queue, P1003.1b-1993, p. 277
47 *
48 *  NOTE: P1003.4b/D8, p. 45 adds mq_timedsend().
49 */
50
51int mq_timedsend(
52  mqd_t                  mqdes,
53  const char            *msg_ptr,
54  size_t                 msg_len,
55  unsigned int           msg_prio,
56  const struct timespec *abstime
57)
58{
59  Watchdog_Interval ticks;
60  boolean           do_wait;
61
62  /*
63   *  POSIX requires that blocking calls with timeouts that take
64   *  an absolute timeout must ignore issues with the absolute
65   *  time provided if the operation would otherwise succeed.
66   *  So we check the abstime provided, and hold on to whether it
67   *  is valid or not.  If it isn't correct and in the future,
68   *  then we do a polling operation and convert the UNSATISFIED
69   *  status into the appropriate error.
70   */
71  switch ( _POSIX_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
72    case POSIX_ABSOLUTE_TIMEOUT_INVALID:
73    case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
74    case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
75      do_wait = FALSE;
76      break;
77    case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
78      do_wait = TRUE;
79      break;
80  }
81
82  return _POSIX_Message_queue_Send_support(
83    mqdes,
84    msg_ptr,
85    msg_len,
86    msg_prio,
87    do_wait,
88    ticks
89  );
90}
Note: See TracBrowser for help on using the repository browser.