Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / histogram / detail / mutex_base.hpp
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
7 #ifndef BOOST_HISTOGRAM_DETAIL_NOOP_MUTEX_HPP
8 #define BOOST_HISTOGRAM_DETAIL_NOOP_MUTEX_HPP
9
10 #include <boost/core/empty_value.hpp>
11 #include <boost/histogram/detail/axes.hpp>
12 #include <boost/mp11/utility.hpp> // mp_if
13 #include <mutex>
14
15 namespace boost {
16 namespace histogram {
17 namespace detail {
18
19 struct null_mutex {
20   bool try_lock() noexcept { return true; }
21   void lock() noexcept {}
22   void unlock() noexcept {}
23 };
24
25 template <class Axes, class Storage,
26           class DetailMutex = mp11::mp_if_c<(Storage::has_threading_support &&
27                                              detail::has_growing_axis<Axes>::value),
28                                             std::mutex, detail::null_mutex>>
29 struct mutex_base : empty_value<DetailMutex> {
30   mutex_base() = default;
31   // do not copy or move mutex
32   mutex_base(const mutex_base&) : empty_value<DetailMutex>() {}
33   // do not copy or move mutex
34   mutex_base& operator=(const mutex_base&) { return *this; }
35 };
36
37 } // namespace detail
38 } // namespace histogram
39 } // namespace boost
40
41 #endif