diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-07-15 23:23:23 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-07-15 23:23:23 +0000 |
commit | 4971b9a8ba2016e1a41927b250e8802eb0787769 (patch) | |
tree | eafc38353a48e1cd63e574edc380874a144179ef /libstdc++-v3/src/chrono.cc | |
parent | 94b087ba5bc98e2c9ff01f73018281c3c47e45f3 (diff) | |
download | gcc-4971b9a8ba2016e1a41927b250e8802eb0787769.tar.gz |
2008-07-15 Chris Fairles <chris.fairles@gmail.com>
* include/std/chrono: New, as per N2661.
* src/chrono.cc: New.
* include/Makefile.am: Update.
* src/Makefile.am: Likewise.
* include/Makefile.in: Regenerate.
* src/Makefile.in: Likewise.
* acinclude.m4: Add tests for clock_gettime and gettimeofday that
define _GLIBCXX_HAS_CLOCK_GETTIME and/or _GLIBCXX_HAS_GETTIMEOFDAY.
* configure.ac: Use them.
* configure: Regenerate.
* config.h.in: Likewise.
* config/abi/pre/gnu.ver: Add symbols for system_clock::now() and
system_clock::is_monotonic.
* testsuite/20_util/duration/cons/1.cc: New.
* testsuite/20_util/duration/cons/2.cc: Likewise.
* testsuite/20_util/duration/cons/1_neg.cc: Likewise.
* testsuite/20_util/duration/requirements/explicit_instantiation/
explicit_instantiation.cc: Likewise.
* testsuite/20_util/duration/arithmetic/1.cc: Likewise.
* testsuite/20_util/duration/arithmetic/2.cc: Likewise.
* testsuite/20_util/duration/comparisons/1.cc: Likewise.
* testsuite/20_util/time_point/requirements/explicit_instantiation/
explicit_instantiation.cc: Likewise.
* testsuite/20_util/time_point/1.cc: Likewise.
* testsuite/20_util/time_point/2.cc: Likewise.
* testsuite/20_util/time_point/3.cc: Likewise.
* testsuite/20_util/clocks/1.cc: Likewise.
* testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc: Add
missing headers.
* testsuite/17_intro/headers/c++200x/all.cc: Likewise.
* include/precompiled/stdc++.h: Likewise and remove <date_time>.
* doc/doxygen/user.cfg.in: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@137858 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/src/chrono.cc')
-rw-r--r-- | libstdc++-v3/src/chrono.cc | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/libstdc++-v3/src/chrono.cc b/libstdc++-v3/src/chrono.cc new file mode 100644 index 00000000000..88fb4c180e9 --- /dev/null +++ b/libstdc++-v3/src/chrono.cc @@ -0,0 +1,76 @@ +// chrono -*- C++ -*- + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This 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 General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include <chrono> + +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 + +// conditional inclusion of sys/time.h for gettimeofday +#if !defined(_GLIBCXX_USE_CLOCK_MONOTONIC) && \ + !defined(_GLIBCXX_USE_CLOCK_REALTIME) && \ + defined(_GLIBCXX_USE_GETTIMEOFDAY) +#include <sys/time.h> +#endif + +namespace std +{ + namespace chrono + { + const bool system_clock::is_monotonic; + + system_clock::time_point + system_clock::now() + { +#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC + timespec tp; + // -EINVAL, -EFAULT + clock_gettime(CLOCK_MONOTONIC, &tp); + return time_point(duration(chrono::seconds(tp.tv_sec) + + chrono::nanoseconds(tp.tv_nsec))); +#elif defined(_GLIBCXX_USE_CLOCK_REALTIME) + timespec tp; + // -EINVAL, -EFAULT + clock_gettime(CLOCK_REALTIME, &tp); + return time_point(duration(chrono::seconds(tp.tv_sec) + + chrono::nanoseconds(tp.tv_nsec))); +#elif defined(_GLIBCXX_USE_GETTIMEOFDAY) + timeval tv; + // EINVAL, EFAULT + gettimeofday(&tv, NULL); + return time_point(duration(chrono::seconds(tv.tv_sec) + + chrono::microseconds(tv.tv_usec))); +#else + std::time_t __sec = std::time(0); + return system_clock::from_time_t(__sec); +#endif + } + } +} + +#endif // _GLIBCXX_USE_C99_STDINT_TR1 |