Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:09:31

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Vicente J. Botet Escriba 2008-2009,2012. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/thread for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_THREAD_LOCKABLE_ADAPTER_HPP
0012 #define BOOST_THREAD_LOCKABLE_ADAPTER_HPP
0013 
0014 #include <boost/thread/detail/delete.hpp>
0015 #include <boost/chrono/chrono.hpp>
0016 
0017 namespace boost
0018 {
0019 
0020   //[basic_lockable_adapter
0021   template <typename BasicLockable>
0022   class basic_lockable_adapter
0023   {
0024   public:
0025     typedef BasicLockable mutex_type;
0026 
0027   protected:
0028     mutex_type& lockable() const
0029     {
0030       return lockable_;
0031     }
0032     mutable mutex_type lockable_; /*< mutable so that it can be modified by const functions >*/
0033   public:
0034 
0035     BOOST_THREAD_NO_COPYABLE( basic_lockable_adapter) /*< no copyable >*/
0036 
0037     basic_lockable_adapter()
0038     {}
0039 
0040     void lock() const
0041     {
0042       lockable().lock();
0043     }
0044     void unlock() const
0045     {
0046       lockable().unlock();
0047     }
0048 
0049   };
0050   //]
0051 
0052   //[lockable_adapter
0053   template <typename Lockable>
0054   class lockable_adapter : public basic_lockable_adapter<Lockable>
0055   {
0056   public:
0057     typedef Lockable mutex_type;
0058 
0059     bool try_lock() const
0060     {
0061       return this->lockable().try_lock();
0062     }
0063   };
0064   //]
0065 
0066   //[timed_lockable_adapter
0067   template <typename TimedLock>
0068   class timed_lockable_adapter: public lockable_adapter<TimedLock>
0069   {
0070   public:
0071     typedef TimedLock mutex_type;
0072 
0073     template <typename Clock, typename Duration>
0074     bool try_lock_until(chrono::time_point<Clock, Duration> const & abs_time) const
0075     {
0076       return this->lockable().try_lock_until(abs_time);
0077     }
0078     template <typename Rep, typename Period>
0079     bool try_lock_for(chrono::duration<Rep, Period> const & rel_time) const
0080     {
0081       return this->lockable().try_lock_for(rel_time);
0082     }
0083 
0084   };
0085   //]
0086 
0087   //[shared_lockable_adapter
0088   template <typename SharableLock>
0089   class shared_lockable_adapter: public timed_lockable_adapter<SharableLock>
0090   {
0091   public:
0092     typedef SharableLock mutex_type;
0093 
0094     void lock_shared() const
0095     {
0096       this->lockable().lock_shared();
0097     }
0098     bool try_lock_shared() const
0099     {
0100       return this->lockable().try_lock_shared();
0101     }
0102     void unlock_shared() const
0103     {
0104       this->lockable().unlock_shared();
0105     }
0106 
0107     template <typename Clock, typename Duration>
0108     bool try_lock_shared_until(chrono::time_point<Clock, Duration> const & abs_time) const
0109     {
0110       return this->lockable().try_lock_shared_until(abs_time);
0111     }
0112     template <typename Rep, typename Period>
0113     bool try_lock_shared_for(chrono::duration<Rep, Period> const & rel_time) const
0114     {
0115       return this->lockable().try_lock_shared_for(rel_time);
0116     }
0117 
0118   };
0119 
0120   //]
0121 
0122   //[upgrade_lockable_adapter
0123   template <typename UpgradableLock>
0124   class upgrade_lockable_adapter: public shared_lockable_adapter<UpgradableLock>
0125   {
0126   public:
0127     typedef UpgradableLock mutex_type;
0128 
0129     void lock_upgrade() const
0130     {
0131       this->lockable().lock_upgrade();
0132     }
0133 
0134     bool try_lock_upgrade() const
0135     {
0136       return this->lockable().try_lock_upgrade();
0137     }
0138 
0139     void unlock_upgrade() const
0140     {
0141       this->lockable().unlock_upgrade();
0142     }
0143 
0144     template <typename Clock, typename Duration>
0145     bool try_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time) const
0146     {
0147       return this->lockable().try_lock_upgrade_until(abs_time);
0148     }
0149     template <typename Rep, typename Period>
0150     bool try_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time) const
0151     {
0152       return this->lockable().try_lock_upgrade_for(rel_time);
0153     }
0154 
0155     bool try_unlock_shared_and_lock() const
0156     {
0157       return this->lockable().try_unlock_shared_and_lock();
0158     }
0159 
0160     template <typename Clock, typename Duration>
0161     bool try_unlock_shared_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time) const
0162     {
0163       return this->lockable().try_unlock_shared_and_lock_until(abs_time);
0164     }
0165     template <typename Rep, typename Period>
0166     bool try_unlock_shared_and_lock_for(chrono::duration<Rep, Period> const & rel_time) const
0167     {
0168       return this->lockable().try_unlock_shared_and_lock_for(rel_time);
0169     }
0170 
0171     void unlock_and_lock_shared() const
0172     {
0173       this->lockable().unlock_and_lock_shared();
0174     }
0175 
0176     bool try_unlock_shared_and_lock_upgrade() const
0177     {
0178       return this->lockable().try_unlock_shared_and_lock_upgrade();
0179     }
0180 
0181     template <typename Clock, typename Duration>
0182     bool try_unlock_shared_and_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time) const
0183     {
0184       return this->lockable().try_unlock_shared_and_lock_upgrade_until(abs_time);
0185     }
0186     template <typename Rep, typename Period>
0187     bool try_unlock_shared_and_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time) const
0188     {
0189       return this->lockable().try_unlock_shared_and_lock_upgrade_for(rel_time);
0190     }
0191 
0192     void unlock_and_lock_upgrade() const
0193     {
0194       this->lockable().unlock_and_lock_upgrade();
0195     }
0196 
0197     void unlock_upgrade_and_lock() const
0198     {
0199       this->lockable().unlock_upgrade_and_lock();
0200     }
0201 
0202     bool try_unlock_upgrade_and_lock() const
0203     {
0204       return this->lockable().try_unlock_upgrade_and_lock();
0205     }
0206     template <typename Clock, typename Duration>
0207     bool try_unlock_upgrade_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time) const
0208     {
0209       return this->lockable().try_unlock_upgrade_and_lock_until(abs_time);
0210     }
0211     template <typename Rep, typename Period>
0212     bool try_unlock_upgrade_and_lock_for(chrono::duration<Rep, Period> const & rel_time) const
0213     {
0214       return this->lockable().try_unlock_upgrade_and_lock_for(rel_time);
0215     }
0216 
0217     void unlock_upgrade_and_lock_shared() const
0218     {
0219       this->lockable().unlock_upgrade_and_lock_shared();
0220     }
0221 
0222   };
0223 //]
0224 
0225 }
0226 #endif