MADARA  3.2.3
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 
8 inline time_t
10 {
11  MADARA_GUARD_TYPE guard (mutex_);
12 
13  time_t cur_time = time (NULL);
14  time_t earliest_time = cur_time - window_;
15 
16  BandwidthMessages::iterator begin = messages_.begin ();
17  BandwidthMessages::iterator end = begin;
18 
19  for (end = begin; end != messages_.end (); ++end)
20  {
25  if (end->first < earliest_time)
26  {
27  utilization_ -= end->second;
28  }
29  else
30  break;
31  }
32 
33  if (end != begin)
34  messages_.erase (begin, end);
35 
36  return cur_time;
37 }
38 
39 #endif // _BANDWIDTH_MONITOR_INL_
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.
time_t window_
Time window for useful messages to bandwidth calculations.