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 #include "test_macros.h" 21 22 struct mutex 23 { 24 static int lock_count; 25 static int unlock_count; lockmutex26 void lock() {++lock_count;} unlockmutex27 void unlock() {++unlock_count;} 28 }; 29 30 int mutex::lock_count = 0; 31 int mutex::unlock_count = 0; 32 33 mutex m; 34 main(int,char **)35int main(int, char**) 36 { 37 std::unique_lock<mutex> lk(m); 38 assert(lk.mutex() == &m); 39 assert(lk.owns_lock() == true); 40 assert(mutex::lock_count == 1); 41 assert(mutex::unlock_count == 0); 42 assert(lk.release() == &m); 43 assert(lk.mutex() == nullptr); 44 assert(lk.owns_lock() == false); 45 assert(mutex::lock_count == 1); 46 assert(mutex::unlock_count == 0); 47 48 return 0; 49 } 50