Github   Telegram
Loading...
Searching...
No Matches
cpu_relax.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <chrono>
7#include <cstddef>
8
10
11USERVER_NAMESPACE_BEGIN
12
13namespace utils {
14
17 public:
18 explicit ScopeTimePause(tracing::ScopeTime* scope);
19
21 void Pause();
22
24 void Unpause();
25
26 private:
27 tracing::ScopeTime* scope_;
28 std::string scope_name_;
29};
30
33class CpuRelax {
34 public:
38 explicit CpuRelax(std::size_t every, tracing::ScopeTime* scope);
39
40 CpuRelax(const CpuRelax&) = delete;
41 CpuRelax(CpuRelax&&) = delete;
42
44 void Relax();
45
46 private:
47 ScopeTimePause pause_;
48 const std::size_t every_iterations_;
49 std::size_t iterations_{0};
50};
51
55 public:
59 explicit StreamingCpuRelax(std::uint64_t check_time_after_bytes,
60 tracing::ScopeTime* scope);
61
64 void Relax(std::uint64_t bytes_processed);
65
68 std::uint64_t GetBytesProcessed() const;
69
70 private:
71 ScopeTimePause pause_;
72 std::uint64_t check_time_after_bytes_;
73 std::uint64_t total_bytes_{0};
74 std::uint64_t bytes_since_last_time_check_{0};
75 std::chrono::steady_clock::time_point last_yield_time_;
76};
77
78} // namespace utils
79
80USERVER_NAMESPACE_END