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

Generated by: LCOV version 1.14