123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #ifndef BOOST_FLYWEIGHT_DETAIL_RECURSIVE_LW_MUTEX_HPP
- #define BOOST_FLYWEIGHT_DETAIL_RECURSIVE_LW_MUTEX_HPP
- #if defined(_MSC_VER)
- #pragma once
- #endif
- #include <boost/config.hpp>
- #if !defined(BOOST_NO_CXX11_HDR_MUTEX)
- #include <boost/noncopyable.hpp>
- #include <mutex>
- namespace boost{
- namespace flyweights{
- namespace detail{
- struct recursive_lightweight_mutex:noncopyable
- {
- recursive_lightweight_mutex(){}
- struct scoped_lock;
- friend struct scoped_lock;
- struct scoped_lock:noncopyable
- {
- public:
- scoped_lock(recursive_lightweight_mutex& m):m_(m.m_){m_.lock();}
- ~scoped_lock(){m_.unlock();}
- private:
- std::recursive_mutex& m_;
- };
- private:
- std::recursive_mutex m_;
- };
- }
- }
- }
- #elif defined(BOOST_HAS_PTHREADS)
- #include <boost/assert.hpp>
- #include <boost/noncopyable.hpp>
- #include <pthread.h>
- namespace boost{
- namespace flyweights{
- namespace detail{
- struct recursive_lightweight_mutex:noncopyable
- {
- recursive_lightweight_mutex()
- {
- pthread_mutexattr_t attr;
- BOOST_VERIFY(pthread_mutexattr_init(&attr)==0);
- BOOST_VERIFY(pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE)==0);
- BOOST_VERIFY(pthread_mutex_init(&m_,&attr)==0);
- BOOST_VERIFY(pthread_mutexattr_destroy(&attr)==0);
- }
- ~recursive_lightweight_mutex(){pthread_mutex_destroy(&m_);}
- struct scoped_lock;
- friend struct scoped_lock;
- struct scoped_lock:noncopyable
- {
- public:
- scoped_lock(recursive_lightweight_mutex& m):m_(m.m_)
- {
- BOOST_VERIFY(pthread_mutex_lock(&m_)==0);
- }
- ~scoped_lock(){BOOST_VERIFY(pthread_mutex_unlock(&m_)==0);}
- private:
- pthread_mutex_t& m_;
- };
- private:
- pthread_mutex_t m_;
- };
- }
- }
- }
- #elif defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
- #include <boost/smart_ptr/detail/lightweight_mutex.hpp>
- namespace boost{
- namespace flyweights{
- namespace detail{
- typedef boost::detail::lightweight_mutex recursive_lightweight_mutex;
- }
- }
- }
- #else
- namespace boost{
- namespace flyweights{
- namespace detail{
- struct recursive_lightweight_mutex
- {
- typedef recursive_lightweight_mutex scoped_lock;
- };
- }
- }
- }
- #endif
- #endif
|