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