mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Merge pull request #12 from robwiss/master
added locking to sequence_impl
This commit is contained in:
commit
0c22da9627
2 changed files with 10 additions and 1 deletions
|
|
@ -10,6 +10,7 @@
|
|||
#define MOCK_SEQUENCE_IMPL_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <algorithm>
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
#define MOCK_SEQUENCE_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "detail/sequence_impl.hpp"
|
||||
#include <boost/make_shared.hpp>
|
||||
#include "detail/sequence_impl.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue