| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <mutex> |
| 10 | |
| 11 | // template <class Rep, class Period> |
| 12 | // unique_lock::unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time); |
| 13 | |
| 14 | #include <cassert> |
| 15 | #include <chrono> |
| 16 | #include <mutex> |
| 17 | |
| 18 | #include "checking_mutex.h" |
| 19 | |
| 20 | int main(int, char**) { |
| 21 | checking_mutex mux; |
| 22 | { // check successful lock |
| 23 | mux.reject = false; |
| 24 | std::unique_lock<checking_mutex> lock(mux, std::chrono::seconds()); |
| 25 | assert(mux.current_state == checking_mutex::locked_via_try_lock_for); |
| 26 | assert(lock.owns_lock()); |
| 27 | } |
| 28 | assert(mux.current_state == checking_mutex::unlocked); |
| 29 | |
| 30 | { // check unsuccessful lock |
| 31 | mux.reject = true; |
| 32 | std::unique_lock<checking_mutex> lock(mux, std::chrono::seconds()); |
| 33 | assert(mux.current_state == checking_mutex::unlocked); |
| 34 | assert(mux.last_try == checking_mutex::locked_via_try_lock_for); |
| 35 | assert(!lock.owns_lock()); |
| 36 | } |
| 37 | assert(mux.current_state == checking_mutex::unlocked); |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |