From 991436303db4b1006d0967fc79b2ae8b6c5c457c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 6 Dec 2005 12:24:40 +0000 Subject: [PATCH] Fixed bug #1370716, static shared_ptr instances not working w/ quick_allocator [SVN r31931] --- include/boost/detail/quick_allocator.hpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/include/boost/detail/quick_allocator.hpp b/include/boost/detail/quick_allocator.hpp index eb6398c..7c19d0f 100644 --- a/include/boost/detail/quick_allocator.hpp +++ b/include/boost/detail/quick_allocator.hpp @@ -71,7 +71,15 @@ template struct allocator_impl #endif #ifdef BOOST_HAS_THREADS - static lightweight_mutex mutex; + + static lightweight_mutex & mutex() + { + static lightweight_mutex m; + return m; + } + + static lightweight_mutex * mutex_init; + #endif static block * free; @@ -81,7 +89,7 @@ template struct allocator_impl static inline void * alloc() { #ifdef BOOST_HAS_THREADS - lightweight_mutex::scoped_lock lock(mutex); + lightweight_mutex::scoped_lock lock( mutex() ); #endif if(block * x = free) { @@ -111,7 +119,7 @@ template struct allocator_impl else { #ifdef BOOST_HAS_THREADS - lightweight_mutex::scoped_lock lock(mutex); + lightweight_mutex::scoped_lock lock( mutex() ); #endif if(block * x = free) { @@ -136,7 +144,7 @@ template struct allocator_impl if(pv != 0) // 18.4.1.1/13 { #ifdef BOOST_HAS_THREADS - lightweight_mutex::scoped_lock lock(mutex); + lightweight_mutex::scoped_lock lock( mutex() ); #endif block * pb = static_cast(pv); pb->next = free; @@ -153,7 +161,7 @@ template struct allocator_impl else if(pv != 0) // 18.4.1.1/13 { #ifdef BOOST_HAS_THREADS - lightweight_mutex::scoped_lock lock(mutex); + lightweight_mutex::scoped_lock lock( mutex() ); #endif block * pb = static_cast(pv); pb->next = free; @@ -163,8 +171,10 @@ template struct allocator_impl }; #ifdef BOOST_HAS_THREADS + template - lightweight_mutex allocator_impl::mutex; + lightweight_mutex allocator_impl::mutex_init = &lightweight_mutex allocator_impl::mutex(); + #endif template