1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Send a Message to a Message Queue |
---|
5 | * @ingroup POSIX_MQUEUE |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
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 <stdarg.h> |
---|
22 | |
---|
23 | #include <pthread.h> |
---|
24 | #include <limits.h> |
---|
25 | #include <errno.h> |
---|
26 | #include <fcntl.h> |
---|
27 | #include <mqueue.h> |
---|
28 | |
---|
29 | #include <rtems/system.h> |
---|
30 | #include <rtems/score/todimpl.h> |
---|
31 | #include <rtems/seterr.h> |
---|
32 | #include <rtems/posix/mqueueimpl.h> |
---|
33 | |
---|
34 | int mq_timedsend( |
---|
35 | mqd_t mqdes, |
---|
36 | const char *msg_ptr, |
---|
37 | size_t msg_len, |
---|
38 | unsigned int msg_prio, |
---|
39 | const struct timespec *abstime |
---|
40 | ) |
---|
41 | { |
---|
42 | Watchdog_Interval ticks; |
---|
43 | bool do_wait = true; |
---|
44 | TOD_Absolute_timeout_conversion_results status; |
---|
45 | |
---|
46 | /* |
---|
47 | * POSIX requires that blocking calls with timeouts that take |
---|
48 | * an absolute timeout must ignore issues with the absolute |
---|
49 | * time provided if the operation would otherwise succeed. |
---|
50 | * So we check the abstime provided, and hold on to whether it |
---|
51 | * is valid or not. If it isn't correct and in the future, |
---|
52 | * then we do a polling operation and convert the UNSATISFIED |
---|
53 | * status into the appropriate error. |
---|
54 | * |
---|
55 | * If the status is TOD_ABSOLUTE_TIMEOUT_INVALID, |
---|
56 | * TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW, |
---|
57 | * then we should not wait. |
---|
58 | */ |
---|
59 | status = _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks ); |
---|
60 | if ( status != TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE ) |
---|
61 | do_wait = false; |
---|
62 | |
---|
63 | return _POSIX_Message_queue_Send_support( |
---|
64 | mqdes, |
---|
65 | msg_ptr, |
---|
66 | msg_len, |
---|
67 | msg_prio, |
---|
68 | do_wait, |
---|
69 | ticks |
---|
70 | ); |
---|
71 | } |
---|