Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:43

0001 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_PT_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_PT_HPP_INCLUDED
0003 
0004 // MS compatible compilers support #pragma once
0005 
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009 
0010 //
0011 //  Copyright (c) 2008 Peter Dimov
0012 //
0013 //  Distributed under the Boost Software License, Version 1.0.
0014 //  See accompanying file LICENSE_1_0.txt or copy at
0015 //  http://www.boost.org/LICENSE_1_0.txt)
0016 //
0017 
0018 #include <pthread.h>
0019 
0020 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0021 
0022 #include <boost/config/pragma_message.hpp>
0023 BOOST_PRAGMA_MESSAGE("Using pthread_mutex spinlock emulation")
0024 
0025 #endif
0026 
0027 namespace boost
0028 {
0029 
0030 namespace detail
0031 {
0032 
0033 class spinlock
0034 {
0035 public:
0036 
0037     pthread_mutex_t v_;
0038 
0039 public:
0040 
0041     bool try_lock()
0042     {
0043         return pthread_mutex_trylock( &v_ ) == 0;
0044     }
0045 
0046     void lock()
0047     {
0048         pthread_mutex_lock( &v_ );
0049     }
0050 
0051     void unlock()
0052     {
0053         pthread_mutex_unlock( &v_ );
0054     }
0055 
0056 public:
0057 
0058     class scoped_lock
0059     {
0060     private:
0061 
0062         spinlock & sp_;
0063 
0064         scoped_lock( scoped_lock const & );
0065         scoped_lock & operator=( scoped_lock const & );
0066 
0067     public:
0068 
0069         explicit scoped_lock( spinlock & sp ): sp_( sp )
0070         {
0071             sp.lock();
0072         }
0073 
0074         ~scoped_lock()
0075         {
0076             sp_.unlock();
0077         }
0078     };
0079 };
0080 
0081 } // namespace detail
0082 } // namespace boost
0083 
0084 #define BOOST_DETAIL_SPINLOCK_INIT { PTHREAD_MUTEX_INITIALIZER }
0085 
0086 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_PT_HPP_INCLUDED