unlock_pass.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // template <class Rep, class Period>
  16. // bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
  17. #include <boost/thread/lock_types.hpp>
  18. //#include <boost/thread/shared_mutex.hpp>
  19. #include <boost/detail/lightweight_test.hpp>
  20. bool unlock_called = false;
  21. struct shared_mutex
  22. {
  23. void lock_shared()
  24. {
  25. }
  26. void unlock_shared()
  27. {
  28. unlock_called = true;
  29. }
  30. };
  31. shared_mutex m;
  32. int main()
  33. {
  34. boost::shared_lock<shared_mutex> lk(m);
  35. lk.unlock();
  36. BOOST_TEST(unlock_called == true);
  37. BOOST_TEST(lk.owns_lock() == false);
  38. try
  39. {
  40. lk.unlock();
  41. BOOST_TEST(false);
  42. }
  43. catch (boost::system::system_error& e)
  44. {
  45. BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
  46. }
  47. lk.release();
  48. try
  49. {
  50. lk.unlock();
  51. BOOST_TEST(false);
  52. }
  53. catch (boost::system::system_error& e)
  54. {
  55. BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
  56. }
  57. return boost::report_errors();
  58. }