cds  2.3.2
cds::backoff::delay< Traits > Class Template Reference

Delay back-off strategy. More...

#include <cds/algo/backoff_strategy.h>

Public Types

typedef Traits traits
 Traits.
 
typedef Traits::duration_type duration_type
 Duration type (default std::chrono::milliseconds)
 

Public Member Functions

 delay () noexcept
 Default ctor takes the timeout from traits::timeout.
 
constexpr delay (unsigned int nTimeout) noexcept
 Initializes timeout from nTimeout.
 

Detailed Description

template<typename Traits = delay_const_traits>
class cds::backoff::delay< Traits >

Delay back-off strategy.

Template arguments:

  • Duration - duration type, default is std::chrono::milliseconds
  • Traits - a class that defines default timeout.

Choosing the best value for th timeout is platform and application specific task. The default values for timeout is provided by Traits class that should timeout data member. There are two predefined Traits implementation:

  • delay_const_traits - defines timeout as a constant (enum). To change timeout you should recompile your application.
  • delay_runtime_traits - specifies timeout as static data member that can be changed at runtime to tune the back-off strategy.

You may use Traits template parameter to separate back-off implementations. For example, you may define two delay back-offs for 5 and 10 ms timeout:

#include <cds/algo/backoff_strategy.h>
namespace bkoff = cds::backoff;
// 5ms delay
struct ms5
{
typedef std::chrono::milliseconds duration_type;
enum: unsigned { timeout = 5 };
};
// 10ms delay, runtime support
struct ms10
{
typedef std::chrono::milliseconds duration_type;
static unsigned timeout;
};
unsigned ms10::timeout = 10;
// define your back-off specialization
typedef bkoff::delay<std::chrono::milliseconds, ms5> delay5;
typedef bkoff::delay<std::chrono::milliseconds, ms10> delay10;

The documentation for this class was generated from the following file:

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:15 by Doxygen 1.8.13