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 // UNSUPPORTED: libcpp-has-no-threads 10 11 // <mutex> 12 13 // template <class Mutex> class unique_lock; 14 15 // mutex_type* release() noexcept; 16 17 #include <mutex> 18 #include <cassert> 19 20 struct mutex 21 { 22 static int lock_count; 23 static int unlock_count; 24 void lock() {++lock_count;} 25 void unlock() {++unlock_count;} 26 }; 27 28 int mutex::lock_count = 0; 29 int mutex::unlock_count = 0; 30 31 mutex m; 32 33 int main(int, char**) 34 { 35 std::unique_lock<mutex> lk(m); 36 assert(lk.mutex() == &m); 37 assert(lk.owns_lock() == true); 38 assert(mutex::lock_count == 1); 39 assert(mutex::unlock_count == 0); 40 assert(lk.release() == &m); 41 assert(lk.mutex() == nullptr); 42 assert(lk.owns_lock() == false); 43 assert(mutex::lock_count == 1); 44 assert(mutex::unlock_count == 0); 45 46 return 0; 47 } 48