mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
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
This commit is contained in:
parent
b0fc3f45bc
commit
a56267c468
1 changed files with 12 additions and 4 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue