Move sleep() and usleep() from sched/ to libc/unistd/. These functions now are simple wrappers for nanosleep(). Remove sleep() and usleep() from system calls; add nanosleep() to system calls
This commit is contained in:
parent
342e777029
commit
7aff059fd0
@ -6211,3 +6211,9 @@
|
||||
* lbc/time/lib_strftime.c: Need null-termination on the the string
|
||||
generated by strftime(). From Max Holtzberg (2013-12-12).
|
||||
* sched/nanosleep.c and include/time.h: Add nanosleep() (2013-12-12).
|
||||
* libc/unistd/lib_sleep.c and lib_usleep.c. Move sleep() and
|
||||
usleep() from sched/sleep.c and usleep.c to libc/unistd. These
|
||||
functions now just call nanosleep(). (2013-12-13).
|
||||
* syscall/ and include/sys/syscall.h: Remove sleep and usleep
|
||||
system calls. Add nanosleep system call (2013-12-13).
|
||||
|
||||
|
@ -162,9 +162,8 @@
|
||||
# define SYS_sigsuspend (__SYS_signals+5)
|
||||
# define SYS_sigtimedwait (__SYS_signals+6)
|
||||
# define SYS_sigwaitinfo (__SYS_signals+7)
|
||||
# define SYS_sleep (__SYS_signals+8)
|
||||
# define SYS_usleep (__SYS_signals+9)
|
||||
# define __SYS_clock (__SYS_signals+10)
|
||||
# define SYS_nanosleep (__SYS_signals+8)
|
||||
# define __SYS_clock (__SYS_signals+9)
|
||||
#else
|
||||
# define __SYS_clock __SYS_signals
|
||||
#endif
|
||||
|
@ -47,6 +47,10 @@ CSRCS += lib_execl.c lib_execv.c lib_execsymtab.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
||||
CSRCS += lib_sleep.c lib_usleep.c
|
||||
endif
|
||||
|
||||
# Add the unistd directory to the build
|
||||
|
||||
DEPPATH += --dep-path unistd
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* sched/sleep.c
|
||||
* lib/lib_sleep.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007, 2009, 2012-2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -128,69 +128,39 @@
|
||||
|
||||
unsigned int sleep(unsigned int seconds)
|
||||
{
|
||||
sigset_t set;
|
||||
struct timespec ts;
|
||||
struct siginfo value;
|
||||
irqstate_t flags;
|
||||
uint32_t start;
|
||||
int32_t elapsed;
|
||||
int32_t remaining = 0;
|
||||
struct timespec rqtp;
|
||||
struct timespec rmtp;
|
||||
unsigned int remaining = 0;
|
||||
int ret;
|
||||
|
||||
/* Don't sleep if seconds == 0 */
|
||||
|
||||
if (seconds)
|
||||
{
|
||||
/* Set up for the sleep. Using the empty set means that we are not
|
||||
* waiting for any particular signal. However, any unmasked signal
|
||||
* can still awaken sigtimedwait().
|
||||
/* Let nanosleep() do all of the work. */
|
||||
|
||||
rqtp.tv_sec = seconds;
|
||||
rqtp.tv_nsec = 0;
|
||||
|
||||
ret = nanosleep(&rqtp, &rmtp);
|
||||
|
||||
/* nanosleep() should only fail if it was interrupted by a signal,
|
||||
* but we treat all errors the same,
|
||||
*/
|
||||
|
||||
(void)sigemptyset(&set);
|
||||
ts.tv_sec = seconds;
|
||||
ts.tv_nsec = 0;
|
||||
|
||||
/* Interrupts are disabled around the following so that it is atomic */
|
||||
|
||||
flags = irqsave();
|
||||
|
||||
/* Get the current time then sleep for the requested time.
|
||||
* sigtimedwait() cannot succeed. It should always return error with
|
||||
* either (1) EAGAIN meaning that the timeout occurred, or (2) EINTR
|
||||
* meaning that some other unblocked signal was caught.
|
||||
*/
|
||||
|
||||
start = clock_systimer();
|
||||
(void)sigtimedwait(&set, &value, &ts);
|
||||
|
||||
/* Calculate the elapsed time (in clock ticks) when we wake up from the sleep.
|
||||
* This is really only necessary if we were awakened from the sleep early
|
||||
* due to the receipt of a signal.
|
||||
*/
|
||||
|
||||
elapsed = clock_systimer() - start;
|
||||
irqrestore(flags);
|
||||
|
||||
/* Get the remaining, un-waited seconds. Note that this calculation
|
||||
* truncates the elapsed seconds in the division. We may have slept some
|
||||
* fraction of a second longer than this! But if the calculation is less
|
||||
* than the 'seconds', we certainly did not sleep for the complete
|
||||
* requested interval.
|
||||
*/
|
||||
|
||||
remaining = (int32_t)seconds - elapsed / TICK_PER_SEC;
|
||||
|
||||
/* Make sure that the elapsed time is non-negative (this should always
|
||||
* be the case unless something exceptional happened while were we
|
||||
* sleeping -- like the clock was reset or we went into a low power mode,
|
||||
* OR if we had to wait a long time to run again after calling
|
||||
* sigtimedwait() making 'elapsed' bigger than it should have been).
|
||||
*/
|
||||
|
||||
if (remaining < 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
remaining = 0;
|
||||
remaining = rmtp.tv_nsec;
|
||||
if (remaining < seconds && rmtp.tv_nsec >= 500000000)
|
||||
{
|
||||
/* Round up */
|
||||
|
||||
remaining++;
|
||||
}
|
||||
}
|
||||
|
||||
return (unsigned int)remaining;
|
||||
return remaining;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* sched/usleep.c
|
||||
* lib/lib_usleep.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007, 2009, 2012-2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -128,40 +128,17 @@
|
||||
|
||||
int usleep(useconds_t usec)
|
||||
{
|
||||
sigset_t set;
|
||||
struct timespec ts;
|
||||
struct siginfo value;
|
||||
int errval;
|
||||
struct timespec rqtp;
|
||||
int ret = 0;
|
||||
|
||||
if (usec)
|
||||
{
|
||||
/* Set up for the sleep. Using the empty set means that we are not
|
||||
* waiting for any particular signal. However, any unmasked signal
|
||||
* can still awaken sigtimedwait().
|
||||
*/
|
||||
/* Let nanosleep() do all of the work. */
|
||||
|
||||
(void)sigemptyset(&set);
|
||||
ts.tv_sec = usec / 1000000;
|
||||
ts.tv_nsec = (usec % 1000000) * 1000;
|
||||
rqtp.tv_sec = usec / 1000000;
|
||||
rqtp.tv_nsec = (usec % 1000000) * 1000;
|
||||
|
||||
/* usleep is a simple application of sigtimedwait. */
|
||||
|
||||
ret = sigtimedwait(&set, &value, &ts);
|
||||
|
||||
/* sigtimedwait() cannot succeed. It should always return error with
|
||||
* either (1) EAGAIN meaning that the timeout occurred, or (2) EINTR
|
||||
* meaning that some other unblocked signal was caught.
|
||||
*/
|
||||
|
||||
errval = errno;
|
||||
DEBUGASSERT(ret < 0 && (errval == EAGAIN || errval == EINTR));
|
||||
if (errval == EAGAIN)
|
||||
{
|
||||
/* The timeout "error" is the normal, successful result */
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
ret = nanosleep(&rqtp, NULL);
|
||||
}
|
||||
|
||||
return ret;
|
@ -114,7 +114,7 @@ WDOG_SRCS += wd_gettime.c
|
||||
TIME_SRCS = sched_processtimer.c
|
||||
|
||||
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
||||
TIME_SRCS += sleep.c usleep.c nanosleep.c
|
||||
TIME_SRCS += nanosleep.c
|
||||
endif
|
||||
|
||||
CLOCK_SRCS = clock_initialize.c clock_settime.c clock_gettime.c clock_getres.c
|
||||
|
@ -40,6 +40,7 @@
|
||||
"mq_timedsend","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const char*","size_t","int","const struct timespec*"
|
||||
"mq_unlink","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","const char*"
|
||||
"on_exit","stdlib.h","defined(CONFIG_SCHED_ONEXIT)","int","CODE void (*)(int, FAR void *)","FAR void *"
|
||||
"nanosleep","time.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR const struct timespec *", "FAR struct timespec*"
|
||||
"open","fcntl.h","CONFIG_NFILE_DESCRIPTORS > 0","int","const char*","int","..."
|
||||
"opendir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","FAR DIR*","FAR const char*"
|
||||
"pipe","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int [2]|int*"
|
||||
@ -118,7 +119,6 @@
|
||||
"sigsuspend","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR const sigset_t*"
|
||||
"sigtimedwait","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR const sigset_t*","FAR struct siginfo*","FAR const struct timespec*"
|
||||
"sigwaitinfo","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR const sigset_t*","FAR struct siginfo*"
|
||||
"sleep","unistd.h","!defined(CONFIG_DISABLE_SIGNALS)","unsigned int","unsigned int"
|
||||
"socket","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int","int"
|
||||
"stat","sys/stat.h","CONFIG_NFILE_DESCRIPTORS > 0","int","const char*","FAR struct stat*"
|
||||
#"statfs","stdio.h","","int","FAR const char*","FAR struct statfs*"
|
||||
@ -138,7 +138,6 @@
|
||||
"unsetenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","const char*"
|
||||
"up_assert","assert.h","","void","FAR const uint8_t*","int"
|
||||
#"up_assert","assert.h","","void"
|
||||
"usleep","unistd.h","!defined(CONFIG_DISABLE_SIGNALS)","int","useconds_t"
|
||||
"vfork","unistd.h","defined(CONFIG_ARCH_HAVE_VFORK)","pid_t"
|
||||
"wait","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","pid_t","int*"
|
||||
"waitid","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","int","idtype_t","id_t"," FAR siginfo_t *","int"
|
||||
|
Can't render this file because it has a wrong number of fields in line 2.
|
@ -118,8 +118,7 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
|
||||
SYSCALL_LOOKUP(sigsuspend, 1, STUB_sigsuspend)
|
||||
SYSCALL_LOOKUP(sigtimedwait, 3, STUB_sigtimedwait)
|
||||
SYSCALL_LOOKUP(sigwaitinfo, 2, STUB_sigwaitinfo)
|
||||
SYSCALL_LOOKUP(sleep, 1, STUB_sleep)
|
||||
SYSCALL_LOOKUP(usleep, 1, STUB_usleep)
|
||||
SYSCALL_LOOKUP(nanosleep, 2, STUB_nanosleep)
|
||||
#endif
|
||||
|
||||
/* The following are only defined if the system clock is enabled in the
|
||||
|
@ -132,8 +132,7 @@ uintptr_t STUB_sigsuspend(int nbr, uintptr_t parm1);
|
||||
uintptr_t STUB_sigtimedwait(int nbr, uintptr_t parm1, uintptr_t parm2,
|
||||
uintptr_t parm3);
|
||||
uintptr_t STUB_sigwaitinfo(int nbr, uintptr_t parm1, uintptr_t parm2);
|
||||
uintptr_t STUB_sleep(int nbr, uintptr_t parm1);
|
||||
uintptr_t STUB_usleep(int nbr, uintptr_t parm1);
|
||||
uintptr_t STUB_nanosleep(int nbr, uintptr_t parm1, uintptr_t parm2);
|
||||
|
||||
/* The following are only defined if the system clock is enabled in the
|
||||
* NuttX configuration.
|
||||
|
Loading…
x
Reference in New Issue
Block a user