On 6/1/06, Jeff Johnston <jjohnstn@redhat.com> wrote:
If we protect the sleep functions with a check for HAVE_NANOSLEEP, then
this would be fine. The three users of the libc/posix dir right now are
I've defined -DHAVE_NANOSLEEP for arm/thumb/xscale. ARM
(-lgloss-linux) is the only configuration that provides nanosleep. It
shouldn't harm the others though.
Cheers,
Shaun
2006-06-02 Shaun Jackman <sjackman@gmail.com>
* configure.host (newlib_cflags) [arm, thumb, xscale]: Add
-DHAVE_NANOSLEEP.
* libc/posix/Makefile.am (GENERAL_SOURCES): Add sleep.c and
usleep.c.
* libc/posix/Makefile.in: Regenerate.
* libc/posix/sleep.c: New file.
* libc/posix/usleep.c: Ditto.
Index: configure.host
===================================================================
RCS file: /cvs/src/src/newlib/configure.host,v
retrieving revision 1.81
diff -u -r1.81 configure.host
--- configure.host 13 Apr 2006 19:56:23 -0000 1.81
+++ configure.host 2 Jun 2006 15:17:55 -0000
@@ -514,7 +514,7 @@
;;
arm-*-*)
syscall_dir=syscalls
- newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY"
+ newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY
-DHAVE_NANOSLEEP"
# If newlib is supplying syscalls, select which debug protocol is being
used.
# ARM_RDP_MONITOR selects the Demon monitor.
# ARM_RDI_MONITOR selects the Angel monitor.
@@ -669,7 +669,7 @@
;;
thumb-*-*)
syscall_dir=syscalls
- newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY"
+ newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY
-DHAVE_NANOSLEEP"
# If newlib is supplying syscalls, select which debug protocol is being
used.
# ARM_RDP_MONITOR selects the Demon monitor.
# ARM_RDI_MONITOR selects the Angel monitor.
@@ -700,7 +700,7 @@
;;
xscale-*-*)
syscall_dir=syscalls
- newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY"
+ newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY
-DHAVE_NANOSLEEP"
newlib_cflags="${newlib_cflags} -DHAVE_SYSTEM -DHAVE_RENAME"
if [ "x${newlib_may_supply_syscalls}" = "xyes" ] ; then
newlib_cflags="${newlib_cflags} -DARM_RDI_MONITOR"
Index: libc/posix/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/posix/Makefile.am,v
retrieving revision 1.6
diff -u -r1.6 Makefile.am
--- libc/posix/Makefile.am 1 May 2006 22:01:02 -0000 1.6
+++ libc/posix/Makefile.am 2 Jun 2006 15:19:22 -0000
@@ -7,7 +7,8 @@
GENERAL_SOURCES = \
closedir.c creat.c isatty.c \
opendir.c readdir.c \
- readdir_r.c rewinddir.c telldir.c
+ readdir_r.c rewinddir.c sleep.c usleep.c \
+ telldir.c
ELIX_2_SOURCES = \
scandir.c seekdir.c
--- /dev/null 2006-05-29 10:11:53.893844952 -0600
+++ libc/posix/sleep.c 2006-06-02 09:14:18.000000000 -0600
@@ -0,0 +1,22 @@
+/* libc/posix/sleep.c - sleep function */
+
+/* Written 2000 by Werner Almesberger */
+
+#ifdef HAVE_NANOSLEEP
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+unsigned sleep(unsigned seconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = seconds;
+ ts.tv_nsec = 0;
+ if (!nanosleep(&ts,&ts)) return 0;
+ if (errno == EINTR) return ts.tv_sec;
+ return -1;
+}
+
+#endif
--- /dev/null 2006-05-29 10:11:53.893844952 -0600
+++ libc/posix/usleep.c 2006-06-02 09:14:30.000000000 -0600
@@ -0,0 +1,22 @@
+/* libc/posix/usleep.c - usleep function */
+
+/* Written 2002 by Jeff Johnston */
+
+#ifdef HAVE_NANOSLEEP
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+int usleep(useconds_t useconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = (long int)useconds / 1000000;
+ ts.tv_nsec = ((long int)useconds % 1000000) * 1000;
+ if (!nanosleep(&ts,&ts)) return 0;
+ if (errno == EINTR) return ts.tv_sec;
+ return -1;
+}
+
+#endif
------------------------------------------------------------------------
2006-06-02 Shaun Jackman <sjackman@gmail.com>
* configure.host (newlib_cflags) [arm, thumb, xscale]: Add
-DHAVE_NANOSLEEP.
* libc/posix/Makefile.am (GENERAL_SOURCES): Add sleep.c and
usleep.c.
* libc/posix/Makefile.in: Regenerate.
* libc/posix/sleep.c: New file.
* libc/posix/usleep.c: Ditto.
Index: configure.host
===================================================================
RCS file: /cvs/src/src/newlib/configure.host,v
retrieving revision 1.81
diff -u -r1.81 configure.host
--- configure.host 13 Apr 2006 19:56:23 -0000 1.81
+++ configure.host 2 Jun 2006 15:17:55 -0000
@@ -514,7 +514,7 @@
;;
arm-*-*)
syscall_dir=syscalls
- newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY"
+ newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY -DHAVE_NANOSLEEP"
# If newlib is supplying syscalls, select which debug protocol is being used.
# ARM_RDP_MONITOR selects the Demon monitor.
# ARM_RDI_MONITOR selects the Angel monitor.
@@ -669,7 +669,7 @@
;;
thumb-*-*)
syscall_dir=syscalls
- newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY"
+ newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY -DHAVE_NANOSLEEP"
# If newlib is supplying syscalls, select which debug protocol is being used.
# ARM_RDP_MONITOR selects the Demon monitor.
# ARM_RDI_MONITOR selects the Angel monitor.
@@ -700,7 +700,7 @@
;;
xscale-*-*)
syscall_dir=syscalls
- newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY"
+ newlib_cflags="${newlib_cflags} -DABORT_PROVIDED -DHAVE_GETTIMEOFDAY -DHAVE_NANOSLEEP"
newlib_cflags="${newlib_cflags} -DHAVE_SYSTEM -DHAVE_RENAME"
if [ "x${newlib_may_supply_syscalls}" = "xyes" ] ; then
newlib_cflags="${newlib_cflags} -DARM_RDI_MONITOR"
Index: libc/posix/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/posix/Makefile.am,v
retrieving revision 1.6
diff -u -r1.6 Makefile.am
--- libc/posix/Makefile.am 1 May 2006 22:01:02 -0000 1.6
+++ libc/posix/Makefile.am 2 Jun 2006 15:19:22 -0000
@@ -7,7 +7,8 @@
GENERAL_SOURCES = \
closedir.c creat.c isatty.c \
opendir.c readdir.c \
- readdir_r.c rewinddir.c telldir.c
+ readdir_r.c rewinddir.c sleep.c usleep.c \
+ telldir.c
ELIX_2_SOURCES = \
scandir.c seekdir.c
--- /dev/null 2006-05-29 10:11:53.893844952 -0600
+++ libc/posix/sleep.c 2006-06-02 09:14:18.000000000 -0600
@@ -0,0 +1,22 @@
+/* libc/posix/sleep.c - sleep function */
+
+/* Written 2000 by Werner Almesberger */
+
+#ifdef HAVE_NANOSLEEP
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+unsigned sleep(unsigned seconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = seconds;
+ ts.tv_nsec = 0;
+ if (!nanosleep(&ts,&ts)) return 0;
+ if (errno == EINTR) return ts.tv_sec;
+ return -1;
+}
+
+#endif
--- /dev/null 2006-05-29 10:11:53.893844952 -0600
+++ libc/posix/usleep.c 2006-06-02 09:14:30.000000000 -0600
@@ -0,0 +1,22 @@
+/* libc/posix/usleep.c - usleep function */
+
+/* Written 2002 by Jeff Johnston */
+
+#ifdef HAVE_NANOSLEEP
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+int usleep(useconds_t useconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = (long int)useconds / 1000000;
+ ts.tv_nsec = ((long int)useconds % 1000000) * 1000;
+ if (!nanosleep(&ts,&ts)) return 0;
+ if (errno == EINTR) return ts.tv_sec;
+ return -1;
+}
+
+#endif