File indexing completed on 2025-01-18 09:42:09
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_MULTI_INDEX_DETAIL_SCOPED_BILOCK_HPP
0010 #define BOOST_MULTI_INDEX_DETAIL_SCOPED_BILOCK_HPP
0011
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015
0016 #include <boost/core/noncopyable.hpp>
0017 #include <boost/type_traits/aligned_storage.hpp>
0018 #include <boost/type_traits/alignment_of.hpp>
0019 #include <functional>
0020 #include <new>
0021
0022 namespace boost{
0023
0024 namespace multi_index{
0025
0026 namespace detail{
0027
0028
0029
0030
0031
0032
0033 template<typename Mutex>
0034 class scoped_bilock:private noncopyable
0035 {
0036 public:
0037 scoped_bilock(Mutex& mutex1,Mutex& mutex2):mutex_eq(&mutex1==&mutex2)
0038 {
0039 bool mutex_lt=std::less<Mutex*>()(&mutex1,&mutex2);
0040
0041 ::new (static_cast<void*>(&lock1)) scoped_lock(mutex_lt?mutex1:mutex2);
0042 if(!mutex_eq)
0043 ::new (static_cast<void*>(&lock2)) scoped_lock(mutex_lt?mutex2:mutex1);
0044 }
0045
0046 ~scoped_bilock()
0047 {
0048 reinterpret_cast<scoped_lock*>(&lock1)->~scoped_lock();
0049 if(!mutex_eq)
0050 reinterpret_cast<scoped_lock*>(&lock2)->~scoped_lock();
0051 }
0052
0053 private:
0054 typedef typename Mutex::scoped_lock scoped_lock;
0055 typedef typename aligned_storage<
0056 sizeof(scoped_lock),
0057 alignment_of<scoped_lock>::value
0058 >::type scoped_lock_space;
0059
0060 bool mutex_eq;
0061 scoped_lock_space lock1,lock2;
0062 };
0063
0064 }
0065
0066 }
0067
0068 }
0069
0070 #endif