mutex_base.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2019 Hans Dembinski
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_HISTOGRAM_DETAIL_NOOP_MUTEX_HPP
  7. #define BOOST_HISTOGRAM_DETAIL_NOOP_MUTEX_HPP
  8. #include <boost/core/empty_value.hpp>
  9. #include <boost/histogram/detail/axes.hpp>
  10. #include <boost/mp11/utility.hpp> // mp_if
  11. #include <mutex>
  12. namespace boost {
  13. namespace histogram {
  14. namespace detail {
  15. struct null_mutex {
  16. bool try_lock() noexcept { return true; }
  17. void lock() noexcept {}
  18. void unlock() noexcept {}
  19. };
  20. template <class Axes, class Storage,
  21. class DetailMutex = mp11::mp_if_c<(Storage::has_threading_support &&
  22. detail::has_growing_axis<Axes>::value),
  23. std::mutex, detail::null_mutex>>
  24. struct mutex_base : empty_value<DetailMutex> {
  25. mutex_base() = default;
  26. // do not copy or move mutex
  27. mutex_base(const mutex_base&) : empty_value<DetailMutex>() {}
  28. // do not copy or move mutex
  29. mutex_base& operator=(const mutex_base&) { return *this; }
  30. };
  31. } // namespace detail
  32. } // namespace histogram
  33. } // namespace boost
  34. #endif