-
Notifications
You must be signed in to change notification settings - Fork 145
/
PipeThrottler.h
43 lines (34 loc) · 932 Bytes
/
PipeThrottler.h
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
43
#pragma once
#include "Interface/PipeThrottler.h"
#include <memory>
class IMutex;
class PipeThrottler : public IPipeThrottler
{
public:
PipeThrottler(size_t bps, bool percent_max, IPipeThrottlerUpdater* updater);
PipeThrottler();
~PipeThrottler(void);
virtual bool addBytes(size_t new_bytes, bool wait);
virtual void changeThrottleLimit(size_t bps, bool p_percent_max);
virtual void changeThrottleUpdater(IPipeThrottlerUpdater* new_updater);
private:
enum ThrottleState
{
ThrottleState_Probe,
ThrottleState_Throttle
};
size_t throttle_bps;
bool percent_max;
int64 update_time_interval;
size_t curr_bytes;
int64 lastresettime;
int64 lastupdatetime;
std::unique_ptr<IPipeThrottlerUpdater> updater;
ThrottleState throttle_state;
int64 lastprobetime;
float probe_bps;
size_t throttle_percent;
float last_probe_result;
size_t probe_interval;
IMutex *mutex;
};