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 // template <class Clock, class Duration>
20 // unique_lock(shared_lock<mutex_type>&&,
21 // const chrono::duration<Rep, Period>&);
22
23 #define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
24
25 #include <boost/thread/lock_types.hpp>
26 #include <boost/thread/shared_mutex.hpp>
27 #include <boost/detail/lightweight_test.hpp>
28
29 boost::upgrade_mutex m;
30
main()31 int main()
32 {
33 {
34 boost::upgrade_lock<boost::upgrade_mutex> lk0(m);
35 boost::unique_lock<boost::upgrade_mutex> lk(boost::move(lk0), boost::chrono::milliseconds(1));
36 BOOST_TEST(lk.mutex() == &m);
37 BOOST_TEST(lk.owns_lock() == true);
38 BOOST_TEST(lk0.mutex() == 0);
39 BOOST_TEST(lk0.owns_lock() == false);
40 }
41 {
42 boost::unique_lock<boost::upgrade_mutex>
43 lk(boost::upgrade_lock<boost::upgrade_mutex>(m), boost::chrono::milliseconds(1));
44 BOOST_TEST(lk.mutex() == &m);
45 BOOST_TEST(lk.owns_lock() == true);
46 }
47 {
48 boost::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock);
49 boost::unique_lock<boost::upgrade_mutex> lk(boost::move(lk0), boost::chrono::milliseconds(1));
50 BOOST_TEST(lk.mutex() == &m);
51 BOOST_TEST(lk.owns_lock() == false);
52 BOOST_TEST(lk0.mutex() == 0);
53 BOOST_TEST(lk0.owns_lock() == false);
54 }
55 {
56 boost::upgrade_lock<boost::upgrade_mutex> lk0(m, boost::defer_lock);
57 lk0.release();
58 boost::unique_lock<boost::upgrade_mutex> lk(boost::move(lk0), boost::chrono::milliseconds(1));
59 BOOST_TEST(lk.mutex() == 0);
60 BOOST_TEST(lk.owns_lock() == false);
61 BOOST_TEST(lk0.mutex() == 0);
62 BOOST_TEST(lk0.owns_lock() == false);
63 }
64
65 return boost::report_errors();
66 }
67
68