summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authormarcus <marcus>2005-01-30 23:26:43 +0000
committermarcus <marcus>2005-01-30 23:26:43 +0000
commit0770fbe0b7f4400a3ac2697b29d92be09b5bf20b (patch)
tree0785238fb5806f2ba7d0d964c02fa5e73eee5a76 /libc
parent898036124a031471d9a77f07a267945ef6c98df5 (diff)
2005-01-30 Marcus Brinkmann <marcus@gnu.org>
* hurd-l4/sysdeps/l4/gettimeofday.c, hurd-l4/sysdeps/l4/nanosleep.c, hurd-l4/sysdeps/l4/sleep.c, hurd-l4/sysdeps/l4/sched_yield.c, hurd-l4/sysdeps/l4/usleep.c: New files.
Diffstat (limited to 'libc')
-rw-r--r--libc/ChangeLog5
-rw-r--r--libc/hurd-l4/sysdeps/l4/gettimeofday.c51
-rw-r--r--libc/hurd-l4/sysdeps/l4/nanosleep.c66
-rw-r--r--libc/hurd-l4/sysdeps/l4/sched_yield.c34
-rw-r--r--libc/hurd-l4/sysdeps/l4/sleep.c53
-rw-r--r--libc/hurd-l4/sysdeps/l4/usleep.c32
6 files changed, 241 insertions, 0 deletions
diff --git a/libc/ChangeLog b/libc/ChangeLog
index 6129060..d49d141 100644
--- a/libc/ChangeLog
+++ b/libc/ChangeLog
@@ -1,5 +1,10 @@
2005-01-30 Marcus Brinkmann <marcus@gnu.org>
+ * hurd-l4/sysdeps/l4/gettimeofday.c,
+ hurd-l4/sysdeps/l4/nanosleep.c, hurd-l4/sysdeps/l4/sleep.c,
+ hurd-l4/sysdeps/l4/sched_yield.c, hurd-l4/sysdeps/l4/usleep.c:
+ New files.
+
* hurd-l4/sysdeps/l4/hurd/read.c: New file.
* hurd-l4/sysdeps/l4/hurd/write.c: New file.
diff --git a/libc/hurd-l4/sysdeps/l4/gettimeofday.c b/libc/hurd-l4/sysdeps/l4/gettimeofday.c
new file mode 100644
index 0000000..b4975ee
--- /dev/null
+++ b/libc/hurd-l4/sysdeps/l4/gettimeofday.c
@@ -0,0 +1,51 @@
+/* Copyright (C) 1991,1992,1995-1997,2001,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <l4.h>
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/time.h>
+
+#undef __gettimeofday
+
+/* Get the current time of day and timezone information,
+ putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
+ Returns 0 on success, -1 on errors. */
+int
+__gettimeofday (tv, tz)
+ struct timeval *tv;
+ struct timezone *tz;
+{
+ l4_clock_t clock;
+
+ /* FIXME: Add support for timezones. */
+ if (tz != NULL)
+ *tz = (struct timezone) { 0, 0 };
+
+ /* FIXME: This is not the wall clock, but has an arbitrary base. */
+ clock = l4_system_clock ();
+
+ tv->tv_sec = clock / (1000 * 1000);
+ tv->tv_usec = clock % (1000 * 1000);
+
+ return 0;
+}
+
+INTDEF(__gettimeofday)
+weak_alias (__gettimeofday, gettimeofday)
diff --git a/libc/hurd-l4/sysdeps/l4/nanosleep.c b/libc/hurd-l4/sysdeps/l4/nanosleep.c
new file mode 100644
index 0000000..616d35e
--- /dev/null
+++ b/libc/hurd-l4/sysdeps/l4/nanosleep.c
@@ -0,0 +1,66 @@
+/* nanosleep.c - Sleep for a period specified with a struct timespec.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <l4.h>
+
+#include <errno.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+
+/* Pause execution for a number of nanoseconds. */
+int
+__nanosleep (const struct timespec *requested_time,
+ struct timespec *remaining_time)
+{
+ struct timeval before;
+ struct timeval after;
+ l4_uint64_t usecs;
+
+ usecs = requested_time->tv_sec;
+ usecs = usecs * 1000 * 1000;
+ usecs = usecs + (((l4_uint64_t) requested_time->tv_nsec) + 999) / 1000;
+
+ if (remaining_time && __gettimeofday (&before, NULL) < 0)
+ return -1;
+ l4_sleep (usecs);
+ if (remaining_time && __gettimeofday (&after, NULL) < 0)
+ return -1;
+
+ if (remaining_time)
+ {
+ struct timeval requested;
+ struct timeval elapsed;
+ struct timeval remaining;
+
+ TIMESPEC_TO_TIMEVAL (&requested, requested_time);
+
+ timersub (&after, &before, &elapsed);
+ if (timercmp (&requested, &elapsed, <))
+ timerclear (&remaining);
+ else
+ timersub (&requested, &elapsed, &remaining);
+
+ TIMEVAL_TO_TIMESPEC (&remaining, remaining_time);
+ }
+
+ return 0;
+}
+libc_hidden_def (__nanosleep)
+weak_alias (__nanosleep, nanosleep)
diff --git a/libc/hurd-l4/sysdeps/l4/sched_yield.c b/libc/hurd-l4/sysdeps/l4/sched_yield.c
new file mode 100644
index 0000000..a0b3860
--- /dev/null
+++ b/libc/hurd-l4/sysdeps/l4/sched_yield.c
@@ -0,0 +1,34 @@
+/* sched_yield.c - Yield the processor. L4 version.
+ Copyright (C) 2000, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <l4.h>
+
+#include <errno.h>
+#include <sched.h>
+
+
+/* Yield the processor. */
+int
+__sched_yield (void)
+{
+ l4_yield ();
+
+ return 0;
+}
+weak_alias (__sched_yield, sched_yield)
diff --git a/libc/hurd-l4/sysdeps/l4/sleep.c b/libc/hurd-l4/sysdeps/l4/sleep.c
new file mode 100644
index 0000000..f3abc01
--- /dev/null
+++ b/libc/hurd-l4/sysdeps/l4/sleep.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 1992, 1993, 1994, 1997, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <l4.h>
+
+#include <signal.h>
+#include <time.h>
+#include <unistd.h>
+
+
+/* Make the process sleep for SECONDS seconds, or until a signal arrives
+ and is not ignored. The function returns the number of seconds less
+ than SECONDS which it actually slept (zero if it slept the full time).
+ There is no return value to indicate error, but if `sleep' returns
+ SECONDS, it probably didn't work. */
+unsigned int
+__sleep (unsigned int seconds)
+{
+ time_t before, after;
+ unsigned int elapsed;
+ l4_uint64_t usecs;
+ l4_time_t period;
+
+ usecs = seconds;
+ usecs = usecs * 1000 * 1000;
+ period = l4_time_period (usecs);
+
+ before = time ((time_t *) NULL);
+ /* FIXME: This can return before the time elapsed even if we are not
+ interrupted, in case the cpu clock is fast. */
+ l4_sleep (period);
+ after = time ((time_t *) NULL);
+
+ elapsed = after - before;
+
+ return elapsed > seconds ? 0 : seconds - elapsed;
+}
+weak_alias (__sleep, sleep)
diff --git a/libc/hurd-l4/sysdeps/l4/usleep.c b/libc/hurd-l4/sysdeps/l4/usleep.c
new file mode 100644
index 0000000..fd1070a
--- /dev/null
+++ b/libc/hurd-l4/sysdeps/l4/usleep.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1992,93,94,97,98,99, 2001, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <l4.h>
+
+#include <errno.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+/* Sleep USECONDS microseconds, or until a previously set timer goes off. */
+int
+usleep (useconds_t useconds)
+{
+ l4_sleep (useconds);
+
+ return 0;
+}