in FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_mqueue.c [154:199]
static int prvCalculateTickTimeout( long lMessageQueueFlags,
const struct timespec * const pxAbsoluteTimeout,
TickType_t * pxTimeoutTicks )
{
int iStatus = 0;
/* Check for nonblocking queue. */
if( lMessageQueueFlags & O_NONBLOCK )
{
/* No additional checks are done for nonblocking queues. Timeout is 0. */
*pxTimeoutTicks = 0;
}
else
{
/* No absolute timeout given. Block forever. */
if( pxAbsoluteTimeout == NULL )
{
*pxTimeoutTicks = portMAX_DELAY;
}
else
{
struct timespec xCurrentTime = { 0 };
/* Check that the given timespec is valid. */
if( UTILS_ValidateTimespec( pxAbsoluteTimeout ) == false )
{
iStatus = EINVAL;
}
/* Get current time */
if( ( iStatus == 0 ) && ( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 ) )
{
iStatus = EINVAL;
}
/* Convert absolute timespec to ticks. */
if( ( iStatus == 0 ) &&
( UTILS_AbsoluteTimespecToDeltaTicks( pxAbsoluteTimeout, &xCurrentTime, pxTimeoutTicks ) != 0 ) )
{
iStatus = ETIMEDOUT;
}
}
}
return iStatus;
}