source: trunk/sys/libgomp/time.c @ 155

Last change on this file since 155 was 1, checked in by alain, 8 years ago

First import

File size: 2.3 KB
RevLine 
[1]1/* Copyright (C) 2005, 2009 Free Software Foundation, Inc.
2   Contributed by Richard Henderson <rth@redhat.com>.
3
4   This file is part of the GNU OpenMP Library (libgomp).
5
6   Libgomp is free software; you can redistribute it and/or modify it
7   under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 3, or (at your option)
9   any later version.
10
11   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14   more details.
15
16   Under Section 7 of GPL version 3, you are granted additional
17   permissions described in the GCC Runtime Library Exception, version
18   3.1, as published by the Free Software Foundation.
19
20   You should have received a copy of the GNU General Public License and
21   a copy of the GCC Runtime Library Exception along with this program;
22   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23   <http://www.gnu.org/licenses/>.  */
24
25/* This file contains system specific timer routines.  It is expected that
26   a system may well want to write special versions of each of these.
27
28   The following implementation uses the most simple POSIX routines.
29   If present, POSIX 4 clocks should be used instead.  */
30
31#include <gomp/libgomp.h>
32#include <unistd.h>
33#if TIME_WITH_SYS_TIME
34# include <sys/time.h>
35# include <time.h>
36#else
37# if HAVE_SYS_TIME_H
38#  include <sys/time.h>
39# else
40#  include <time.h>
41# endif
42#endif
43
44/* TODO: implements tv */
45double
46omp_get_wtime (void)
47{
48#ifdef HAVE_CLOCK_GETTIME
49  struct timespec ts;
50# ifdef CLOCK_MONOTONIC
51  if (clock_gettime (CLOCK_MONOTONIC, &ts) < 0)
52# endif
53    clock_gettime (CLOCK_REALTIME, &ts);
54  return ts.tv_sec + ts.tv_nsec / 1e9;
55#else
56  #ifndef _ALMOS_
57  struct timeval tv;
58  gettimeofday (&tv, NULL);
59  return tv.tv_sec + tv.tv_usec / 1e6;
60  #else
61  return clock();
62  #endif
63#endif
64}
65
66double
67omp_get_wtick (void)
68{
69#ifdef HAVE_CLOCK_GETTIME
70  struct timespec ts;
71# ifdef CLOCK_MONOTONIC
72  if (clock_getres (CLOCK_MONOTONIC, &ts) < 0)
73# endif
74    clock_getres (CLOCK_REALTIME, &ts);
75  return ts.tv_sec + ts.tv_nsec / 1e9;
76#else
77  return 1.0 / sysconf(_SC_CLK_TCK);
78#endif
79}
80
81ialias (omp_get_wtime)
82ialias (omp_get_wtick)
Note: See TracBrowser for help on using the repository browser.