Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:31

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2012-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/interprocess for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_INTERPROCESS_DETAIL_LOCKS_HPP
0012 #define BOOST_INTERPROCESS_DETAIL_LOCKS_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 #  pragma once
0020 #endif
0021 
0022 #include <boost/interprocess/detail/config_begin.hpp>
0023 #include <boost/interprocess/detail/workaround.hpp>
0024 
0025 namespace boost {
0026 namespace interprocess {
0027 namespace ipcdetail {
0028 
0029 template<class Lock>
0030 class internal_mutex_lock
0031 {
0032    typedef void (internal_mutex_lock::*unspecified_bool_type)();
0033    public:
0034 
0035    typedef typename Lock::mutex_type::internal_mutex_type  mutex_type;
0036 
0037 
0038    BOOST_INTERPROCESS_FORCEINLINE internal_mutex_lock(Lock &l)
0039       : l_(l)
0040    {}
0041 
0042    BOOST_INTERPROCESS_FORCEINLINE mutex_type* mutex() const
0043    {  return l_ ? &l_.mutex()->internal_mutex() : 0;  }
0044 
0045    BOOST_INTERPROCESS_FORCEINLINE void lock()    { l_.lock(); }
0046 
0047    BOOST_INTERPROCESS_FORCEINLINE void unlock()  { l_.unlock(); }
0048 
0049    BOOST_INTERPROCESS_FORCEINLINE operator unspecified_bool_type() const
0050    {  return l_ ? &internal_mutex_lock::lock : 0;  }
0051 
0052    private:
0053    Lock &l_;
0054 };
0055 
0056 template <class Lock>
0057 class lock_inverter
0058 {
0059    Lock &l_;
0060    public:
0061    BOOST_INTERPROCESS_FORCEINLINE lock_inverter(Lock &l)
0062       :  l_(l)
0063    {}
0064 
0065    BOOST_INTERPROCESS_FORCEINLINE void lock()    {   l_.unlock();   }
0066 
0067    BOOST_INTERPROCESS_FORCEINLINE void unlock()  {   l_.lock();     }
0068 };
0069 
0070 template <class Lock>
0071 class lock_to_sharable
0072 {
0073    Lock &l_;
0074 
0075    public:
0076    BOOST_INTERPROCESS_FORCEINLINE explicit lock_to_sharable(Lock &l)
0077       :  l_(l)
0078    {}
0079 
0080    BOOST_INTERPROCESS_FORCEINLINE void lock()    {  l_.lock_sharable();     }
0081 
0082    BOOST_INTERPROCESS_FORCEINLINE bool try_lock(){  return l_.try_lock_sharable(); }
0083 
0084    BOOST_INTERPROCESS_FORCEINLINE void unlock()  {  l_.unlock_sharable();   }
0085 };
0086 
0087 template <class Lock>
0088 class lock_to_wait
0089 {
0090    Lock &l_;
0091 
0092    public:
0093    BOOST_INTERPROCESS_FORCEINLINE explicit lock_to_wait(Lock &l)
0094       :  l_(l)
0095    {}
0096    BOOST_INTERPROCESS_FORCEINLINE void lock()     {  l_.wait();     }
0097 
0098    BOOST_INTERPROCESS_FORCEINLINE bool try_lock() {  return l_.try_wait(); }
0099 
0100    template<class TimePoint>
0101    BOOST_INTERPROCESS_FORCEINLINE bool timed_lock(const TimePoint &abs_time)
0102       {  return l_.timed_wait(abs_time);   }
0103 };
0104 
0105 }  //namespace ipcdetail
0106 }  //namespace interprocess
0107 }  //namespace boost
0108 
0109 #include <boost/interprocess/detail/config_end.hpp>
0110 
0111 #endif   //BOOST_INTERPROCESS_DETAIL_LOCKS_HPP