sched/signal/sig_nanosleep: fix the clock_nanosleep posix case
1. make the clock_nanosleep can pass ltp/open_posix_testsuite/clock_nanosleep 13-1, 10-1, 9-1 cases 2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html Signed-off-by: guoshichao <guoshichao@xiaomi.com>
This commit is contained in:
parent
8abf803a1d
commit
0092b3e30f
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -80,10 +81,22 @@
|
|||||||
|
|
||||||
int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp)
|
int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Calling clock_nanosleep() with the value TIMER_ABSTIME not set in the
|
/* Calling clock_nanosleep() with the value TIMER_ABSTIME not set in the
|
||||||
* flags argument and with a clock_id of CLOCK_REALTIME is equivalent t
|
* flags argument and with a clock_id of CLOCK_REALTIME is equivalent t
|
||||||
* calling nanosleep() with the same rqtp and rmtp arguments.
|
* calling nanosleep() with the same rqtp and rmtp arguments.
|
||||||
|
* As clock_nanosleep() method return errno on fail, which is not
|
||||||
|
* compatible with nanosleep(), the nanosleep() need to return -1 on fail,
|
||||||
|
* so we need to convert the return value.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp);
|
ret = clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
set_errno(ret);
|
||||||
|
ret = ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -244,12 +244,13 @@ int nxsig_nanosleep(FAR const struct timespec *rqtp,
|
|||||||
* actually slept). If the rmtp argument is NULL, the remaining time is not
|
* actually slept). If the rmtp argument is NULL, the remaining time is not
|
||||||
* returned.
|
* returned.
|
||||||
*
|
*
|
||||||
* If clock_nanosleep() fails, it returns a value of -1 and sets errno to
|
* If clock_nanosleep() fails, it returns a value of errno. The
|
||||||
* indicate the error. The clock_nanosleep() function will fail if:
|
* clock_nanosleep() function will fail if:
|
||||||
*
|
*
|
||||||
* EINTR - The clock_nanosleep() function was interrupted by a signal.
|
* EINTR - The clock_nanosleep() function was interrupted by a signal.
|
||||||
* EINVAL - The rqtp argument specified a nanosecond value less than
|
* EINVAL - The rqtp argument specified a nanosecond value less than
|
||||||
* zero or greater than or equal to 1000 million.
|
* zero or greater than or equal to 1000 million. Or the clockid that
|
||||||
|
* does not specify a known clock.
|
||||||
* ENOSYS - The clock_nanosleep() function is not supported by this
|
* ENOSYS - The clock_nanosleep() function is not supported by this
|
||||||
* implementation.
|
* implementation.
|
||||||
*
|
*
|
||||||
@ -265,6 +266,12 @@ int clock_nanosleep(clockid_t clockid, int flags,
|
|||||||
|
|
||||||
enter_cancellation_point();
|
enter_cancellation_point();
|
||||||
|
|
||||||
|
if (clockid < CLOCK_REALTIME || clockid > CLOCK_BOOTTIME)
|
||||||
|
{
|
||||||
|
leave_cancellation_point();
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if absolute time is selected */
|
/* Check if absolute time is selected */
|
||||||
|
|
||||||
if ((flags & TIMER_ABSTIME) != 0)
|
if ((flags & TIMER_ABSTIME) != 0)
|
||||||
@ -286,7 +293,7 @@ int clock_nanosleep(clockid_t clockid, int flags,
|
|||||||
|
|
||||||
leave_critical_section(irqstate);
|
leave_critical_section(irqstate);
|
||||||
leave_cancellation_point();
|
leave_cancellation_point();
|
||||||
return ERROR;
|
return -ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
clock_timespec_subtract(rqtp, &now, &reltime);
|
clock_timespec_subtract(rqtp, &now, &reltime);
|
||||||
@ -312,10 +319,9 @@ int clock_nanosleep(clockid_t clockid, int flags,
|
|||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
/* If not set the errno variable and return -1 */
|
/* If not return the errno */
|
||||||
|
|
||||||
set_errno(-ret);
|
ret = -ret;
|
||||||
ret = ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
leave_cancellation_point();
|
leave_cancellation_point();
|
||||||
|
Loading…
Reference in New Issue
Block a user