1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03, c++11
14 // class shared_timed_mutex;
16 // template <class Clock, class Duration>
17 // shared_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
25 #include <shared_mutex>
28 #include "make_test_thread.h"
29 #include "test_macros.h"
31 std::shared_timed_mutex m
;
33 typedef std::chrono::steady_clock Clock
;
34 typedef Clock::time_point time_point
;
35 typedef Clock::duration duration
;
36 typedef std::chrono::milliseconds ms
;
37 typedef std::chrono::nanoseconds ns
;
39 ms LongTime
= ms(5000);
40 ms ShortTime
= ms(50);
42 static constexpr unsigned Threads
= 5;
44 std::atomic
<unsigned> CountDown(Threads
);
49 time_point t0
= Clock::now();
50 std::shared_lock
<std::shared_timed_mutex
> lk(m
, t0
+ LongTime
);
51 time_point t1
= Clock::now();
52 assert(lk
.owns_lock() == true);
53 assert(t1
- t0
<= LongTime
);
58 time_point t0
= Clock::now();
59 std::shared_lock
<std::shared_timed_mutex
> lk(m
, t0
+ ShortTime
);
60 time_point t1
= Clock::now();
61 assert(lk
.owns_lock() == false);
62 assert(t1
- t0
>= ShortTime
);
69 std::vector
<std::thread
> v
;
70 for (unsigned i
= 0; i
< Threads
; ++i
)
71 v
.push_back(support::make_test_thread(f1
));
73 std::this_thread::yield();
74 std::this_thread::sleep_for(ShortTime
);
81 std::vector
<std::thread
> v
;
82 for (unsigned i
= 0; i
< Threads
; ++i
)
83 v
.push_back(support::make_test_thread(f2
));