File indexing completed on 2025-01-18 09:39:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef BOOST_LOG_SOURCES_THREADING_MODELS_HPP_INCLUDED_
0018 #define BOOST_LOG_SOURCES_THREADING_MODELS_HPP_INCLUDED_
0019
0020 #include <boost/type_traits/has_nothrow_constructor.hpp>
0021 #include <boost/log/detail/config.hpp>
0022 #include <boost/log/detail/locks.hpp> // is_mutex_type
0023 #if !defined(BOOST_LOG_NO_THREADS)
0024 #include <boost/type_traits/integral_constant.hpp>
0025 #endif
0026 #include <boost/log/detail/header.hpp>
0027
0028 #ifdef BOOST_HAS_PRAGMA_ONCE
0029 #pragma once
0030 #endif
0031
0032 namespace boost {
0033
0034 BOOST_LOG_OPEN_NAMESPACE
0035
0036 namespace sources {
0037
0038
0039 struct single_thread_model
0040 {
0041
0042 void lock_shared() const BOOST_NOEXCEPT {}
0043 bool try_lock_shared() const BOOST_NOEXCEPT { return true; }
0044 template< typename TimeT >
0045 bool timed_lock_shared(TimeT const&) const BOOST_NOEXCEPT { return true; }
0046 void unlock_shared() const BOOST_NOEXCEPT {}
0047 void lock() const BOOST_NOEXCEPT {}
0048 bool try_lock() const BOOST_NOEXCEPT { return true; }
0049 template< typename TimeT >
0050 bool timed_lock(TimeT const&) const BOOST_NOEXCEPT { return true; }
0051 void unlock() const BOOST_NOEXCEPT {}
0052 void lock_upgrade() const BOOST_NOEXCEPT {}
0053 bool try_lock_upgrade() const BOOST_NOEXCEPT { return true; }
0054 template< typename TimeT >
0055 bool timed_lock_upgrade(TimeT const&) const BOOST_NOEXCEPT { return true; }
0056 void unlock_upgrade() const BOOST_NOEXCEPT {}
0057 void unlock_upgrade_and_lock() const BOOST_NOEXCEPT {}
0058 void unlock_and_lock_upgrade() const BOOST_NOEXCEPT {}
0059 void unlock_and_lock_shared() const BOOST_NOEXCEPT {}
0060 void unlock_upgrade_and_lock_shared() const BOOST_NOEXCEPT {}
0061
0062 void swap(single_thread_model&) BOOST_NOEXCEPT {}
0063 };
0064
0065 inline void swap(single_thread_model&, single_thread_model&) BOOST_NOEXCEPT
0066 {
0067 }
0068
0069 #if !defined(BOOST_LOG_NO_THREADS)
0070
0071
0072 template< typename MutexT >
0073 struct multi_thread_model
0074 {
0075 multi_thread_model() BOOST_NOEXCEPT_IF(boost::has_nothrow_constructor< MutexT >::value) {}
0076 multi_thread_model(multi_thread_model const&) BOOST_NOEXCEPT_IF(boost::has_nothrow_constructor< MutexT >::value) {}
0077 multi_thread_model& operator= (multi_thread_model const&) BOOST_NOEXCEPT { return *this; }
0078 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0079 multi_thread_model(multi_thread_model&&) BOOST_NOEXCEPT_IF(boost::has_nothrow_constructor< MutexT >::value) {}
0080 multi_thread_model& operator= (multi_thread_model&&) BOOST_NOEXCEPT { return *this; }
0081 #endif
0082
0083 void lock_shared() const { m_Mutex.lock_shared(); }
0084 bool try_lock_shared() const { return m_Mutex.try_lock_shared(); }
0085 template< typename TimeT >
0086 bool timed_lock_shared(TimeT const& t) const { return m_Mutex.timed_lock_shared(t); }
0087 void unlock_shared() const BOOST_NOEXCEPT { m_Mutex.unlock_shared(); }
0088 void lock() const { m_Mutex.lock(); }
0089 bool try_lock() const { return m_Mutex.try_lock(); }
0090 template< typename TimeT >
0091 bool timed_lock(TimeT const& t) const { return m_Mutex.timed_lock(t); }
0092 void unlock() const BOOST_NOEXCEPT { m_Mutex.unlock(); }
0093 void lock_upgrade() const { m_Mutex.lock_upgrade(); }
0094 bool try_lock_upgrade() const { return m_Mutex.try_lock_upgrade(); }
0095 template< typename TimeT >
0096 bool timed_lock_upgrade(TimeT const& t) const { return m_Mutex.timed_lock_upgrade(t); }
0097 void unlock_upgrade() const BOOST_NOEXCEPT { m_Mutex.unlock_upgrade(); }
0098 void unlock_upgrade_and_lock() const { m_Mutex.unlock_upgrade_and_lock(); }
0099 void unlock_and_lock_upgrade() const { m_Mutex.unlock_and_lock_upgrade(); }
0100 void unlock_and_lock_shared() const { m_Mutex.unlock_and_lock_shared(); }
0101 void unlock_upgrade_and_lock_shared() const { m_Mutex.unlock_upgrade_and_lock_shared(); }
0102
0103 void swap(multi_thread_model&) BOOST_NOEXCEPT {}
0104
0105 private:
0106
0107 mutable MutexT m_Mutex;
0108 };
0109
0110 template< typename MutexT >
0111 inline void swap(multi_thread_model< MutexT >&, multi_thread_model< MutexT >&) BOOST_NOEXCEPT
0112 {
0113 }
0114
0115 #endif
0116
0117 }
0118
0119 BOOST_LOG_CLOSE_NAMESPACE
0120
0121 #if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_LOG_DOXYGEN_PASS)
0122
0123 template< >
0124 struct is_mutex_type< boost::log::sources::single_thread_model > : boost::true_type
0125 {
0126 };
0127
0128 template< typename T >
0129 struct is_mutex_type< boost::log::sources::multi_thread_model< T > > : boost::true_type
0130 {
0131 };
0132
0133 #endif
0134
0135 }
0136
0137 #include <boost/log/detail/footer.hpp>
0138
0139 #endif