X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=blobdiff_plain;f=cds%2Falgo%2Fbackoff_strategy.h;h=c80ea829d43d365d7a55d220c4a13dabb98b1b4e;hp=24852bbafb294811314be6de3fde571b2e75f331;hb=25f6df95be1521466e78b4db7a1bf34da590f41f;hpb=f6c63698d567fc5c70556130c5ba9bed9a18d5b6 diff --git a/cds/algo/backoff_strategy.h b/cds/algo/backoff_strategy.h index 24852bba..c80ea829 100644 --- a/cds/algo/backoff_strategy.h +++ b/cds/algo/backoff_strategy.h @@ -16,9 +16,9 @@ 2009.09.10 Maxim Khiszinsky reset() function added */ +#include +#include #include -#include -#include namespace cds { /// Different backoff schemes @@ -55,16 +55,16 @@ namespace cds { /// Empty backoff strategy. Do nothing struct empty { //@cond - void operator ()() + void operator ()() const CDS_NOEXCEPT {} template - bool operator()( Predicate pr ) + bool operator()(Predicate pr) CDS_NOEXCEPT { return pr(); } - void reset() + void reset() const CDS_NOEXCEPT {} //@endcond }; @@ -72,14 +72,13 @@ namespace cds { /// Switch to another thread (yield). Good for thread preemption architecture. struct yield { //@cond - void operator ()() + void operator ()() CDS_NOEXCEPT { - cds_std::this_thread::yield(); - //OS::yield(); + std::this_thread::yield(); } template - bool operator()( Predicate pr ) + bool operator()( Predicate pr ) CDS_NOEXCEPT { if ( pr() ) return true; @@ -87,7 +86,7 @@ namespace cds { return false; } - void reset() + void reset() const CDS_NOEXCEPT {} //@endcond }; @@ -99,7 +98,7 @@ namespace cds { */ struct pause { //@cond - void operator ()() + void operator ()() CDS_NOEXCEPT { # ifdef CDS_backoff_pause_defined platform::backoff_pause(); @@ -107,7 +106,7 @@ namespace cds { } template - bool operator()( Predicate pr ) + bool operator()( Predicate pr ) CDS_NOEXCEPT { if ( pr() ) return true; @@ -115,7 +114,7 @@ namespace cds { return false; } - void reset() + void reset() const CDS_NOEXCEPT {} //@endcond }; @@ -128,7 +127,7 @@ namespace cds { struct hint { //@cond - void operator ()() + void operator ()() CDS_NOEXCEPT { # if defined(CDS_backoff_hint_defined) platform::backoff_hint(); @@ -138,7 +137,7 @@ namespace cds { } template - bool operator()( Predicate pr ) + bool operator()( Predicate pr ) CDS_NOEXCEPT { if ( pr() ) return true; @@ -146,7 +145,7 @@ namespace cds { return false; } - void reset() + void reset() const CDS_NOEXCEPT {} //@endcond }; @@ -231,7 +230,7 @@ namespace cds { public: /// Initializes m_nExpMin and m_nExpMax from default s_nExpMin and s_nExpMax respectively - exponential() + exponential() CDS_NOEXCEPT : m_nExpMin( s_nExpMin ) , m_nExpMax( s_nExpMax ) { @@ -245,7 +244,7 @@ namespace cds { exponential( size_t nExpMin, ///< Minimum spinning size_t nExpMax ///< Maximum spinning - ) + ) CDS_NOEXCEPT : m_nExpMin( nExpMin ) , m_nExpMax( nExpMax ) { @@ -253,7 +252,7 @@ namespace cds { } //@cond - void operator ()() + void operator ()() CDS_NOEXCEPT_(noexcept(spin_backoff()()) && noexcept(yield_backoff()())) { if ( m_nExpCur <= m_nExpMax ) { for ( size_t n = 0; n < m_nExpCur; ++n ) @@ -265,7 +264,7 @@ namespace cds { } template - bool operator()( Predicate pr ) + bool operator()( Predicate pr ) CDS_NOEXCEPT_(noexcept( spin_backoff()()) && noexcept( yield_backoff()())) { if ( m_nExpCur <= m_nExpMax ) { for ( size_t n = 0; n < m_nExpCur; ++n ) { @@ -279,7 +278,7 @@ namespace cds { return false; } - void reset() + void reset() CDS_NOEXCEPT_(noexcept(spin_backoff().reset()) && noexcept(yield_backoff().reset())) { m_nExpCur = m_nExpMin; m_bkSpin.reset(); @@ -342,7 +341,7 @@ namespace cds { \endcode */ - template + template class delay { public: @@ -356,33 +355,33 @@ namespace cds { public: /// Default ctor takes the timeout from s_nTimeout - delay() + delay() CDS_NOEXCEPT : m_nTimeout( s_nTimeout ) {} /// Initializes timeout from \p nTimeout - CDS_CONSTEXPR delay( unsigned int nTimeout ) + CDS_CONSTEXPR delay( unsigned int nTimeout ) CDS_NOEXCEPT : m_nTimeout( nTimeout ) {} //@cond - void operator()() const + void operator()() const CDS_NOEXCEPT { - cds_std::this_thread::sleep_for( duration_type( m_nTimeout )); + std::this_thread::sleep_for( duration_type( m_nTimeout )); } template - bool operator()( Predicate pr ) const + bool operator()( Predicate pr ) const CDS_NOEXCEPT { for ( unsigned int i = 0; i < m_nTimeout; i += 2 ) { if ( pr() ) return true; - cds_std::this_thread::sleep_for( duration_type( 2 )); + std::this_thread::sleep_for( duration_type( 2 )); } return false; } - void reset() const + void reset() const CDS_NOEXCEPT {} //@endcond }; @@ -400,13 +399,13 @@ namespace cds { The declaration cds::backoff::delay_of< 5 > bkoff is equal for cds::backoff::delay<> bkoff(5). */ - template + template class delay_of: public delay { //@cond typedef delay base_class; public: - delay_of() + delay_of() CDS_NOEXCEPT : base_class( Timeout ) {} //@endcond