annotate DEPENDENCIES/generic/include/boost/thread/lockable_adapter.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //////////////////////////////////////////////////////////////////////////////
Chris@16 2 //
Chris@16 3 // (C) Copyright Vicente J. Botet Escriba 2008-2009,2012. Distributed under the Boost
Chris@16 4 // Software License, Version 1.0. (See accompanying file
Chris@16 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 //
Chris@16 7 // See http://www.boost.org/libs/thread for documentation.
Chris@16 8 //
Chris@16 9 //////////////////////////////////////////////////////////////////////////////
Chris@16 10
Chris@16 11 #ifndef BOOST_THREAD_LOCKABLE_ADAPTER_HPP
Chris@16 12 #define BOOST_THREAD_LOCKABLE_ADAPTER_HPP
Chris@16 13
Chris@16 14 #include <boost/thread/detail/delete.hpp>
Chris@16 15 #include <boost/chrono/chrono.hpp>
Chris@16 16
Chris@16 17 namespace boost
Chris@16 18 {
Chris@16 19
Chris@16 20 //[basic_lockable_adapter
Chris@16 21 template <typename BasicLockable>
Chris@16 22 class basic_lockable_adapter
Chris@16 23 {
Chris@16 24 public:
Chris@16 25 typedef BasicLockable mutex_type;
Chris@16 26
Chris@16 27 protected:
Chris@16 28 mutex_type& lockable() const
Chris@16 29 {
Chris@16 30 return lockable_;
Chris@16 31 }
Chris@16 32 mutable mutex_type lockable_; /*< mutable so that it can be modified by const functions >*/
Chris@16 33 public:
Chris@16 34
Chris@16 35 BOOST_THREAD_NO_COPYABLE( basic_lockable_adapter) /*< no copyable >*/
Chris@16 36
Chris@16 37 basic_lockable_adapter()
Chris@16 38 {}
Chris@16 39
Chris@101 40 void lock() const
Chris@16 41 {
Chris@16 42 lockable().lock();
Chris@16 43 }
Chris@101 44 void unlock() const
Chris@16 45 {
Chris@16 46 lockable().unlock();
Chris@16 47 }
Chris@16 48
Chris@16 49 };
Chris@16 50 //]
Chris@16 51
Chris@16 52 //[lockable_adapter
Chris@16 53 template <typename Lockable>
Chris@16 54 class lockable_adapter : public basic_lockable_adapter<Lockable>
Chris@16 55 {
Chris@16 56 public:
Chris@16 57 typedef Lockable mutex_type;
Chris@16 58
Chris@101 59 bool try_lock() const
Chris@16 60 {
Chris@16 61 return this->lockable().try_lock();
Chris@16 62 }
Chris@16 63 };
Chris@16 64 //]
Chris@16 65
Chris@16 66 //[timed_lockable_adapter
Chris@16 67 template <typename TimedLock>
Chris@16 68 class timed_lockable_adapter: public lockable_adapter<TimedLock>
Chris@16 69 {
Chris@16 70 public:
Chris@16 71 typedef TimedLock mutex_type;
Chris@16 72
Chris@16 73 template <typename Clock, typename Duration>
Chris@101 74 bool try_lock_until(chrono::time_point<Clock, Duration> const & abs_time) const
Chris@16 75 {
Chris@16 76 return this->lockable().try_lock_until(abs_time);
Chris@16 77 }
Chris@16 78 template <typename Rep, typename Period>
Chris@101 79 bool try_lock_for(chrono::duration<Rep, Period> const & rel_time) const
Chris@16 80 {
Chris@16 81 return this->lockable().try_lock_for(rel_time);
Chris@16 82 }
Chris@16 83
Chris@16 84 };
Chris@16 85 //]
Chris@16 86
Chris@16 87 //[shared_lockable_adapter
Chris@16 88 template <typename SharableLock>
Chris@16 89 class shared_lockable_adapter: public timed_lockable_adapter<SharableLock>
Chris@16 90 {
Chris@16 91 public:
Chris@16 92 typedef SharableLock mutex_type;
Chris@16 93
Chris@101 94 void lock_shared() const
Chris@16 95 {
Chris@16 96 this->lockable().lock_shared();
Chris@16 97 }
Chris@101 98 bool try_lock_shared() const
Chris@16 99 {
Chris@16 100 return this->lockable().try_lock_shared();
Chris@16 101 }
Chris@101 102 void unlock_shared() const
Chris@16 103 {
Chris@16 104 this->lockable().unlock_shared();
Chris@16 105 }
Chris@16 106
Chris@16 107 template <typename Clock, typename Duration>
Chris@101 108 bool try_lock_shared_until(chrono::time_point<Clock, Duration> const & abs_time) const
Chris@16 109 {
Chris@16 110 return this->lockable().try_lock_shared_until(abs_time);
Chris@16 111 }
Chris@16 112 template <typename Rep, typename Period>
Chris@101 113 bool try_lock_shared_for(chrono::duration<Rep, Period> const & rel_time) const
Chris@16 114 {
Chris@16 115 return this->lockable().try_lock_shared_for(rel_time);
Chris@16 116 }
Chris@16 117
Chris@16 118 };
Chris@16 119
Chris@16 120 //]
Chris@16 121
Chris@16 122 //[upgrade_lockable_adapter
Chris@16 123 template <typename UpgradableLock>
Chris@16 124 class upgrade_lockable_adapter: public shared_lockable_adapter<UpgradableLock>
Chris@16 125 {
Chris@16 126 public:
Chris@16 127 typedef UpgradableLock mutex_type;
Chris@16 128
Chris@101 129 void lock_upgrade() const
Chris@16 130 {
Chris@16 131 this->lockable().lock_upgrade();
Chris@16 132 }
Chris@16 133
Chris@101 134 bool try_lock_upgrade() const
Chris@16 135 {
Chris@16 136 return this->lockable().try_lock_upgrade();
Chris@16 137 }
Chris@16 138
Chris@101 139 void unlock_upgrade() const
Chris@16 140 {
Chris@16 141 this->lockable().unlock_upgrade();
Chris@16 142 }
Chris@16 143
Chris@16 144 template <typename Clock, typename Duration>
Chris@101 145 bool try_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time) const
Chris@16 146 {
Chris@16 147 return this->lockable().try_lock_upgrade_until(abs_time);
Chris@16 148 }
Chris@16 149 template <typename Rep, typename Period>
Chris@101 150 bool try_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time) const
Chris@16 151 {
Chris@16 152 return this->lockable().try_lock_upgrade_for(rel_time);
Chris@16 153 }
Chris@16 154
Chris@101 155 bool try_unlock_shared_and_lock() const
Chris@16 156 {
Chris@16 157 return this->lockable().try_unlock_shared_and_lock();
Chris@16 158 }
Chris@16 159
Chris@16 160 template <typename Clock, typename Duration>
Chris@101 161 bool try_unlock_shared_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time) const
Chris@16 162 {
Chris@16 163 return this->lockable().try_unlock_shared_and_lock_until(abs_time);
Chris@16 164 }
Chris@16 165 template <typename Rep, typename Period>
Chris@101 166 bool try_unlock_shared_and_lock_for(chrono::duration<Rep, Period> const & rel_time) const
Chris@16 167 {
Chris@16 168 return this->lockable().try_unlock_shared_and_lock_for(rel_time);
Chris@16 169 }
Chris@16 170
Chris@101 171 void unlock_and_lock_shared() const
Chris@16 172 {
Chris@16 173 this->lockable().unlock_and_lock_shared();
Chris@16 174 }
Chris@16 175
Chris@101 176 bool try_unlock_shared_and_lock_upgrade() const
Chris@16 177 {
Chris@16 178 return this->lockable().try_unlock_shared_and_lock_upgrade();
Chris@16 179 }
Chris@16 180
Chris@16 181 template <typename Clock, typename Duration>
Chris@101 182 bool try_unlock_shared_and_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time) const
Chris@16 183 {
Chris@16 184 return this->lockable().try_unlock_shared_and_lock_upgrade_until(abs_time);
Chris@16 185 }
Chris@16 186 template <typename Rep, typename Period>
Chris@101 187 bool try_unlock_shared_and_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time) const
Chris@16 188 {
Chris@16 189 return this->lockable().try_unlock_shared_and_lock_upgrade_for(rel_time);
Chris@16 190 }
Chris@16 191
Chris@101 192 void unlock_and_lock_upgrade() const
Chris@16 193 {
Chris@16 194 this->lockable().unlock_and_lock_upgrade();
Chris@16 195 }
Chris@16 196
Chris@101 197 void unlock_upgrade_and_lock() const
Chris@16 198 {
Chris@16 199 this->lockable().unlock_upgrade_and_lock();
Chris@16 200 }
Chris@16 201
Chris@101 202 bool try_unlock_upgrade_and_lock() const
Chris@16 203 {
Chris@16 204 return this->lockable().try_unlock_upgrade_and_lock();
Chris@16 205 }
Chris@16 206 template <typename Clock, typename Duration>
Chris@101 207 bool try_unlock_upgrade_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time) const
Chris@16 208 {
Chris@16 209 return this->lockable().try_unlock_upgrade_and_lock_until(abs_time);
Chris@16 210 }
Chris@16 211 template <typename Rep, typename Period>
Chris@101 212 bool try_unlock_upgrade_and_lock_for(chrono::duration<Rep, Period> const & rel_time) const
Chris@16 213 {
Chris@16 214 return this->lockable().try_unlock_upgrade_and_lock_for(rel_time);
Chris@16 215 }
Chris@16 216
Chris@101 217 void unlock_upgrade_and_lock_shared() const
Chris@16 218 {
Chris@16 219 this->lockable().unlock_upgrade_and_lock_shared();
Chris@16 220 }
Chris@16 221
Chris@16 222 };
Chris@16 223 //]
Chris@16 224
Chris@16 225 }
Chris@16 226 #endif