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 // void swap(unique_lock& u); 16 17 #include <mutex> 18 #include <cassert> 19 20 struct mutex 21 { 22 void lock() {} 23 void unlock() {} 24 }; 25 26 mutex m; 27 28 int main(int, char**) 29 { 30 std::unique_lock<mutex> lk1(m); 31 std::unique_lock<mutex> lk2; 32 lk1.swap(lk2); 33 assert(lk1.mutex() == nullptr); 34 assert(lk1.owns_lock() == false); 35 assert(lk2.mutex() == &m); 36 assert(lk2.owns_lock() == true); 37 38 return 0; 39 } 40