diff --git a/include/turtle/detail/sequence_impl.hpp b/include/turtle/detail/sequence_impl.hpp index 26ad742..ac40080 100644 --- a/include/turtle/detail/sequence_impl.hpp +++ b/include/turtle/detail/sequence_impl.hpp @@ -10,6 +10,7 @@ #define MOCK_SEQUENCE_IMPL_HPP_INCLUDED #include "../config.hpp" +#include "mutex.hpp" #include #include #include @@ -22,24 +23,30 @@ namespace detail class sequence_impl : private boost::noncopyable { public: + sequence_impl() : mutex_( boost::make_shared< mutex >() ) {} + void add( void* e ) { + lock _( mutex_ ); elements_.push_back( e ); } void remove( void* e ) { + lock _( mutex_ ); elements_.erase( std::remove( elements_.begin(), elements_.end(), e ), elements_.end() ); } bool is_valid( const void* e ) const { + lock _( mutex_ ); return std::find( elements_.begin(), elements_.end(), e ) != elements_.end(); } void invalidate( const void* e ) { + lock _( mutex_ ); elements_type::iterator it = std::find( elements_.begin(), elements_.end(), e ); if( it != elements_.end() ) @@ -50,6 +57,8 @@ namespace detail typedef std::vector< void* > elements_type; elements_type elements_; + + const boost::shared_ptr< mutex > mutex_; }; } } // mock diff --git a/include/turtle/sequence.hpp b/include/turtle/sequence.hpp index f3009ca..051d219 100644 --- a/include/turtle/sequence.hpp +++ b/include/turtle/sequence.hpp @@ -10,8 +10,8 @@ #define MOCK_SEQUENCE_HPP_INCLUDED #include "config.hpp" -#include "detail/sequence_impl.hpp" #include +#include "detail/sequence_impl.hpp" namespace mock {