1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <shared_mutex> 11 12 // template <class Mutex> class shared_lock; 13 14 // mutex_type* release() noexcept; 15 16 #include <shared_mutex> 17 #include <cassert> 18 19 #if _LIBCPP_STD_VER > 11 20 21 struct mutex 22 { 23 static int lock_count; 24 static int unlock_count; 25 void lock_shared() {++lock_count;} 26 void unlock_shared() {++unlock_count;} 27 }; 28 29 int mutex::lock_count = 0; 30 int mutex::unlock_count = 0; 31 32 mutex m; 33 34 #endif // _LIBCPP_STD_VER > 11 35 36 int main() 37 { 38 #if _LIBCPP_STD_VER > 11 39 std::shared_lock<mutex> lk(m); 40 assert(lk.mutex() == &m); 41 assert(lk.owns_lock() == true); 42 assert(mutex::lock_count == 1); 43 assert(mutex::unlock_count == 0); 44 assert(lk.release() == &m); 45 assert(lk.mutex() == nullptr); 46 assert(lk.owns_lock() == false); 47 assert(mutex::lock_count == 1); 48 assert(mutex::unlock_count == 0); 49 static_assert(noexcept(lk.release()), "release must be noexcept"); 50 #endif // _LIBCPP_STD_VER > 11 51 } 52