forked from Abc-Arbitrage/Disruptor-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSleepingWaitStrategy.h
More file actions
42 lines (31 loc) · 1.2 KB
/
SleepingWaitStrategy.h
File metadata and controls
42 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include <cstdint>
#include "Disruptor/IWaitStrategy.h"
namespace Disruptor
{
/**
* Sleeping strategy that initially spins, then uses a std::this_thread::yield(), and eventually sleep. This strategy is a good compromise between performance and CPU resource.
* Latency spikes can occur after quiet periods.
*/
class SleepingWaitStrategy : public IWaitStrategy
{
public:
explicit SleepingWaitStrategy(std::int32_t retries = m_defaultRetries);
/**
* \see IWaitStrategy::waitFor()
*/
std::int64_t waitFor(std::int64_t sequence,
Sequence& cursor,
ISequence& dependentSequence,
ISequenceBarrier& barrier) override;
/**
* \see IWaitStrategy::signalAllWhenBlocking()
*/
void signalAllWhenBlocking() override;
void writeDescriptionTo(std::ostream& stream) const override;
private:
static std::int32_t applyWaitMethod(ISequenceBarrier& barrier, std::int32_t counter);
static const std::int32_t m_defaultRetries = 200;
std::int32_t m_retries = 0;
};
} // namespace Disruptor