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 // template <class Mutex> class shared_lock;
16 // template <class Clock, class Duration>
17 // bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
22 #include <shared_mutex>
23 #include <system_error>
25 #include "test_macros.h"
27 bool try_lock_until_called
= false;
31 template <class Clock
, class Duration
>
32 bool try_lock_shared_until(const std::chrono::time_point
<Clock
, Duration
>& abs_time
)
34 typedef std::chrono::milliseconds ms
;
35 assert(Clock::now() - abs_time
< ms(5));
36 try_lock_until_called
= !try_lock_until_called
;
37 return try_lock_until_called
;
39 void unlock_shared() {}
46 typedef std::chrono::steady_clock Clock
;
47 std::shared_lock
<mutex
> lk(m
, std::defer_lock
);
48 assert(lk
.try_lock_until(Clock::now()) == true);
49 assert(try_lock_until_called
== true);
50 assert(lk
.owns_lock() == true);
51 #ifndef TEST_HAS_NO_EXCEPTIONS
54 TEST_IGNORE_NODISCARD lk
.try_lock_until(Clock::now());
57 catch (std::system_error
& e
)
59 assert(e
.code().value() == EDEADLK
);
63 assert(lk
.try_lock_until(Clock::now()) == false);
64 assert(try_lock_until_called
== false);
65 assert(lk
.owns_lock() == false);
67 #ifndef TEST_HAS_NO_EXCEPTIONS
70 TEST_IGNORE_NODISCARD lk
.try_lock_until(Clock::now());
73 catch (std::system_error
& e
)
75 assert(e
.code().value() == EPERM
);