| 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 Mutex> class unique_lock; |
| 12 | |
| 13 | // unique_lock(mutex_type& m, try_to_lock_t); |
| 14 | |
| 15 | #include <cassert> |
| 16 | #include <mutex> |
| 17 | |
| 18 | #include "checking_mutex.h" |
| 19 | |
| 20 | int main(int, char**) { |
| 21 | checking_mutex mux; |
| 22 | |
| 23 | { // check successful lock |
| 24 | mux.reject = false; |
| 25 | std::unique_lock<checking_mutex> lock(mux, std::try_to_lock_t()); |
| 26 | assert(mux.current_state == checking_mutex::locked_via_try_lock); |
| 27 | assert(lock.owns_lock()); |
| 28 | } |
| 29 | assert(mux.current_state == checking_mutex::unlocked); |
| 30 | |
| 31 | { // check successful lock |
| 32 | mux.reject = true; |
| 33 | std::unique_lock<checking_mutex> lock(mux, std::try_to_lock_t()); |
| 34 | assert(mux.last_try == checking_mutex::locked_via_try_lock); |
| 35 | assert(mux.current_state == checking_mutex::unlocked); |
| 36 | assert(!lock.owns_lock()); |
| 37 | } |
| 38 | assert(mux.current_state == checking_mutex::unlocked); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |