mirror of git://gcc.gnu.org/git/gcc.git
chrono: (system_clock::is_steady): Update to N3291 from is_monotonic.
2011-07-20 Benjamin Kosnik <bkoz@redhat.com> Daniel Krugler <daniel.kruegler@googlemail.com> * include/std/chrono: (system_clock::is_steady): Update to N3291 from is_monotonic. (time_point): Add constexpr to nonmember arithmetic operators. * src/chrono.cc: Modify for above. * src/compatibility-c++0x.cc: Same. * testsuite/20_util/time_point/nonmember/constexpr.cc: New. * testsuite/20_util/time_point/1.cc: Modify. * testsuite/20_util/system_clock/constexpr_data.cc: Modify. * testsuite/20_util/system_clock/1.cc: Modify. * testsuite/20_util/monotonic_clock/constexpr_data.cc: Move to... * testsuite/20_util/steady_clock/constexpr_data.cc: ...here. * testsuite/30_threads/condition_variable/members/2.cc: Modify. * testsuite/30_threads/condition_variable_any/members/2.cc: Modify. From-SVN: r176549
This commit is contained in:
parent
e56925329c
commit
1b97ec17bc
|
@ -1,3 +1,20 @@
|
||||||
|
2011-07-20 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
Daniel Krugler <daniel.kruegler@googlemail.com>
|
||||||
|
|
||||||
|
* include/std/chrono: (system_clock::is_steady): Update to N3291
|
||||||
|
from is_monotonic.
|
||||||
|
(time_point): Add constexpr to nonmember arithmetic operators.
|
||||||
|
* src/chrono.cc: Modify for above.
|
||||||
|
* src/compatibility-c++0x.cc: Same.
|
||||||
|
* testsuite/20_util/time_point/nonmember/constexpr.cc: New.
|
||||||
|
* testsuite/20_util/time_point/1.cc: Modify.
|
||||||
|
* testsuite/20_util/system_clock/constexpr_data.cc: Modify.
|
||||||
|
* testsuite/20_util/system_clock/1.cc: Modify.
|
||||||
|
* testsuite/20_util/monotonic_clock/constexpr_data.cc: Move to...
|
||||||
|
* testsuite/20_util/steady_clock/constexpr_data.cc: ...here.
|
||||||
|
* testsuite/30_threads/condition_variable/members/2.cc: Modify.
|
||||||
|
* testsuite/30_threads/condition_variable_any/members/2.cc: Modify.
|
||||||
|
|
||||||
2011-07-20 Paolo Carlini <paolo.carlini@oracle.com>
|
2011-07-20 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
* include/std/system_error: Use noexcept.
|
* include/std/system_error: Use noexcept.
|
||||||
|
|
|
@ -585,7 +585,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
|
||||||
|
|
||||||
template<typename _Clock, typename _Dur1,
|
template<typename _Clock, typename _Dur1,
|
||||||
typename _Rep2, typename _Period2>
|
typename _Rep2, typename _Period2>
|
||||||
inline time_point<_Clock,
|
inline constexpr time_point<_Clock,
|
||||||
typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
|
typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
|
||||||
operator+(const time_point<_Clock, _Dur1>& __lhs,
|
operator+(const time_point<_Clock, _Dur1>& __lhs,
|
||||||
const duration<_Rep2, _Period2>& __rhs)
|
const duration<_Rep2, _Period2>& __rhs)
|
||||||
|
@ -593,27 +593,37 @@ _GLIBCXX_END_NAMESPACE_VERSION
|
||||||
typedef duration<_Rep2, _Period2> __dur2;
|
typedef duration<_Rep2, _Period2> __dur2;
|
||||||
typedef typename common_type<_Dur1,__dur2>::type __ct;
|
typedef typename common_type<_Dur1,__dur2>::type __ct;
|
||||||
typedef time_point<_Clock, __ct> __time_point;
|
typedef time_point<_Clock, __ct> __time_point;
|
||||||
return __time_point(__lhs) += __rhs;
|
return __time_point(__lhs.time_since_epoch() + __rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename _Rep1, typename _Period1,
|
template<typename _Rep1, typename _Period1,
|
||||||
typename _Clock, typename _Dur2>
|
typename _Clock, typename _Dur2>
|
||||||
inline time_point<_Clock,
|
inline constexpr time_point<_Clock,
|
||||||
typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
|
typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
|
||||||
operator+(const duration<_Rep1, _Period1>& __lhs,
|
operator+(const duration<_Rep1, _Period1>& __lhs,
|
||||||
const time_point<_Clock, _Dur2>& __rhs)
|
const time_point<_Clock, _Dur2>& __rhs)
|
||||||
{ return __rhs + __lhs; }
|
{
|
||||||
|
typedef duration<_Rep1, _Period1> __dur1;
|
||||||
|
typedef typename common_type<__dur1,_Dur2>::type __ct;
|
||||||
|
typedef time_point<_Clock, __ct> __time_point;
|
||||||
|
return __time_point(__rhs.time_since_epoch() + __lhs);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename _Clock, typename _Dur1,
|
template<typename _Clock, typename _Dur1,
|
||||||
typename _Rep2, typename _Period2>
|
typename _Rep2, typename _Period2>
|
||||||
inline time_point<_Clock,
|
inline constexpr time_point<_Clock,
|
||||||
typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
|
typename common_type<_Dur1, duration<_Rep2, _Period2>>::type>
|
||||||
operator-(const time_point<_Clock, _Dur1>& __lhs,
|
operator-(const time_point<_Clock, _Dur1>& __lhs,
|
||||||
const duration<_Rep2, _Period2>& __rhs)
|
const duration<_Rep2, _Period2>& __rhs)
|
||||||
{ return __lhs + (-__rhs); }
|
{
|
||||||
|
typedef duration<_Rep2, _Period2> __dur2;
|
||||||
|
typedef typename common_type<_Dur1,__dur2>::type __ct;
|
||||||
|
typedef time_point<_Clock, __ct> __time_point;
|
||||||
|
return __time_point(__lhs.time_since_epoch() -__rhs);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename _Clock, typename _Dur1, typename _Dur2>
|
template<typename _Clock, typename _Dur1, typename _Dur2>
|
||||||
inline typename common_type<_Dur1, _Dur2>::type
|
inline constexpr typename common_type<_Dur1, _Dur2>::type
|
||||||
operator-(const time_point<_Clock, _Dur1>& __lhs,
|
operator-(const time_point<_Clock, _Dur1>& __lhs,
|
||||||
const time_point<_Clock, _Dur2>& __rhs)
|
const time_point<_Clock, _Dur2>& __rhs)
|
||||||
{ return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
|
{ return __lhs.time_since_epoch() - __rhs.time_since_epoch(); }
|
||||||
|
@ -673,7 +683,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
|
||||||
< system_clock::duration::zero(),
|
< system_clock::duration::zero(),
|
||||||
"a clock's minimum duration cannot be less than its epoch");
|
"a clock's minimum duration cannot be less than its epoch");
|
||||||
|
|
||||||
static constexpr bool is_monotonic = false;
|
static constexpr bool is_steady = false;
|
||||||
|
|
||||||
static time_point
|
static time_point
|
||||||
now() throw ();
|
now() throw ();
|
||||||
|
@ -696,21 +706,21 @@ _GLIBCXX_END_NAMESPACE_VERSION
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC
|
#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC
|
||||||
/// monotonic_clock
|
/// steady_clock
|
||||||
struct monotonic_clock
|
struct steady_clock
|
||||||
{
|
{
|
||||||
typedef chrono::nanoseconds duration;
|
typedef chrono::nanoseconds duration;
|
||||||
typedef duration::rep rep;
|
typedef duration::rep rep;
|
||||||
typedef duration::period period;
|
typedef duration::period period;
|
||||||
typedef chrono::time_point<monotonic_clock, duration> time_point;
|
typedef chrono::time_point<steady_clock, duration> time_point;
|
||||||
|
|
||||||
static constexpr bool is_monotonic = true;
|
static constexpr bool is_steady = true;
|
||||||
|
|
||||||
static time_point
|
static time_point
|
||||||
now();
|
now();
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
typedef system_clock monotonic_clock;
|
typedef system_clock steady_clock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef system_clock high_resolution_clock;
|
typedef system_clock high_resolution_clock;
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
{
|
{
|
||||||
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
|
|
||||||
constexpr bool system_clock::is_monotonic;
|
constexpr bool system_clock::is_steady;
|
||||||
|
|
||||||
system_clock::time_point
|
system_clock::time_point
|
||||||
system_clock::now() throw ()
|
system_clock::now() throw ()
|
||||||
|
@ -63,10 +63,10 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC
|
#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC
|
||||||
constexpr bool monotonic_clock::is_monotonic;
|
constexpr bool steady_clock::is_steady;
|
||||||
|
|
||||||
monotonic_clock::time_point
|
steady_clock::time_point
|
||||||
monotonic_clock::now()
|
steady_clock::now()
|
||||||
{
|
{
|
||||||
timespec tp;
|
timespec tp;
|
||||||
// -EINVAL, -EFAULT
|
// -EINVAL, -EFAULT
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Compatibility symbols for previous versions, C++0x bits -*- C++ -*-
|
// Compatibility symbols for previous versions, C++0x bits -*- C++ -*-
|
||||||
|
|
||||||
// Copyright (C) 2009, 2010 Free Software Foundation, Inc.
|
// Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// 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
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
@ -81,4 +81,17 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
const size_t __tmp = std::_Hash_impl::hash(__e._M_value);
|
const size_t __tmp = std::_Hash_impl::hash(__e._M_value);
|
||||||
return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp);
|
return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// gcc-4.7.0
|
||||||
|
// <chrono> changes is_monotonic to is_steady.
|
||||||
|
namespace chrono
|
||||||
|
{
|
||||||
|
struct system_clock
|
||||||
|
{
|
||||||
|
static constexpr bool is_monotonic = false;
|
||||||
|
};
|
||||||
|
constexpr bool system_clock::is_monotonic;
|
||||||
|
} // namespace chrono
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace __gnu_test
|
||||||
void __constraint()
|
void __constraint()
|
||||||
{
|
{
|
||||||
constexpr auto v1 __attribute__((unused))
|
constexpr auto v1 __attribute__((unused))
|
||||||
= _Ttesttype::is_monotonic;
|
= _Ttesttype::is_steady;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,6 +47,6 @@ namespace __gnu_test
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
__gnu_test::constexpr_member_data test;
|
__gnu_test::constexpr_member_data test;
|
||||||
test.operator()<std::chrono::monotonic_clock>();
|
test.operator()<std::chrono::steady_clock>();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
// { dg-options "-std=gnu++0x" }
|
// { dg-options "-std=gnu++0x" }
|
||||||
// { dg-require-cstdint "" }
|
// { dg-require-cstdint "" }
|
||||||
|
|
||||||
// Copyright (C) 2008, 2009, 2010 Free Software Foundation
|
// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// 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
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
@ -29,8 +29,8 @@ main()
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
system_clock::time_point t1 = system_clock::now();
|
system_clock::time_point t1 = system_clock::now();
|
||||||
bool is_monotonic = system_clock::is_monotonic;
|
bool is_steady = system_clock::is_steady;
|
||||||
is_monotonic = is_monotonic; // suppress unused warning
|
is_steady = is_steady; // suppress unused warning
|
||||||
std::time_t t2 = system_clock::to_time_t(t1);
|
std::time_t t2 = system_clock::to_time_t(t1);
|
||||||
system_clock::time_point t3 = system_clock::from_time_t(t2);
|
system_clock::time_point t3 = system_clock::from_time_t(t2);
|
||||||
t3 = t3; // suppress unused warning
|
t3 = t3; // suppress unused warning
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// { dg-do compile }
|
// { dg-do compile }
|
||||||
// { dg-options "-std=gnu++0x" }
|
// { dg-options "-std=gnu++0x" }
|
||||||
|
|
||||||
// Copyright (C) 2010 Free Software Foundation, Inc.
|
// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// 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
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
@ -34,7 +34,7 @@ namespace __gnu_test
|
||||||
void __constraint()
|
void __constraint()
|
||||||
{
|
{
|
||||||
constexpr auto v1 __attribute__((unused))
|
constexpr auto v1 __attribute__((unused))
|
||||||
= _Ttesttype::is_monotonic;
|
= _Ttesttype::is_steady;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// { dg-options "-std=gnu++0x" }
|
// { dg-options "-std=gnu++0x" }
|
||||||
// { dg-require-cstdint "" }
|
// { dg-require-cstdint "" }
|
||||||
|
|
||||||
// Copyright (C) 2008, 2009 Free Software Foundation
|
// Copyright (C) 2008, 2009, 2011 Free Software Foundation
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// 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
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
@ -33,8 +33,8 @@ test01()
|
||||||
time_point<system_clock> t1;
|
time_point<system_clock> t1;
|
||||||
VERIFY(t1.time_since_epoch() == system_clock::duration::zero());
|
VERIFY(t1.time_since_epoch() == system_clock::duration::zero());
|
||||||
|
|
||||||
time_point<monotonic_clock> t2;
|
time_point<steady_clock> t2;
|
||||||
VERIFY(t2.time_since_epoch() == monotonic_clock::duration::zero());
|
VERIFY(t2.time_since_epoch() == steady_clock::duration::zero());
|
||||||
|
|
||||||
time_point<high_resolution_clock> t3;
|
time_point<high_resolution_clock> t3;
|
||||||
VERIFY(t3.time_since_epoch() == high_resolution_clock::duration::zero());
|
VERIFY(t3.time_since_epoch() == high_resolution_clock::duration::zero());
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
// { dg-do compile }
|
||||||
|
// { dg-options "-std=gnu++0x" }
|
||||||
|
|
||||||
|
// Copyright (C) 2011 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 3, 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 COPYING3. If not see
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
|
typedef time_point<system_clock> time_type;
|
||||||
|
|
||||||
|
constexpr time_type t1(seconds(1));
|
||||||
|
constexpr time_type t2(seconds(30));
|
||||||
|
constexpr time_type t3(seconds(60));
|
||||||
|
|
||||||
|
constexpr duration<int> d0(12);
|
||||||
|
constexpr duration<int> d1(3);
|
||||||
|
|
||||||
|
constexpr auto r1 = t1 + d0;
|
||||||
|
constexpr auto r2 = d1 + t2;
|
||||||
|
|
||||||
|
constexpr auto r3 = t1 - d0;
|
||||||
|
constexpr auto r4 = t2 - t3;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -5,7 +5,7 @@
|
||||||
// { dg-require-cstdint "" }
|
// { dg-require-cstdint "" }
|
||||||
// { dg-require-gthreads "" }
|
// { dg-require-gthreads "" }
|
||||||
|
|
||||||
// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
|
// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// 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
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
@ -38,10 +38,10 @@ void test01()
|
||||||
std::mutex m;
|
std::mutex m;
|
||||||
std::unique_lock<std::mutex> l(m);
|
std::unique_lock<std::mutex> l(m);
|
||||||
|
|
||||||
auto then = std::chrono::monotonic_clock::now();
|
auto then = std::chrono::steady_clock::now();
|
||||||
std::cv_status result = c1.wait_until(l, then + ms);
|
std::cv_status result = c1.wait_until(l, then + ms);
|
||||||
VERIFY( result == std::cv_status::timeout );
|
VERIFY( result == std::cv_status::timeout );
|
||||||
VERIFY( (std::chrono::monotonic_clock::now() - then) >= ms );
|
VERIFY( (std::chrono::steady_clock::now() - then) >= ms );
|
||||||
VERIFY( l.owns_lock() );
|
VERIFY( l.owns_lock() );
|
||||||
}
|
}
|
||||||
catch (const std::system_error& e)
|
catch (const std::system_error& e)
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// { dg-require-cstdint "" }
|
// { dg-require-cstdint "" }
|
||||||
// { dg-require-gthreads "" }
|
// { dg-require-gthreads "" }
|
||||||
|
|
||||||
// Copyright (C) 2010 Free Software Foundation, Inc.
|
// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// 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
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
@ -63,10 +63,10 @@ void test01()
|
||||||
Mutex m;
|
Mutex m;
|
||||||
m.lock();
|
m.lock();
|
||||||
|
|
||||||
auto then = std::chrono::monotonic_clock::now();
|
auto then = std::chrono::steady_clock::now();
|
||||||
std::cv_status result = c1.wait_until(m, then + ms);
|
std::cv_status result = c1.wait_until(m, then + ms);
|
||||||
VERIFY( result == std::cv_status::timeout );
|
VERIFY( result == std::cv_status::timeout );
|
||||||
VERIFY( (std::chrono::monotonic_clock::now() - then) >= ms );
|
VERIFY( (std::chrono::steady_clock::now() - then) >= ms );
|
||||||
VERIFY( m.locked );
|
VERIFY( m.locked );
|
||||||
}
|
}
|
||||||
catch (const std::system_error& e)
|
catch (const std::system_error& e)
|
||||||
|
|
Loading…
Reference in New Issue