MADARA  3.1.8
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"
6 
7 inline time_t
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_
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.