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 // Copyright (C) 2011 Vicente J. Botet Escriba 11 // 12 // Distributed under the Boost Software License, Version 1.0. (See accompanying 13 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 14 15 // <boost/thread/locks.hpp> 16 17 // template <class Mutex> class unique_lock; 18 19 // unique_lock(upgrade_lock&& u, try_to_lock); 20 21 #define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN 22 23 #include <boost/thread/lock_types.hpp> 24 #include <boost/thread/shared_mutex.hpp> 25 #include <boost/detail/lightweight_test.hpp> 26 27 boost::upgrade_mutex m; 28 main()29int main() 30 { 31 { 32 boost::upgrade_lock<boost::upgrade_mutex> lk0(m); 33 boost::unique_lock<boost::upgrade_mutex> lk(boost::move(lk0), boost::try_to_lock ); 34 BOOST_TEST(lk.mutex() == &m); 35 BOOST_TEST(lk.owns_lock() == true); 36 BOOST_TEST(lk0.mutex() == 0); 37 BOOST_TEST(lk0.owns_lock() == false); 38 } 39 { 40 boost::unique_lock<boost::upgrade_mutex> lk(boost::upgrade_lock<boost::upgrade_mutex>(m), boost::try_to_lock); 41 BOOST_TEST(lk.mutex() == &m); 42 BOOST_TEST(lk.owns_lock() == true); 43 } 44 { 45 boost::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock); 46 boost::unique_lock<boost::upgrade_mutex> lk(boost::move(lk0), boost::try_to_lock); 47 BOOST_TEST(lk.mutex() == &m); 48 BOOST_TEST(lk.owns_lock() == false); 49 BOOST_TEST(lk0.mutex() == 0); 50 BOOST_TEST(lk0.owns_lock() == false); 51 } 52 { 53 boost::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock); 54 lk0.release(); 55 boost::unique_lock<boost::upgrade_mutex> lk(boost::move(lk0), boost::try_to_lock); 56 BOOST_TEST(lk.mutex() == 0); 57 BOOST_TEST(lk.owns_lock() == false); 58 BOOST_TEST(lk0.mutex() == 0); 59 BOOST_TEST(lk0.owns_lock() == false); 60 } 61 62 return boost::report_errors(); 63 } 64 65