File indexing completed on 2025-12-15 10:09:31
0001
0002
0003
0004
0005
0006 #ifndef BOOST_THREAD_LOCKABLE_CONCEPTS_HPP
0007 #define BOOST_THREAD_LOCKABLE_CONCEPTS_HPP
0008
0009 #include <boost/chrono/chrono.hpp>
0010 #include <boost/concept_check.hpp>
0011
0012 namespace boost
0013 {
0014
0015
0016
0017
0018
0019
0020
0021
0022 template <typename Mutex>
0023 struct BasicLockable
0024 {
0025
0026 BOOST_CONCEPT_USAGE(BasicLockable)
0027 {
0028 l.lock();
0029 l.unlock();
0030 }
0031 BasicLockable() : l(*static_cast<Mutex*>(0)) {}
0032 private:
0033 BasicLockable operator=(BasicLockable const&);
0034
0035 Mutex& l;
0036 }
0037 ;
0038
0039
0040
0041
0042
0043
0044
0045 template <typename Mutex>
0046 struct Lockable
0047 {
0048 BOOST_CONCEPT_ASSERT(( BasicLockable<Mutex> ));
0049
0050 BOOST_CONCEPT_USAGE(Lockable)
0051 {
0052 if (l.try_lock()) return;
0053 }
0054 Lockable() : l(*static_cast<Mutex*>(0)) {}
0055 private:
0056 Lockable operator=(Lockable const&);
0057 Mutex& l;
0058 };
0059
0060
0061
0062
0063
0064
0065
0066
0067 template <typename Mutex>
0068 struct TimedLockable
0069 {
0070 BOOST_CONCEPT_ASSERT(( Lockable<Mutex> ));
0071
0072 BOOST_CONCEPT_USAGE(TimedLockable)
0073 {
0074 if (l.try_lock_until(t)) return;
0075 if (l.try_lock_for(d)) return;
0076 }
0077 TimedLockable() : l(*static_cast<Mutex*>(0)) {}
0078 private:
0079 TimedLockable operator=(TimedLockable const&);
0080 Mutex& l;
0081 chrono::system_clock::time_point t;
0082 chrono::system_clock::duration d;
0083 };
0084
0085
0086
0087
0088
0089
0090
0091
0092 template <typename Mutex>
0093 struct SharedLockable
0094 {
0095 BOOST_CONCEPT_ASSERT(( TimedLockable<Mutex> ));
0096
0097 BOOST_CONCEPT_USAGE(SharedLockable)
0098 {
0099 l.lock_shared();
0100 l.unlock_shared();
0101 if (l.try_lock_shared()) return;
0102 if (l.try_lock_shared_until(t)) return;
0103 if (l.try_lock_shared_for(d)) return;
0104 }
0105 SharedLockable() : l(*static_cast<Mutex*>(0)) {}
0106 private:
0107 SharedLockable operator=(SharedLockable const&);
0108 Mutex& l;
0109 chrono::system_clock::time_point t;
0110 chrono::system_clock::duration d;
0111 };
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 template <typename Mutex>
0122 struct UpgradeLockable
0123 {
0124 BOOST_CONCEPT_ASSERT(( SharedLockable<Mutex> ));
0125
0126 BOOST_CONCEPT_USAGE(UpgradeLockable)
0127 {
0128 l.lock_upgrade();
0129 l.unlock_upgrade();
0130 if (l.try_lock_upgrade()) return;
0131 if (l.try_lock_upgrade_until(t)) return;
0132 if (l.try_lock_upgrade_for(d)) return;
0133 if (l.try_unlock_shared_and_lock()) return;
0134 if (l.try_unlock_shared_and_lock_until(t)) return;
0135 if (l.try_unlock_shared_and_lock_for(d)) return;
0136 l.unlock_and_lock_shared();
0137 if (l.try_unlock_shared_and_lock_upgrade()) return;
0138 if (l.try_unlock_shared_and_lock_upgrade_until(t)) return;
0139 if (l.try_unlock_shared_and_lock_upgrade_for(d)) return;
0140 l.unlock_and_lock_upgrade();
0141 l.unlock_upgrade_and_lock();
0142 if (l.try_unlock_upgrade_and_lock()) return;
0143 if (l.try_unlock_upgrade_and_lock_until(t)) return;
0144 if (l.try_unlock_upgrade_and_lock_for(d)) return;
0145 l.unlock_upgrade_and_lock_shared();
0146 }
0147 UpgradeLockable() : l(*static_cast<Mutex*>(0)) {}
0148 private:
0149 UpgradeLockable operator=(UpgradeLockable const&);
0150 Mutex& l;
0151 chrono::system_clock::time_point t;
0152 chrono::system_clock::duration d;
0153 };
0154
0155
0156 }
0157 #endif