* @brief Receive a message from a message queue with a timeout. * * This function attempts to receive a message from the specified message queue, but it * allows the receiver to specify a timeout. If the queue is empty, the function will block * until either a message becomes available or the specified timeout expires. If the timeout * expires without receiving a message, the function returns
| 9228 | * @see sys_mq_receive |
| 9229 | */ |
| 9230 | sysret_t sys_mq_timedreceive(mqd_t mqd, char *restrict msg, size_t len, unsigned *restrict prio, const struct timespec *restrict at) |
| 9231 | { |
| 9232 | int ret = 0; |
| 9233 | #ifdef ARCH_MM_MMU |
| 9234 | char *restrict kmsg = RT_NULL; |
| 9235 | |
| 9236 | struct timespec at_k; |
| 9237 | |
| 9238 | kmsg = (char *restrict)kmem_get(len + 1); |
| 9239 | if (!kmsg) |
| 9240 | return -ENOMEM; |
| 9241 | |
| 9242 | lwp_get_from_user(kmsg, (void *)msg, len + 1); |
| 9243 | if (at == RT_NULL) |
| 9244 | { |
| 9245 | ret = mq_timedreceive(mqd, kmsg, len, prio, RT_NULL); |
| 9246 | } |
| 9247 | else |
| 9248 | { |
| 9249 | if (!lwp_get_from_user(&at_k, (void *)at, sizeof(struct timespec))) |
| 9250 | return -EINVAL; |
| 9251 | ret = mq_timedreceive(mqd, kmsg, len, prio, &at_k); |
| 9252 | } |
| 9253 | |
| 9254 | if (ret > 0) |
| 9255 | lwp_put_to_user(msg, kmsg, len + 1); |
| 9256 | |
| 9257 | if (ret < 0) |
| 9258 | { |
| 9259 | ret = GET_ERRNO(); |
| 9260 | } |
| 9261 | |
| 9262 | kmem_put(kmsg); |
| 9263 | |
| 9264 | return ret; |
| 9265 | #else |
| 9266 | ret = mq_timedreceive(mqd, msg, len, prio, at); |
| 9267 | return (ret < 0 ? GET_ERRNO() : ret); |
| 9268 | #endif |
| 9269 | } |
| 9270 | |
| 9271 | /** |
| 9272 | * @brief Set up asynchronous notification for a message queue. |
nothing calls this directly
no test coverage detected