mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Removed all copies of the wrapper object
This commit is contained in:
parent
4eadca553b
commit
04497bd5b5
6 changed files with 54 additions and 18 deletions
|
|
@ -133,9 +133,9 @@ namespace detail
|
|||
>
|
||||
> () )
|
||||
, file_( "unknown location" )
|
||||
, line_( 0 )
|
||||
, line_( 0 )
|
||||
#if defined(MOCK_THREAD_SAFE)
|
||||
, blocked(ATOMIC_VAR_INIT(false))
|
||||
, blocked(false)
|
||||
#endif
|
||||
{ }
|
||||
expectation( const char* file, int line )
|
||||
|
|
@ -149,10 +149,20 @@ namespace detail
|
|||
, file_( file )
|
||||
, line_( line )
|
||||
#if defined(MOCK_THREAD_SAFE)
|
||||
, blocked(ATOMIC_VAR_INIT(false))
|
||||
, blocked(false)
|
||||
#endif
|
||||
{ }
|
||||
|
||||
expectation(expectation && e)
|
||||
: invocation_ ( e.invocation_)
|
||||
, matcher_(e.matcher_)
|
||||
, file_(e.file_)
|
||||
, line_(e.line_)
|
||||
#if defined(MOCK_THREAD_SAFE)
|
||||
, blocked(false)
|
||||
#endif
|
||||
{}
|
||||
|
||||
~expectation()
|
||||
{
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
|
|
@ -197,7 +207,7 @@ namespace detail
|
|||
expectation &async(const duration timeout)
|
||||
{
|
||||
timeout_ = timeout;
|
||||
blocked = false;
|
||||
blocked.store(false,std::memory_order_release);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -220,7 +230,7 @@ namespace detail
|
|||
{
|
||||
if (MOCK_THREAD_NAMESPACE::cv_status::timeout == cv->wait_for(lk.get_unique_lock(), *timeout_))
|
||||
{
|
||||
std::atomic_store(&blocked,true);
|
||||
blocked.store(true, std::memory_order_release);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -232,7 +242,7 @@ namespace detail
|
|||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, a) ) const
|
||||
{
|
||||
#if defined(MOCK_THREAD_SAFE)
|
||||
return !blocked && !invocation_->exhausted()
|
||||
return !blocked.load(std::memory_order_acquire) && !invocation_->exhausted()
|
||||
&& (*matcher_)( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, a) );
|
||||
#else
|
||||
return !invocation_->exhausted()
|
||||
|
|
@ -294,7 +304,7 @@ namespace detail
|
|||
int line_;
|
||||
#if defined(MOCK_THREAD_SAFE)
|
||||
boost::optional<nanoseconds> timeout_;
|
||||
mutable std::atomic_bool blocked;
|
||||
mutable std::atomic<bool> blocked;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,10 @@ namespace detail
|
|||
: e_( &e )
|
||||
{}
|
||||
|
||||
wrapper_base( wrapper_base && w )
|
||||
: e_( w.e_ )
|
||||
{}
|
||||
|
||||
template< typename T >
|
||||
void returns( T t )
|
||||
{
|
||||
|
|
@ -64,6 +68,11 @@ namespace detail
|
|||
: e_( &e )
|
||||
{}
|
||||
|
||||
wrapper_base( wrapper_base && w )
|
||||
: e_( w.e_ )
|
||||
{}
|
||||
|
||||
|
||||
E* e_;
|
||||
};
|
||||
template< typename R, typename E >
|
||||
|
|
@ -73,6 +82,10 @@ namespace detail
|
|||
: e_( &e )
|
||||
{}
|
||||
|
||||
wrapper_base( wrapper_base && w )
|
||||
: e_( w.e_ )
|
||||
{}
|
||||
|
||||
void returns( R* r )
|
||||
{
|
||||
e_->returns( r );
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ namespace detail
|
|||
}
|
||||
return valid_;
|
||||
}
|
||||
|
||||
|
||||
virtual void reset()
|
||||
{
|
||||
lock _( mutex_ );
|
||||
|
|
@ -112,9 +112,16 @@ namespace detail
|
|||
: wrapper_base< R, expectation_type >( e )
|
||||
, lock_( m )
|
||||
{}
|
||||
|
||||
|
||||
wrapper(const wrapper &) = delete;
|
||||
|
||||
wrapper( wrapper && w)
|
||||
: wrapper_base< R, expectation_type > (*w.e_)
|
||||
, lock_( std::move(w.lock_) )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
wrapper &once()
|
||||
{
|
||||
this->e_->invoke( boost::make_shared< detail::once >() );
|
||||
|
|
|
|||
|
|
@ -41,13 +41,19 @@ namespace detail
|
|||
typedef MOCK_THREAD_NAMESPACE::condition_variable_any condition_variable;
|
||||
typedef MOCK_THREAD_NAMESPACE::chrono::nanoseconds nanoseconds;
|
||||
typedef MOCK_THREAD_NAMESPACE::unique_lock<mutex> lock_base;
|
||||
|
||||
struct lock : public lock_base
|
||||
|
||||
struct lock : public lock_base
|
||||
{
|
||||
lock(const boost::shared_ptr< detail::mutex > &m)
|
||||
: lock_base (*m)
|
||||
, m_(m)
|
||||
{}
|
||||
|
||||
lock(lock && l)
|
||||
: lock_base(*l.m_)
|
||||
, m_(l.m_)
|
||||
{
|
||||
}
|
||||
~lock()
|
||||
{
|
||||
unlock();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue