]>
Commit | Line | Data |
---|---|---|
37d13ae6 | 1 | // { dg-do run { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-rtems* *-*-darwin* powerpc-ibm-aix* } } |
71c54f8e JW |
2 | // { dg-options "-pthread" { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* powerpc-ibm-aix* } } |
3 | // { dg-require-effective-target c++11 } | |
25e00ab6 | 4 | // { dg-require-cstdint "" } |
25e00ab6 | 5 | |
818ab71a | 6 | // Copyright (C) 2013-2016 Free Software Foundation, Inc. |
25e00ab6 JW |
7 | // |
8 | // This file is part of the GNU ISO C++ Library. This library is free | |
9 | // software; you can redistribute it and/or modify it under the | |
10 | // terms of the GNU General Public License as published by the | |
11 | // Free Software Foundation; either version 3, or (at your option) | |
12 | // any later version. | |
13 | ||
14 | // This library is distributed in the hope that it will be useful, | |
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | // GNU General Public License for more details. | |
18 | ||
19 | // You should have received a copy of the GNU General Public License along | |
20 | // with this library; see the file COPYING3. If not see | |
21 | // <http://www.gnu.org/licenses/>. | |
22 | ||
23 | #include <mutex> | |
24 | #include <chrono> | |
25 | #include <thread> | |
26 | #include <testsuite_hooks.h> | |
27 | ||
28 | // PR libstdc++/57641 | |
29 | ||
30 | namespace C = std::chrono; | |
31 | ||
32 | // custom clock with epoch 10s before system_clock's | |
33 | struct clock | |
34 | { | |
35 | typedef C::system_clock::rep rep; | |
36 | typedef C::system_clock::period period; | |
37 | typedef C::system_clock::duration duration; | |
38 | typedef C::time_point<clock> time_point; | |
39 | static constexpr bool is_steady = C::system_clock::is_steady; | |
40 | ||
41 | static time_point | |
42 | now() | |
43 | { | |
44 | auto sys_time = C::system_clock::now().time_since_epoch(); | |
45 | return time_point(sys_time + C::seconds(10)); | |
46 | } | |
47 | }; | |
48 | ||
49 | std::timed_mutex mx; | |
2d5e3740 | 50 | bool locked = false; |
25e00ab6 JW |
51 | |
52 | void f() | |
53 | { | |
2d5e3740 | 54 | locked = mx.try_lock_until(clock::now() + C::milliseconds(1)); |
25e00ab6 JW |
55 | } |
56 | ||
57 | int main() | |
58 | { | |
2d5e3740 | 59 | bool test __attribute__((unused)) = true; |
25e00ab6 JW |
60 | std::lock_guard<std::timed_mutex> l(mx); |
61 | auto start = C::system_clock::now(); | |
62 | std::thread t(f); | |
63 | t.join(); | |
64 | auto stop = C::system_clock::now(); | |
65 | VERIFY( (stop - start) < C::seconds(9) ); | |
2d5e3740 | 66 | VERIFY( !locked ); |
25e00ab6 | 67 | } |