release_pass.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 shared_lock;
  15. // void Mutex* release();
  16. #include <boost/thread/lock_types.hpp>
  17. #include <boost/detail/lightweight_test.hpp>
  18. struct shared_mutex
  19. {
  20. static int lock_count;
  21. static int unlock_count;
  22. void lock_shared()
  23. {
  24. ++lock_count;
  25. }
  26. void unlock_shared()
  27. {
  28. ++unlock_count;
  29. }
  30. };
  31. int shared_mutex::lock_count = 0;
  32. int shared_mutex::unlock_count = 0;
  33. shared_mutex m;
  34. int main()
  35. {
  36. boost::shared_lock<shared_mutex> lk(m);
  37. BOOST_TEST(lk.mutex() == &m);
  38. BOOST_TEST(lk.owns_lock() == true);
  39. BOOST_TEST(shared_mutex::lock_count == 1);
  40. BOOST_TEST(shared_mutex::unlock_count == 0);
  41. BOOST_TEST(lk.release() == &m);
  42. BOOST_TEST(lk.mutex() == 0);
  43. BOOST_TEST(lk.owns_lock() == false);
  44. BOOST_TEST(shared_mutex::lock_count == 1);
  45. BOOST_TEST(shared_mutex::unlock_count == 0);
  46. return boost::report_errors();
  47. }