Boost logo

Boost Users :

Subject: [Boost-users] [smart_ptr] No locks in quick allocator for shared pointers
From: Manish Vachharajani (manishv_at_[hidden])
Date: 2010-07-21 14:31:56


I was wondering if there was a standard way to turn off locks in the
quick allocator for smart_ptr without disabling threading for all of
Boost?

It appears that the scoped_locks in the quick allocator are controlled
by BOOST_HAS_THREADS. In turn, BOOST_HAS_THREADS seems to be
controllable via BOOST_DISABLE_THREADS. However, I do not want to use
this option as I need to link multiple programs against the same boost
non-header libraries. Some programs have threading others do not. I
want to be able to selectively disable locking for the non-threaded
programs.

If there is not better way to do this, the patch below adds a
BOOST_QA_DISABLE_THREADS that will eliminate the scoped locks.

---
 .../boost/smart_ptr/detail/quick_allocator.hpp     |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/ext/boost_1_43_0/boost/smart_ptr/detail/quick_allocator.hpp
b/ext/boost_1_43_0/boost/smart_ptr/detail/quick_allocator.hpp
index 159bd5e..ed878cb 100644
--- a/ext/boost_1_43_0/boost/smart_ptr/detail/quick_allocator.hpp
+++ b/ext/boost_1_43_0/boost/smart_ptr/detail/quick_allocator.hpp
@@ -70,7 +70,7 @@ template<unsigned size, unsigned align_> struct allocator_impl
 #endif
-#ifdef BOOST_HAS_THREADS
+#if defined(BOOST_HAS_THREADS) && !defined(BOOST_QA_DISABLE_THREADS)
     static lightweight_mutex & mutex()
     {
@@ -89,7 +89,7 @@ template<unsigned size, unsigned align_> struct allocator_impl
     static inline void * alloc()
     {
-#ifdef BOOST_HAS_THREADS
+#if defined(BOOST_HAS_THREADS) && !defined(BOOST_QA_DISABLE_THREADS)
         lightweight_mutex::scoped_lock lock( mutex() );
 #endif
         if(block * x = free)
@@ -119,7 +119,7 @@ template<unsigned size, unsigned align_> struct
allocator_impl
         }
         else
         {
-#ifdef BOOST_HAS_THREADS
+#if defined(BOOST_HAS_THREADS) && !defined(BOOST_QA_DISABLE_THREADS)
             lightweight_mutex::scoped_lock lock( mutex() );
 #endif
             if(block * x = free)
@@ -144,7 +144,7 @@ template<unsigned size, unsigned align_> struct
allocator_impl
     {
         if(pv != 0) // 18.4.1.1/13
         {
-#ifdef BOOST_HAS_THREADS
+#if defined(BOOST_HAS_THREADS) && !defined(BOOST_QA_DISABLE_THREADS)
             lightweight_mutex::scoped_lock lock( mutex() );
 #endif
             block * pb = static_cast<block *>(pv);
@@ -161,7 +161,7 @@ template<unsigned size, unsigned align_> struct
allocator_impl
         }
         else if(pv != 0) // 18.4.1.1/13
         {
-#ifdef BOOST_HAS_THREADS
+#if defined(BOOST_HAS_THREADS) && !defined(BOOST_QA_DISABLE_THREADS)
             lightweight_mutex::scoped_lock lock( mutex() );
 #endif
             block * pb = static_cast<block *>(pv);
@@ -171,7 +171,7 @@ template<unsigned size, unsigned align_> struct
allocator_impl
     }
 };
-#ifdef BOOST_HAS_THREADS
+#if defined(BOOST_HAS_THREADS) && !defined(BOOST_QA_DISABLE_THREADS)
 template<unsigned size, unsigned align_>
   lightweight_mutex * allocator_impl<size, align_>::mutex_init =
&allocator_impl<size, align_>::mutex();
-- 
1.7.0.1
Manish

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net