Implement timespec_get

This commit is contained in:
Ulrich Drepper 2011-12-24 00:40:15 -05:00
parent 380d7e87dc
commit 74033a2507
8 changed files with 154 additions and 16 deletions

View File

@ -28,6 +28,15 @@
2011-12-23 Ulrich Drepper <drepper@gmail.com>
[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.

3
NEWS
View File

@ -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

View File

@ -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 <time.h>
#include <sysdep.h>
#include <kernel-features.h>
#ifndef HAVE_CLOCK_GETTIME_VSYSCALL
# undef INTERNAL_VSYSCALL
# define INTERNAL_VSYSCALL INTERNAL_SYSCALL
#else
# include <bits/libc-vdso.h>
#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;
}

View File

@ -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"

View File

@ -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

View File

@ -62,4 +62,7 @@ libc {
GLIBC_2.3.2 {
strptime_l;
}
GLIBC_2.16 {
timespec_get;
}
}

View File

@ -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 <bits/types.h> /* This defines __time_t for us. */
@ -177,6 +178,15 @@ typedef __pid_t pid_t;
# endif
# ifdef __USE_ISOC11
/* Time base values for timespec_get. */
enum
{
TIME_UTC = 1
};
# endif
__BEGIN_NAMESPACE_STD
/* Time used by the program so far (user time + system time).
The result / CLOCKS_PER_SECOND is program time in seconds. */
@ -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,

40
time/timespec_get.c Normal file
View File

@ -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 <time.h>
/* 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)