spinlock_nt.hpp
Go to the documentation of this file.
00001 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED
00002 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED
00003 
00004 // MS compatible compilers support #pragma once
00005 
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009 
00010 //
00011 //  Copyright (c) 2008 Peter Dimov
00012 //
00013 //  Distributed under the Boost Software License, Version 1.0.
00014 //  See accompanying file LICENSE_1_0.txt or copy at
00015 //  http://www.boost.org/LICENSE_1_0.txt)
00016 //
00017 
00018 #include <boost/assert.hpp>
00019 
00020 namespace boost
00021 {
00022 
00023 namespace detail
00024 {
00025 
00026 class spinlock
00027 {
00028 public:
00029 
00030     bool locked_;
00031 
00032 public:
00033 
00034     inline bool try_lock()
00035     {
00036         if( locked_ )
00037         {
00038             return false;
00039         }
00040         else
00041         {
00042             locked_ = true;
00043             return true;
00044         }
00045     }
00046 
00047     inline void lock()
00048     {
00049         BOOST_ASSERT( !locked_ );
00050         locked_ = true;
00051     }
00052 
00053     inline void unlock()
00054     {
00055         BOOST_ASSERT( locked_ );
00056         locked_ = false;
00057     }
00058 
00059 public:
00060 
00061     class scoped_lock
00062     {
00063     private:
00064 
00065         spinlock & sp_;
00066 
00067         scoped_lock( scoped_lock const & );
00068         scoped_lock & operator=( scoped_lock const & );
00069 
00070     public:
00071 
00072         explicit scoped_lock( spinlock & sp ): sp_( sp )
00073         {
00074             sp.lock();
00075         }
00076 
00077         ~scoped_lock()
00078         {
00079             sp_.unlock();
00080         }
00081     };
00082 };
00083 
00084 } // namespace detail
00085 } // namespace boost
00086 
00087 #define BOOST_DETAIL_SPINLOCK_INIT { false }
00088 
00089 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29