Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file sources/threading_models.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 04.10.2008
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains definition of threading models that can be used in loggers.
|
Chris@16
|
13 * The header also provides a number of tags that can be used to express lock requirements
|
Chris@16
|
14 * on a function callee.
|
Chris@16
|
15 */
|
Chris@16
|
16
|
Chris@16
|
17 #ifndef BOOST_LOG_SOURCES_THREADING_MODELS_HPP_INCLUDED_
|
Chris@16
|
18 #define BOOST_LOG_SOURCES_THREADING_MODELS_HPP_INCLUDED_
|
Chris@16
|
19
|
Chris@16
|
20 #include <boost/log/detail/config.hpp>
|
Chris@16
|
21 #include <boost/log/detail/locks.hpp> // is_mutex_type
|
Chris@16
|
22 #if !defined(BOOST_LOG_NO_THREADS)
|
Chris@16
|
23 #include <boost/mpl/bool.hpp>
|
Chris@16
|
24 #endif
|
Chris@16
|
25 #include <boost/log/detail/header.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
28 #pragma once
|
Chris@16
|
29 #endif
|
Chris@16
|
30
|
Chris@16
|
31 namespace boost {
|
Chris@16
|
32
|
Chris@16
|
33 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
34
|
Chris@16
|
35 namespace sources {
|
Chris@16
|
36
|
Chris@16
|
37 //! Single thread locking model
|
Chris@16
|
38 struct single_thread_model
|
Chris@16
|
39 {
|
Chris@16
|
40 // We provide methods for the most advanced locking concept: UpgradeLockable
|
Chris@16
|
41 void lock_shared() const {}
|
Chris@16
|
42 bool try_lock_shared() const { return true; }
|
Chris@16
|
43 template< typename TimeT >
|
Chris@16
|
44 bool timed_lock_shared(TimeT const&) const { return true; }
|
Chris@16
|
45 void unlock_shared() const {}
|
Chris@16
|
46 void lock() const {}
|
Chris@16
|
47 bool try_lock() const { return true; }
|
Chris@16
|
48 template< typename TimeT >
|
Chris@16
|
49 bool timed_lock(TimeT const&) const { return true; }
|
Chris@16
|
50 void unlock() const {}
|
Chris@16
|
51 void lock_upgrade() const {}
|
Chris@16
|
52 bool try_lock_upgrade() const { return true; }
|
Chris@16
|
53 template< typename TimeT >
|
Chris@16
|
54 bool timed_lock_upgrade(TimeT const&) const { return true; }
|
Chris@16
|
55 void unlock_upgrade() const {}
|
Chris@16
|
56 void unlock_upgrade_and_lock() const {}
|
Chris@16
|
57 void unlock_and_lock_upgrade() const {}
|
Chris@16
|
58 void unlock_and_lock_shared() const {}
|
Chris@16
|
59 void unlock_upgrade_and_lock_shared() const {}
|
Chris@16
|
60
|
Chris@16
|
61 void swap(single_thread_model&) {}
|
Chris@16
|
62 };
|
Chris@16
|
63
|
Chris@16
|
64 #if !defined(BOOST_LOG_NO_THREADS)
|
Chris@16
|
65
|
Chris@16
|
66 //! Multi-thread locking model with maximum locking capabilities
|
Chris@16
|
67 template< typename MutexT >
|
Chris@16
|
68 struct multi_thread_model
|
Chris@16
|
69 {
|
Chris@16
|
70 multi_thread_model() {}
|
Chris@16
|
71 multi_thread_model(multi_thread_model const&) {}
|
Chris@16
|
72 multi_thread_model& operator= (multi_thread_model const&) { return *this; }
|
Chris@16
|
73
|
Chris@16
|
74 void lock_shared() const { m_Mutex.lock_shared(); }
|
Chris@16
|
75 bool try_lock_shared() const { return m_Mutex.try_lock_shared(); }
|
Chris@16
|
76 template< typename TimeT >
|
Chris@16
|
77 bool timed_lock_shared(TimeT const& t) const { return m_Mutex.timed_lock_shared(t); }
|
Chris@16
|
78 void unlock_shared() const { m_Mutex.unlock_shared(); }
|
Chris@16
|
79 void lock() const { m_Mutex.lock(); }
|
Chris@16
|
80 bool try_lock() const { return m_Mutex.try_lock(); }
|
Chris@16
|
81 template< typename TimeT >
|
Chris@16
|
82 bool timed_lock(TimeT const& t) const { return m_Mutex.timed_lock(t); }
|
Chris@16
|
83 void unlock() const { m_Mutex.unlock(); }
|
Chris@16
|
84 void lock_upgrade() const { m_Mutex.lock_upgrade(); }
|
Chris@16
|
85 bool try_lock_upgrade() const { return m_Mutex.try_lock_upgrade(); }
|
Chris@16
|
86 template< typename TimeT >
|
Chris@16
|
87 bool timed_lock_upgrade(TimeT const& t) const { return m_Mutex.timed_lock_upgrade(t); }
|
Chris@16
|
88 void unlock_upgrade() const { m_Mutex.unlock_upgrade(); }
|
Chris@16
|
89 void unlock_upgrade_and_lock() const { m_Mutex.unlock_upgrade_and_lock(); }
|
Chris@16
|
90 void unlock_and_lock_upgrade() const { m_Mutex.unlock_and_lock_upgrade(); }
|
Chris@16
|
91 void unlock_and_lock_shared() const { m_Mutex.unlock_and_lock_shared(); }
|
Chris@16
|
92 void unlock_upgrade_and_lock_shared() const { m_Mutex.unlock_upgrade_and_lock_shared(); }
|
Chris@16
|
93
|
Chris@16
|
94 void swap(multi_thread_model&) {}
|
Chris@16
|
95
|
Chris@16
|
96 private:
|
Chris@16
|
97 //! Synchronization primitive
|
Chris@16
|
98 mutable MutexT m_Mutex;
|
Chris@16
|
99 };
|
Chris@16
|
100
|
Chris@16
|
101 #endif // !defined(BOOST_LOG_NO_THREADS)
|
Chris@16
|
102
|
Chris@16
|
103 } // namespace sources
|
Chris@16
|
104
|
Chris@16
|
105 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
106
|
Chris@16
|
107 #if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_LOG_DOXYGEN_PASS)
|
Chris@16
|
108
|
Chris@16
|
109 template< >
|
Chris@16
|
110 struct is_mutex_type< boost::log::sources::single_thread_model > : mpl::true_
|
Chris@16
|
111 {
|
Chris@16
|
112 };
|
Chris@16
|
113
|
Chris@16
|
114 template< typename T >
|
Chris@16
|
115 struct is_mutex_type< boost::log::sources::multi_thread_model< T > > : mpl::true_
|
Chris@16
|
116 {
|
Chris@16
|
117 };
|
Chris@16
|
118
|
Chris@16
|
119 #endif // !defined(BOOST_LOG_NO_THREADS)
|
Chris@16
|
120
|
Chris@16
|
121 } // namespace boost
|
Chris@16
|
122
|
Chris@16
|
123 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
124
|
Chris@16
|
125 #endif // BOOST_LOG_SOURCES_THREADING_MODELS_HPP_INCLUDED_
|