is_locked_by_this_thread.hpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // (C) Copyright 2012 Vicente J. Botet Escriba
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_THREAD_IS_LOCKED_BY_THIS_THREAD_HPP
  6. #define BOOST_THREAD_IS_LOCKED_BY_THIS_THREAD_HPP
  7. #include <boost/thread/detail/config.hpp>
  8. #include <boost/config/abi_prefix.hpp>
  9. namespace boost
  10. {
  11. template <typename Lockable>
  12. class testable_mutex;
  13. /**
  14. * Overloaded function used to check if the mutex is locked when it is testable and do nothing otherwise.
  15. *
  16. * This function is used usually to assert the pre-condition when the function can only be called when the mutex
  17. * must be locked by the current thread.
  18. */
  19. template <typename Lockable>
  20. bool is_locked_by_this_thread(testable_mutex<Lockable> const& mtx)
  21. {
  22. return mtx.is_locked_by_this_thread();
  23. }
  24. template <typename Lockable>
  25. bool is_locked_by_this_thread(Lockable const&)
  26. {
  27. return true;
  28. }
  29. }
  30. #include <boost/config/abi_suffix.hpp>
  31. #endif // header