From a56267c468c9fae1b4010e11ff91955e547163b3 Mon Sep 17 00:00:00 2001 From: mat007 Date: Wed, 21 May 2014 07:09:28 +0000 Subject: [PATCH] Fixed race condition for C++03 compilers git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@733 860be788-9bd5-4423-9f1e-828f051e677b --- turtle/detail/functor.hpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/turtle/detail/functor.hpp b/turtle/detail/functor.hpp index b45f3a1..b5c777e 100644 --- a/turtle/detail/functor.hpp +++ b/turtle/detail/functor.hpp @@ -17,23 +17,31 @@ namespace mock { namespace detail { + class functor_mutex_t : + public boost::unit_test::singleton< functor_mutex_t >, + public mutex + { + private: + BOOST_TEST_SINGLETON_CONS( functor_mutex_t ); + }; + BOOST_TEST_SINGLETON_INST( functor_mutex ) + template< typename Signature > struct functor : function< Signature > { functor() { - static mutex m_; - scoped_lock _( m_ ); + scoped_lock _( functor_mutex ); static functor* f = 0; if( f ) { *this = *f; f = 0; - m_.unlock(); + functor_mutex.unlock(); } else { - m_.lock(); + functor_mutex.lock(); f = this; } }