MADARA  3.4.1
BandwidthMonitor.inl
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 #ifndef _BANDWIDTH_MONITOR_INL_
3 #define _BANDWIDTH_MONITOR_INL_
4 
5 #include "BandwidthMonitor.h"
7 
9 {
10  MADARA_GUARD_TYPE guard(mutex_);
11 
12  time_t cur_time = time(NULL);
13  time_t earliest_time = cur_time - window_;
14 
15  BandwidthMessages::iterator begin = messages_.begin();
16  BandwidthMessages::iterator end = begin;
17 
18  for (end = begin; end != messages_.end(); ++end)
19  {
24  if (end->first < earliest_time)
25  {
26  utilization_ -= end->second;
27  }
28  else
29  break;
30  }
31 
32  if (end != begin)
33  messages_.erase(begin, end);
34 
35  return cur_time;
36 }
37 
38 #endif // _BANDWIDTH_MONITOR_INL_
time_t window_
Time window for useful messages to bandwidth calculations.
MADARA_LOCK_TYPE mutex_
Mutex for supporting multithreaded monitor calls.
time_t update_utilization(void)
Updates utilization for most public functions.
BandwidthMessages messages_
Map of timestamps to messages.