MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / sys_mq_timedreceive

Function sys_mq_timedreceive

components/lwp/lwp_syscall.c:9230–9269  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

9228 * @see sys_mq_receive
9229 */
9230sysret_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.

Callers

nothing calls this directly

Calls 5

kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
mq_timedreceiveFunction · 0.85
lwp_put_to_userFunction · 0.85
kmem_putFunction · 0.85

Tested by

no test coverage detected