6 namespace honey {
namespace lockfree
20 Backoff(
bool spin =
true, Nanosec timeMin = 100_ns, Nanosec timeMax = 100_us,
int tickThresh = 5) :
24 _tickThresh(tickThresh)
28 void inc(
int ticks = 1)
31 for (l.tick += ticks; l.tick >= _tickThresh; l.tick -= _tickThresh)
34 if (l.spin) { l.spin =
false;
continue; }
36 l.time = l.time*2 + 1_ns;
37 if (l.time > _timeMax) l.time = _timeMax;
42 void dec(
int ticks = 1)
45 for (l.tick -= ticks; l.tick <= -_tickThresh; l.tick += _tickThresh)
48 if (l.time == _timeMin) { l.spin = _spin;
continue; }
51 if (l.time < _timeMin) l.time = _timeMin;
59 void reset() { Local& l = _l; l.spin = _spin; l.time = _timeMin; l.tick = 0; }
void inc(int ticks=1)
Increase tick count by ticks. Increases the amount of time that backoff will wait.
Definition: Backoff.h:28
void spin(int count)
Suspend this thread momentarily without giving up its time slice. The thread will pause count times...
Definition: Thread.h:60
void pause()
Perform a no-op without giving up this thread's time slice. This no-op momentarily frees resources fo...
Definition: Thread.h:54
void sleep(MonoClock::Duration time)
Suspend this thread for an amount of time.
Definition: Thread.cpp:35
Exponential backoff algorithm. Backoff spins for first X ticks, then sleeps with a time that doubles ...
Definition: Backoff.h:10
Backoff(bool spin=true, Nanosec timeMin=100_ns, Nanosec timeMax=100_us, int tickThresh=5)
Definition: Backoff.h:20
void wait()
Perform backoff, suspend thread.
Definition: Backoff.h:56
void reset()
Reset backoff to initial state.
Definition: Backoff.h:59
Global Honeycomb namespace.
void dec(int ticks=1)
Decrease tick count by ticks. Decreases the amount of time that backoff will wait.
Definition: Backoff.h:42