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 Clock, class Duration> 12 // unique_lock::unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_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 23 { // check successful lock 24 mux.reject = false; 25 std::unique_lock<checking_mutex> lock(mux, std::chrono::time_point<std::chrono::system_clock>()); 26 assert(mux.current_state == checking_mutex::locked_via_try_lock_until); 27 assert(lock.owns_lock()); 28 } 29 assert(mux.current_state == checking_mutex::unlocked); 30 31 { // check unsuccessful lock 32 mux.reject = true; 33 std::unique_lock<checking_mutex> lock(mux, std::chrono::time_point<std::chrono::system_clock>()); 34 assert(mux.current_state == checking_mutex::unlocked); 35 assert(mux.last_try == checking_mutex::locked_via_try_lock_until); 36 assert(!lock.owns_lock()); 37 } 38 assert(mux.current_state == checking_mutex::unlocked); 39 40 return 0; 41 } 42