LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/base - watermark.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 8 8 100.0 %
Date: 2026-08-03 02:19:58 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
       3             : //
       4             : 
       5             : // watermark.h
       6             : // class to handle multiple level high/low watermarks
       7             : // this is NOT thread-safe, caller needs take mutex.
       8             : //
       9             : #ifndef BASE_WATERMARK_H_
      10             : #define BASE_WATERMARK_H_
      11             : 
      12             : #include <set>
      13             : #include <boost/function.hpp>
      14             : #include <base/util.h>
      15             : 
      16             : // WaterMarkInfo
      17             : typedef boost::function<void (size_t)> WaterMarkCallback;
      18             : 
      19             : struct WaterMarkInfo {
      20      226741 :     WaterMarkInfo(size_t count, WaterMarkCallback cb) :
      21      226741 :         count_(count),
      22      226741 :         cb_(cb) {
      23      226741 :     }
      24             :     friend inline bool operator<(const WaterMarkInfo& lhs,
      25             :         const WaterMarkInfo& rhs);
      26             :     friend inline bool operator==(const WaterMarkInfo& lhs,
      27             :         const WaterMarkInfo& rhs);
      28             :     size_t count_;
      29             :     WaterMarkCallback cb_;
      30             : };
      31             : 
      32      483976 : inline bool operator<(const WaterMarkInfo& lhs, const WaterMarkInfo& rhs) {
      33      483976 :     return lhs.count_ < rhs.count_;
      34             : }
      35             : 
      36           6 : inline bool operator==(const WaterMarkInfo& lhs, const WaterMarkInfo& rhs) {
      37           6 :     return lhs.count_ == rhs.count_;
      38             : }
      39             : 
      40             : typedef std::set<WaterMarkInfo> WaterMarkInfos;
      41             : 
      42             : class WaterMarkTuple {
      43             : public:
      44             :     WaterMarkTuple();
      45             : 
      46             :     void SetHighWaterMark(const WaterMarkInfos &high_water);
      47             :     void SetHighWaterMark(const WaterMarkInfo& hwm_info);
      48             :     void ResetHighWaterMark();
      49             :     WaterMarkInfos GetHighWaterMark() const;
      50             :     void SetLowWaterMark(const WaterMarkInfos &low_water);
      51             :     void SetLowWaterMark(const WaterMarkInfo& lwm_info);
      52             :     void ResetLowWaterMark();
      53             :     WaterMarkInfos GetLowWaterMark() const;
      54             :     void ProcessWaterMarks(size_t in_count, size_t curr_count);
      55             :     bool AreWaterMarksSet() const;
      56             :     void ProcessHighWaterMarks(size_t count);
      57             :     void ProcessLowWaterMarks(size_t count);
      58             : 
      59             : private:
      60             :     WaterMarkInfos high_water_;
      61             :     WaterMarkInfos low_water_;
      62             :     size_t last_count_;
      63             : 
      64             :     DISALLOW_COPY_AND_ASSIGN(WaterMarkTuple);
      65             : };
      66             : 
      67             : #endif /* BASE_WATERMARK_H_ */

Generated by: LCOV version 1.14