From 74033a2507841cf077e31221de2481ff30b43d51 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 24 Dec 2011 00:40:15 -0500 Subject: [PATCH] Implement timespec_get --- ChangeLog | 9 +++ NEWS | 3 +- sysdeps/unix/sysv/linux/timespec_get.c | 57 +++++++++++++++++++ sysdeps/unix/sysv/linux/x86_64/timespec_get.c | 10 ++++ time/Makefile | 5 +- time/Versions | 3 + time/time.h | 43 +++++++++----- time/timespec_get.c | 40 +++++++++++++ 8 files changed, 154 insertions(+), 16 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/timespec_get.c create mode 100644 sysdeps/unix/sysv/linux/x86_64/timespec_get.c create mode 100644 time/timespec_get.c diff --git a/ChangeLog b/ChangeLog index c75d829875..7ad4272f4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,15 @@ 2011-12-23 Ulrich Drepper + [BZ #13532] + * time/Makefile (routines): Add timespec_get. + * time/Versions: Export timespec_get from libc for GLIBC_2.16. + * time/time.h: Define TIME_UTC and declare timespec_get. Define + timespec for ISO C11. + * time/timespec_get.c: New file. + * sysdeps/unix/sysv/linux/timespec_get.c: New file. + * sysdeps/unix/sysv/linux/x86_64/timespec_get.c: New file. + [BZ #13531] * malloc/malloc.c: Define alias aligned_alloc for public_mEMALIGn. * stdlib/stdlib.h: Declare aligned_alloc. diff --git a/NEWS b/NEWS index 43f02d9fd4..2d7a9df3d7 100644 --- a/NEWS +++ b/NEWS @@ -9,7 +9,7 @@ Version 2.16 * The following bugs are resolved with this release: - 13526, 13527, 13528, 13529, 13531 + 13526, 13527, 13528, 13529, 13531, 13532 * ISO C11 support: @@ -24,6 +24,7 @@ Version 2.16 in the standard but it is only a requirement on the caller, not the implementation. + + timespec_get added Version 2.15 diff --git a/sysdeps/unix/sysv/linux/timespec_get.c b/sysdeps/unix/sysv/linux/timespec_get.c new file mode 100644 index 0000000000..5d5bc3ea62 --- /dev/null +++ b/sysdeps/unix/sysv/linux/timespec_get.c @@ -0,0 +1,57 @@ +/* Copyright (C) 2011 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. + + 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 +#include +#include + +#ifndef HAVE_CLOCK_GETTIME_VSYSCALL +# undef INTERNAL_VSYSCALL +# define INTERNAL_VSYSCALL INTERNAL_SYSCALL +#else +# include +#endif + +#ifndef INTERNAL_GETTIME +# define INTERNAL_GETTIME(id, tp) \ + INTERNAL_VSYSCALL (clock_gettime, err, 2, id, tp) +#endif + + +/* Set TS to calendar time based in time base BASE. */ +int +timespec_get (ts, base) + struct timespec *ts; + int base; +{ + switch (base) + { + int res; + INTERNAL_SYSCALL_DECL (err); + case TIME_UTC: + res = INTERNAL_GETTIME (CLOCK_REALTIME, ts); + if (INTERNAL_SYSCALL_ERROR_P (res, err)) + return 0; + break; + + default: + return 0; + } + + return base; +} diff --git a/sysdeps/unix/sysv/linux/x86_64/timespec_get.c b/sysdeps/unix/sysv/linux/x86_64/timespec_get.c new file mode 100644 index 0000000000..cb26068147 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86_64/timespec_get.c @@ -0,0 +1,10 @@ +#include "bits/libc-vdso.h" + +#ifdef SHARED +# define INTERNAL_GETTIME(id, tp) \ + ({ long int (*f) (clockid_t, struct timespec *) = __vdso_clock_gettime; \ + PTR_DEMANGLE (f); \ + f (id, tp); }) +#endif + +#include "../timespec_get.c" diff --git a/time/Makefile b/time/Makefile index 71d919d015..badf2f984d 100644 --- a/time/Makefile +++ b/time/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1991-2003, 2004, 2005, 2007 Free Software Foundation, Inc. +# Copyright (C) 1991-2003, 2004, 2005, 2007, 2011 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 @@ -29,7 +29,8 @@ routines := offtime asctime clock ctime ctime_r difftime \ tzfile getitimer setitimer \ stime dysize timegm ftime \ getdate strptime strptime_l \ - strftime wcsftime strftime_l wcsftime_l + strftime wcsftime strftime_l wcsftime_l \ + timespec_get aux := era alt_digit lc-time-cleanup distribute := datemsk diff --git a/time/Versions b/time/Versions index 273956d5f3..a7c263008c 100644 --- a/time/Versions +++ b/time/Versions @@ -62,4 +62,7 @@ libc { GLIBC_2.3.2 { strptime_l; } + GLIBC_2.16 { + timespec_get; + } } diff --git a/time/time.h b/time/time.h index fee8d27052..5cb19db29d 100644 --- a/time/time.h +++ b/time/time.h @@ -107,10 +107,11 @@ typedef __timer_t timer_t; #undef __need_timer_t -#if !defined __timespec_defined && \ - ((defined _TIME_H && \ - (defined __USE_POSIX199309 || defined __USE_MISC)) || \ - defined __need_timespec) +#if (!defined __timespec_defined \ + && ((defined _TIME_H \ + && (defined __USE_POSIX199309 || defined __USE_MISC \ + || defined __USE_ISOC11)) \ + || defined __need_timespec)) # define __timespec_defined 1 # include /* This defines __time_t for us. */ @@ -142,13 +143,13 @@ struct tm int tm_yday; /* Days in year.[0-365] */ int tm_isdst; /* DST. [-1/0/1]*/ -#ifdef __USE_BSD +# ifdef __USE_BSD long int tm_gmtoff; /* Seconds east of UTC. */ __const char *tm_zone; /* Timezone abbreviation. */ -#else +# else long int __tm_gmtoff; /* Seconds east of UTC. */ __const char *__tm_zone; /* Timezone abbreviation. */ -#endif +# endif }; __END_NAMESPACE_STD #if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC @@ -156,7 +157,7 @@ __USING_NAMESPACE_STD(tm) #endif -#ifdef __USE_POSIX199309 +# ifdef __USE_POSIX199309 /* POSIX.1b structure for timer start values and intervals. */ struct itimerspec { @@ -167,14 +168,23 @@ struct itimerspec /* We can use a simple forward declaration. */ struct sigevent; -#endif /* POSIX.1b */ +# endif /* POSIX.1b */ -#ifdef __USE_XOPEN2K -# ifndef __pid_t_defined +# ifdef __USE_XOPEN2K +# ifndef __pid_t_defined typedef __pid_t pid_t; -# define __pid_t_defined +# define __pid_t_defined +# endif +# endif + + +# ifdef __USE_ISOC11 +/* Time base values for timespec_get. */ +enum + { + TIME_UTC = 1 + }; # endif -#endif __BEGIN_NAMESPACE_STD @@ -353,6 +363,13 @@ extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __THROW; # endif +# ifdef __USE_ISOC11 +/* Set TS to calendar time based in time base BASE. */ +extern int timespec_get (struct timespec *__ts, int __base) + __THROW __nonnull ((1)); +# endif + + /* Create new per-process timer using CLOCK_ID. */ extern int timer_create (clockid_t __clock_id, struct sigevent *__restrict __evp, diff --git a/time/timespec_get.c b/time/timespec_get.c new file mode 100644 index 0000000000..05009ec11b --- /dev/null +++ b/time/timespec_get.c @@ -0,0 +1,40 @@ +/* Copyright (C) 2011 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. + + 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 + + +/* Set TS to calendar time based in time base BASE. */ +int +timespec_get (ts, base) + struct timespec *ts; + int base; +{ + switch (base) + { + case TIME_UTC: + /* Not supported. */ + return 0; + + default: + return 0; + } + + return base; +} +stub_warning (timespec_get)