123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- #ifndef BOOST_THREAD_LOCKABLE_CONCEPTS_HPP
- #define BOOST_THREAD_LOCKABLE_CONCEPTS_HPP
- #include <boost/chrono/chrono.hpp>
- #include <boost/concept_check.hpp>
- namespace boost
- {
-
-
- template <typename Mutex>
- struct BasicLockable
- {
- BOOST_CONCEPT_USAGE(BasicLockable)
- {
- l.lock();
- l.unlock();
- }
- BasicLockable() : l(*static_cast<Mutex*>(0)) {}
- private:
- BasicLockable operator=(BasicLockable const&);
- Mutex& l;
- }
- ;
-
-
-
- template <typename Mutex>
- struct Lockable
- {
- BOOST_CONCEPT_ASSERT(( BasicLockable<Mutex> ));
- BOOST_CONCEPT_USAGE(Lockable)
- {
- if (l.try_lock()) return;
- }
- Lockable() : l(*static_cast<Mutex*>(0)) {}
- private:
- Lockable operator=(Lockable const&);
- Mutex& l;
- };
-
-
-
- template <typename Mutex>
- struct TimedLockable
- {
- BOOST_CONCEPT_ASSERT(( Lockable<Mutex> ));
- BOOST_CONCEPT_USAGE(TimedLockable)
- {
- if (l.try_lock_until(t)) return;
- if (l.try_lock_for(d)) return;
- }
- TimedLockable() : l(*static_cast<Mutex*>(0)) {}
- private:
- TimedLockable operator=(TimedLockable const&);
- Mutex& l;
- chrono::system_clock::time_point t;
- chrono::system_clock::duration d;
- };
-
-
-
- template <typename Mutex>
- struct SharedLockable
- {
- BOOST_CONCEPT_ASSERT(( TimedLockable<Mutex> ));
- BOOST_CONCEPT_USAGE(SharedLockable)
- {
- l.lock_shared();
- l.unlock_shared();
- if (l.try_lock_shared()) return;
- if (l.try_lock_shared_until(t)) return;
- if (l.try_lock_shared_for(d)) return;
- }
- SharedLockable() : l(*static_cast<Mutex*>(0)) {}
- private:
- SharedLockable operator=(SharedLockable const&);
- Mutex& l;
- chrono::system_clock::time_point t;
- chrono::system_clock::duration d;
- };
-
-
-
- template <typename Mutex>
- struct UpgradeLockable
- {
- BOOST_CONCEPT_ASSERT(( SharedLockable<Mutex> ));
- BOOST_CONCEPT_USAGE(UpgradeLockable)
- {
- l.lock_upgrade();
- l.unlock_upgrade();
- if (l.try_lock_upgrade()) return;
- if (l.try_lock_upgrade_until(t)) return;
- if (l.try_lock_upgrade_for(d)) return;
- if (l.try_unlock_shared_and_lock()) return;
- if (l.try_unlock_shared_and_lock_until(t)) return;
- if (l.try_unlock_shared_and_lock_for(d)) return;
- l.unlock_and_lock_shared();
- if (l.try_unlock_shared_and_lock_upgrade()) return;
- if (l.try_unlock_shared_and_lock_upgrade_until(t)) return;
- if (l.try_unlock_shared_and_lock_upgrade_for(d)) return;
- l.unlock_and_lock_upgrade();
- l.unlock_upgrade_and_lock();
- if (l.try_unlock_upgrade_and_lock()) return;
- if (l.try_unlock_upgrade_and_lock_until(t)) return;
- if (l.try_unlock_upgrade_and_lock_for(d)) return;
- l.unlock_upgrade_and_lock_shared();
- }
- UpgradeLockable() : l(*static_cast<Mutex*>(0)) {}
- private:
- UpgradeLockable operator=(UpgradeLockable const&);
- Mutex& l;
- chrono::system_clock::time_point t;
- chrono::system_clock::duration d;
- };
-
- }
- #endif
|