RTAI_SYSCALL_MODE int _rt_msg_receive_until(RT_MSGQ *mq, void *msg, int msg_size, int *msgpri, RTIME until, int space) { int retval; if ((retval = rt_sem_wait_until(&mq->receivers, until)) >= RTE_LOWERR) { return TBX_RET(msg_size, retval); } if ((retval = rt_sem_wait_until(&mq->received, until)) >= RTE_LOWERR) { rt_sem_signal(&mq->receivers); return TBX_RET(msg_size, retval); } return _receive(mq, msg, msg_size, msgpri, space); }
/** * @brief Receives a message with absolute timeout. * * rt_mbx_receive_until receives a message of @e msg_size bytes from * the mailbox @e mbx. The caller will be blocked until all bytes of * the message arrive, timeout expires or an error occurs. * * @param mbx is a pointer to a user allocated mailbox structure. * * @param msg points to a buffer provided by the caller. * * @param msg_size corresponds to the size of the message received. * * @param time is an absolute value of the timeout. * * @return On success, 0 is returned. * On failure a value is returned as described below: * - the number of bytes not received: an error is occured * in the queueing of all receiving tasks or the timeout has expired. * - @b EINVAL: mbx points to an invalid mailbox. * * See also: notes under rt_mbx_received_timed(). */ RTAI_SYSCALL_MODE int _rt_mbx_receive_until(MBX *mbx, void *msg, int msg_size, RTIME time, int space) { RT_TASK *rt_current = RT_CURRENT; int retval; CHK_MBX_MAGIC; if ((retval = rt_sem_wait_until(&mbx->rcvsem, time)) > 1) { return MBX_RET(msg_size, retval); } while (msg_size) { if ((retval = mbx_wait_until(mbx, &mbx->avbs, time, rt_current))) { rt_sem_signal(&mbx->rcvsem); retval = MBX_RET(msg_size, retval); rt_wakeup_pollers(&mbx->poll_recv, retval); return retval; } msg_size = mbxget(mbx, (char **)(&msg), msg_size, space); mbx_signal(mbx); } rt_sem_signal(&mbx->rcvsem); rt_wakeup_pollers(&mbx->poll_send, 0); return 0; }
RTAI_SYSCALL_MODE int _rt_msg_broadcast_until(RT_MSGQ *mq, void *msg, int msg_size, int msgpri, RTIME until, int space) { int retval; if ((retval = rt_sem_wait_until(&mq->senders, until)) >= RTE_LOWERR) { return TBX_RET(0, retval); } if (mq->received.count >= 0) { rt_sem_signal(&mq->senders); return 0; } if ((retval = rt_sem_wait_until(&mq->freslots, until)) >= RTE_LOWERR) { rt_sem_signal(&mq->senders); return TBX_RET(0, retval); } return _broadcast(mq, msg, msg_size, msgpri, -(mq->received.count + mq->receivers.count), space); }
int rtos_sem_wait_until(rt_sem_t* m, NANO_TIME when ) { int ret; CHK_LXRT_CALL(); ret = rt_sem_wait_until(m->sem, nano2count(when) ) ; #if defined(CONFIG_RTAI_VERSION_MINOR) && defined(CONFIG_RTAI_VERSION_MAJOR) # if CONFIG_RTAI_VERSION_MAJOR == 3 && CONFIG_RTAI_VERSION_MINOR > 3 return (ret == RTE_TIMOUT) ? -1 : 0; # else return (ret == SEM_TIMOUT) ? -1 : 0; # endif #else return (ret == SEM_TIMOUT) ? -1 : 0; #endif }
int rtos_mutex_rec_lock_until( rt_rec_mutex_t* m, NANO_TIME abs_time) { CHK_LXRT_CALL(); return rt_sem_wait_until(m->sem, nano2count(abs_time)) < SEM_TIMOUT ? 0 : -EAGAIN; }