member_swap_pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // Copyright (C) 2011 Vicente J. Botet Escriba
  10. //
  11. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  12. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  13. // <boost/thread/locks.hpp>
  14. // template <class Mutex> class upgrade_lock;
  15. // void swap(upgrade_lock& u);
  16. #include <boost/thread/lock_types.hpp>
  17. #include <boost/detail/lightweight_test.hpp>
  18. struct shared_mutex
  19. {
  20. void lock_upgrade()
  21. {
  22. }
  23. void unlock_upgrade()
  24. {
  25. }
  26. };
  27. shared_mutex m;
  28. int main()
  29. {
  30. boost::upgrade_lock<shared_mutex> lk1(m);
  31. boost::upgrade_lock<shared_mutex> lk2;
  32. lk1.swap(lk2);
  33. BOOST_TEST(lk1.mutex() == 0);
  34. BOOST_TEST(lk1.owns_lock() == false);
  35. BOOST_TEST(lk2.mutex() == &m);
  36. BOOST_TEST(lk2.owns_lock() == true);
  37. return boost::report_errors();
  38. }