Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/gettime.c @ 5662:42df9db003cc
* modules/gethrxtime: New file.
* modules/xnanosleep (Files): Add m4/xnanosleep.m4.
(Depends-on): Add gethrxtime.
(configure.ac): Add gl_XNANOSLEEP.
(Makefile.am): Remove lib_SOURCES line.
* lib/gethrxtime.h, lib/gethrxtime.c, lib/xtime.h: New files.
* lib/timespec.h (gettime): Return void, since it always
succeeds now. All uses changed.
* lib/gettime.c (gettime) Likewise.
[HAVE_NANOTIME]: Prefer nanotime.
Assume gettimeofday succeeds, as POSIX requires.
Assime time () succeeds, since other code already does.
* lib/xnanosleep.c: Include xtime.h and gethrxtime.h, not xalloc.h.
(timespec_subtract): Remove.
(NANOSLEEP_BUG_WORKAROUND): New constant.
(xnanosleep): Use gethrxtime rather than gettime; this simplifies
things considerably. Use it only on GNU/Linux hosts, since the
workaround shouldn't be needed elsewhere.
* m4/gethrxtime.m4, m4/xnanosleep.m4: New files.
* m4/gettime.m4 (gl_GETTIME): Check for nanotime.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sat, 26 Feb 2005 08:18:27 +0000 |
parents | eb3efcec6ae2 |
children | a48fb0e98c8c |
rev | line source |
---|---|
3768 | 1 /* gettime -- get the system clock |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
2 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. |
3768 | 3 |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2, or (at your option) | |
7 any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software Foundation, | |
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
17 | |
18 /* Written by Paul Eggert. */ | |
19 | |
20 #ifdef HAVE_CONFIG_H | |
21 # include <config.h> | |
22 #endif | |
23 | |
24 #include "timespec.h" | |
25 | |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
26 /* Get the system time into *TS. */ |
3768 | 27 |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
28 void |
3768 | 29 gettime (struct timespec *ts) |
30 { | |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
31 #if HAVE_NANOTIME |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
32 nanotime (ts); |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
33 #else |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
34 |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
35 # if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME |
3768 | 36 if (clock_gettime (CLOCK_REALTIME, ts) == 0) |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
37 return; |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
38 # endif |
3768 | 39 |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
40 # if HAVE_GETTIMEOFDAY |
3768 | 41 { |
42 struct timeval tv; | |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
43 gettimeofday (&tv, NULL); |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
44 ts->tv_sec = tv.tv_sec; |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
45 ts->tv_nsec = tv.tv_usec * 1000; |
3768 | 46 } |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
47 # else |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
48 ts->tv_sec = time (NULL); |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
49 ts->tv_nsec = 0; |
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
50 # endif |
5059
eb3efcec6ae2
Don't assume that gettimeofday and settimeofday exist or work.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3774
diff
changeset
|
51 |
5662
42df9db003cc
* modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5059
diff
changeset
|
52 #endif |
3768 | 53 } |