LCOV - code coverage report
Current view: top level - vnsw/agent/pkt - flow_token.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 29 37 78.4 %
Date: 2026-06-08 02:02:55 Functions: 7 10 70.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "flow_token.h"
       2             : #include "flow_proto.h"
       3             : 
       4         144 : Token::Token(TokenPool *pool) :
       5         144 :     pool_(pool){
       6         144 : }
       7             : 
       8         144 : Token::~Token() {
       9         144 :     if (pool_)
      10         144 :         pool_->FreeToken();
      11         144 : }
      12             : 
      13           7 : TokenPool::TokenPool(const std::string &name, Proto *proto,
      14           7 :                              int count) :
      15          14 :     name_(name), max_tokens_(count), min_tokens_(count),
      16           7 :     low_water_mark_((count * 10)/100), failures_(0), restarts_(0),
      17           7 :     proto_(proto) {
      18           7 :     token_count_ = count;
      19           7 : }
      20             : 
      21           7 : TokenPool::~TokenPool() {
      22           7 : }
      23             : 
      24         144 : void TokenPool::FreeToken() {
      25         144 :     int val = token_count_.fetch_add(1);
      26         144 :     assert(val <= max_tokens_);
      27         144 :     if (val == low_water_mark_) {
      28           0 :         proto_->TokenAvailable(this);
      29             :     }
      30         144 : }
      31             : 
      32         348 : bool TokenPool::TokenCheck() const {
      33         348 :     if (token_count_ > 0) {
      34         348 :         return true;
      35             :     }
      36             : 
      37           0 :     failures_++;
      38           0 :     return false;
      39             : }
      40             : 
      41           0 : TokenPtr TokenPool::GetToken() {
      42           0 :     int val = token_count_.fetch_sub(1);
      43           0 :     if (val < min_tokens_)
      44           0 :         min_tokens_ = val;
      45           0 :     return TokenPtr(new Token(this));
      46             : }
      47             : 
      48         144 : TokenPtr FlowTokenPool::GetToken(FlowEntry *entry) {
      49         144 :     int val = token_count_.fetch_sub(1);
      50         144 :     if (val < min_tokens_)
      51           8 :         min_tokens_ = val;
      52         144 :     return TokenPtr(new FlowToken(this, entry));
      53             : }

Generated by: LCOV version 1.14