-//$$CDS-header$$
+/*
+ This file is a part of libcds - Concurrent Data Structures library
+
+ (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
+
+ Source code repo: http://github.com/khizmax/libcds/
+ Download: http://sourceforge.net/projects/libcds/files/
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
#ifndef CDSLIB_BACKOFF_STRATEGY_H
#define CDSLIB_BACKOFF_STRATEGY_H
{}
template <typename Predicate>
- bool operator()(Predicate pr) CDS_NOEXCEPT_( noexcept(std::declval<Predicate>()() ))
+ bool operator()(Predicate pr) const CDS_NOEXCEPT_( noexcept(std::declval<Predicate>()()))
{
return pr();
}
- void reset() const CDS_NOEXCEPT
+ static void reset() CDS_NOEXCEPT
{}
//@endcond
};
/// Switch to another thread (yield). Good for thread preemption architecture.
struct yield {
//@cond
- void operator ()() CDS_NOEXCEPT
+ void operator ()() const CDS_NOEXCEPT
{
std::this_thread::yield();
}
template <typename Predicate>
- bool operator()(Predicate pr) CDS_NOEXCEPT_( noexcept(std::declval<Predicate>()() ))
+ bool operator()(Predicate pr) const CDS_NOEXCEPT_( noexcept(std::declval<Predicate>()()))
{
- if ( pr() )
+ if ( pr())
return true;
operator()();
return false;
}
- void reset() const CDS_NOEXCEPT
+ static void reset() CDS_NOEXCEPT
{}
//@endcond
};
*/
struct pause {
//@cond
- void operator ()() CDS_NOEXCEPT
+ void operator ()() const CDS_NOEXCEPT
{
# ifdef CDS_backoff_pause_defined
platform::backoff_pause();
}
template <typename Predicate>
- bool operator()(Predicate pr) CDS_NOEXCEPT_( noexcept(std::declval<Predicate>()() ))
+ bool operator()(Predicate pr) const CDS_NOEXCEPT_( noexcept(std::declval<Predicate>()()))
{
- if ( pr() )
+ if ( pr())
return true;
operator()();
return false;
}
- void reset() const CDS_NOEXCEPT
+ static void reset() CDS_NOEXCEPT
{}
//@endcond
};
struct hint
{
//@cond
- void operator ()() CDS_NOEXCEPT
+ void operator ()() const CDS_NOEXCEPT
{
# if defined(CDS_backoff_hint_defined)
platform::backoff_hint();
}
template <typename Predicate>
- bool operator()(Predicate pr) CDS_NOEXCEPT_(noexcept(std::declval<Predicate>()() ))
+ bool operator()(Predicate pr) const CDS_NOEXCEPT_(noexcept(std::declval<Predicate>()()))
{
- if ( pr() )
+ if ( pr())
return true;
operator()();
return false;
}
- void reset() const CDS_NOEXCEPT
+ static void reset() CDS_NOEXCEPT
{}
//@endcond
};
}
template <typename Predicate>
- bool operator()( Predicate pr ) CDS_NOEXCEPT_( noexcept(std::declval<Predicate>()()) && noexcept(std::declval<spin_backoff>()()) && noexcept(std::declval<yield_backoff>()() ))
+ bool operator()( Predicate pr ) CDS_NOEXCEPT_( noexcept(std::declval<Predicate>()()) && noexcept(std::declval<spin_backoff>()()) && noexcept(std::declval<yield_backoff>()()))
{
if ( m_nExpCur <= m_nExpMax ) {
for ( size_t n = 0; n < m_nExpCur; ++n ) {
- if ( m_bkSpin(pr) )
+ if ( m_bkSpin(pr))
return true;
}
m_nExpCur *= 2;
return false;
}
- void reset() CDS_NOEXCEPT_( noexcept( std::declval<spin_backoff>().reset() ) && noexcept( std::declval<yield_backoff>().reset() ))
+ void reset() CDS_NOEXCEPT_( noexcept( std::declval<spin_backoff>().reset()) && noexcept( std::declval<yield_backoff>().reset()))
{
m_nExpCur = m_nExpMin;
m_bkSpin.reset();
{}
/// Initializes timeout from \p nTimeout
- CDS_CONSTEXPR delay( unsigned int nTimeout ) CDS_NOEXCEPT
+ CDS_CONSTEXPR explicit delay( unsigned int nTimeout ) CDS_NOEXCEPT
: m_nTimeout( nTimeout )
{}
bool operator()(Predicate pr) const
{
for ( unsigned int i = 0; i < m_nTimeout; i += 2 ) {
- if ( pr() )
+ if ( pr())
return true;
std::this_thread::sleep_for( duration_type( 2 ));
}
return false;
}
- void reset() const CDS_NOEXCEPT
+ static void reset() CDS_NOEXCEPT
{}
//@endcond
};