[PATCH v2 08/20] lib/cobalt: mq: Move all time64 related services to wrappers_time64.c
Florian Bezdeka <[email protected]>
| Newsgroups | dev.linux.lists.xenomai |
|---|---|
| Message-ID | <20260302-wip-flo-fix-time64-32bit-native-v2-8-7caefce29bcd@siemens.com> |
Code movement with some minor adjustments to the doxygen headers. All services should remain in the cobalt_api_mq group. Signed-off-by: Florian Bezdeka <[email protected]> --- lib/cobalt/mq.c | 121 ----------------------------------------- lib/cobalt/wrappers_time64.c | 125 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 121 deletions(-) diff --git a/lib/cobalt/mq.c b/lib/cobalt/mq.c index 72d419d6cfac0097ba7ed61941e7b8a92e3bc673..0997d396d06e08407741f4b5d6b373284f219f97 100644 --- a/lib/cobalt/mq.c +++ b/lib/cobalt/mq.c @@ -345,64 +345,6 @@ COBALT_IMPL(int, mq_send, (mqd_t q, const char *buffer, size_t len, unsigned pri return -1; } -/** - * Attempt, during a bounded time, to send a message to a message queue. - * - * This service is equivalent to mq_send(), except that if the message queue is - * full and the flag @a O_NONBLOCK is not set for the descriptor @a fd, the - * calling thread is only suspended until the timeout specified by @a - * abs_timeout expires. - * - * @param q message queue descriptor; - * - * @param buffer pointer to the message to be sent; - * - * @param len length of the message; - * - * @param prio priority of the message; - * - * @param timeout the timeout, expressed as an absolute value of the - * CLOCK_REALTIME clock. - * - * @return 0 and send a message on success; - * @return -1 with no message sent and @a errno set if: - * - EBADF, @a fd is not a valid message queue descriptor open for writing; - * - EMSGSIZE, the message length exceeds the @a mq_msgsize attribute of the - * message queue; - * - EAGAIN, the flag O_NONBLOCK is set for the descriptor @a fd and the message - * queue is full; - * - EPERM, the caller context is invalid; - * - ETIMEDOUT, the specified timeout expired; - * - EINTR, the service was interrupted by a signal. - * - * @see - * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/mq_timedsend.html"> - * Specification.</a> - * - * @apitags{xthread-only, switch-primary} - */ -COBALT_IMPL_TIME64(int, mq_timedsend, __mq_timedsend_time64, - (mqd_t q, const char *buffer, size_t len, unsigned prio, - const struct timespec *timeout)) -{ - int err, oldtype; - - if (timeout == NULL) - return -EFAULT; - - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); - - err = __do_mq_timesend(q, buffer, len, prio, timeout); - - pthread_setcanceltype(oldtype, NULL); - - if (!err) - return 0; - - errno = -err; - return -1; -} - /** * Receive a message from a message queue. * @@ -461,69 +403,6 @@ COBALT_IMPL(ssize_t, mq_receive, (mqd_t q, char *buffer, size_t len, unsigned *p return -1; } -/** - * Attempt, during a bounded time, to receive a message from a message queue. - * - * This service is equivalent to mq_receive(), except that if the flag @a - * O_NONBLOCK is not set for the descriptor @a fd and the message queue is - * empty, the calling thread is only suspended until the timeout @a abs_timeout - * expires. - * - * @param q the queue descriptor; - * - * @param buffer the address where the received message will be stored on - * success; - * - * @param len @a buffer length; - * - * @param prio address where the priority of the received message will be - * stored on success. - * - * @param timeout the timeout, expressed as an absolute value of the - * CLOCK_REALTIME clock. - * - * @return the message length, and copy a message at the address @a buffer on - * success; - * @return -1 with no message unqueued and @a errno set if: - * - EBADF, @a fd is not a valid descriptor open for reading; - * - EMSGSIZE, the length @a len is lesser than the message queue @a mq_msgsize - * attribute; - * - EAGAIN, the queue is empty, and the flag @a O_NONBLOCK is set for the - * descriptor @a fd; - * - EPERM, the caller context is invalid; - * - EINTR, the service was interrupted by a signal; - * - ETIMEDOUT, the specified timeout expired. - * - * @see - * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/mq_timedreceive.html"> - * Specification.</a> - * - * @apitags{xthread-only, switch-primary} - */ -COBALT_IMPL_TIME64(ssize_t, mq_timedreceive, __mq_timedreceive_time64, - (mqd_t q, char *__restrict__ buffer, size_t len, - unsigned *__restrict__ prio, - const struct timespec *__restrict__ timeout)) -{ - ssize_t rlen = (ssize_t) len; - int err, oldtype; - - if (timeout == NULL) - return -EFAULT; - - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); - - err = __do_mq_timedreceive(q, buffer, &rlen, prio, timeout); - - pthread_setcanceltype(oldtype, NULL); - - if (!err) - return rlen; - - errno = -err; - return -1; -} - /** * @brief Enable notification on message arrival * diff --git a/lib/cobalt/wrappers_time64.c b/lib/cobalt/wrappers_time64.c index ef2fb9869976fa9a60f45dab0a6ded1606ebf21d..09930ab018104dcc2a54c354b4b756230cfda029 100644 --- a/lib/cobalt/wrappers_time64.c +++ b/lib/cobalt/wrappers_time64.c @@ -14,11 +14,13 @@ #include "cond.h" #include "internal.h" +#include "mq.h" #include <asm/xenomai/syscall.h> #include <cobalt/uapi/syscall.h> #include <errno.h> +#include <mqueue.h> #include <pthread.h> #include <sys/time.h> #include <time.h> @@ -428,3 +430,126 @@ COBALT_IMPL_TIME64(int, pthread_cond_timedwait, __pthread_cond_timedwait64, return -err ?: -c.err; } + +/** + * Attempt, during a bounded time, to send a message to a message queue. + * @ingroup cobalt_api_mq + * + * This service is equivalent to mq_send(), except that if the message queue is + * full and the flag @a O_NONBLOCK is not set for the descriptor @a fd, the + * calling thread is only suspended until the timeout specified by @a + * abs_timeout expires. + * + * @param q message queue descriptor; + * + * @param buffer pointer to the message to be sent; + * + * @param len length of the message; + * + * @param prio priority of the message; + * + * @param timeout the timeout, expressed as an absolute value of the + * CLOCK_REALTIME clock. + * + * @return 0 and send a message on success; + * @return -1 with no message sent and @a errno set if: + * - EBADF, @a fd is not a valid message queue descriptor open for writing; + * - EMSGSIZE, the message length exceeds the @a mq_msgsize attribute of the + * message queue; + * - EAGAIN, the flag O_NONBLOCK is set for the descriptor @a fd and the message + * queue is full; + * - EPERM, the caller context is invalid; + * - ETIMEDOUT, the specified timeout expired; + * - EINTR, the service was interrupted by a signal. + * + * @see + * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/mq_timedsend.html"> + * Specification.</a> + * + * @apitags{xthread-only, switch-primary} + */ +COBALT_IMPL_TIME64(int, mq_timedsend, __mq_timedsend_time64, + (mqd_t q, const char *buffer, size_t len, unsigned prio, + const struct timespec *timeout)) +{ + int err, oldtype; + + if (timeout == NULL) + return -EFAULT; + + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); + + err = __do_mq_timesend(q, buffer, len, prio, timeout); + + pthread_setcanceltype(oldtype, NULL); + + if (!err) + return 0; + + errno = -err; + return -1; +} + +/** + * Attempt, during a bounded time, to receive a message from a message queue. + * @ingroup cobalt_api_mq + * + * This service is equivalent to mq_receive(), except that if the flag @a + * O_NONBLOCK is not set for the descriptor @a fd and the message queue is + * empty, the calling thread is only suspended until the timeout @a abs_timeout + * expires. + * + * @param q the queue descriptor; + * + * @param buffer the address where the received message will be stored on + * success; + * + * @param len @a buffer length; + * + * @param prio address where the priority of the received message will be + * stored on success. + * + * @param timeout the timeout, expressed as an absolute value of the + * CLOCK_REALTIME clock. + * + * @return the message length, and copy a message at the address @a buffer on + * success; + * @return -1 with no message unqueued and @a errno set if: + * - EBADF, @a fd is not a valid descriptor open for reading; + * - EMSGSIZE, the length @a len is lesser than the message queue @a mq_msgsize + * attribute; + * - EAGAIN, the queue is empty, and the flag @a O_NONBLOCK is set for the + * descriptor @a fd; + * - EPERM, the caller context is invalid; + * - EINTR, the service was interrupted by a signal; + * - ETIMEDOUT, the specified timeout expired. + * + * @see + * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/mq_timedreceive.html"> + * Specification.</a> + * + * @apitags{xthread-only, switch-primary} + */ +COBALT_IMPL_TIME64(ssize_t, mq_timedreceive, __mq_timedreceive_time64, + (mqd_t q, char *__restrict__ buffer, size_t len, + unsigned *__restrict__ prio, + const struct timespec *__restrict__ timeout)) +{ + ssize_t rlen = (ssize_t) len; + int err, oldtype; + + if (timeout == NULL) + return -EFAULT; + + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); + + err = __do_mq_timedreceive(q, buffer, &rlen, prio, timeout); + + pthread_setcanceltype(oldtype, NULL); + + if (!err) + return rlen; + + errno = -err; + return -1; +} -- 2.53.0