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-08-17 02:09:53 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         361 : Token::Token(TokenPool *pool) :
       5         361 :     pool_(pool){
       6         361 : }
       7             : 
       8         361 : Token::~Token() {
       9         361 :     if (pool_)
      10         361 :         pool_->FreeToken();
      11         361 : }
      12             : 
      13          28 : TokenPool::TokenPool(const std::string &name, Proto *proto,
      14          28 :                              int count) :
      15          56 :     name_(name), max_tokens_(count), min_tokens_(count),
      16          28 :     low_water_mark_((count * 10)/100), failures_(0), restarts_(0),
      17          28 :     proto_(proto) {
      18          28 :     token_count_ = count;
      19          28 : }
      20             : 
      21          28 : TokenPool::~TokenPool() {
      22          28 : }
      23             : 
      24         361 : void TokenPool::FreeToken() {
      25         361 :     int val = token_count_.fetch_add(1);
      26         361 :     assert(val <= max_tokens_);
      27         361 :     if (val == low_water_mark_) {
      28           0 :         proto_->TokenAvailable(this);
      29             :     }
      30         361 : }
      31             : 
      32        1700 : bool TokenPool::TokenCheck() const {
      33        1700 :     if (token_count_ > 0) {
      34        1700 :         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         361 : TokenPtr FlowTokenPool::GetToken(FlowEntry *entry) {
      49         361 :     int val = token_count_.fetch_sub(1);
      50         361 :     if (val < min_tokens_)
      51          29 :         min_tokens_ = val;
      52         361 :     return TokenPtr(new FlowToken(this, entry));
      53             : }

Generated by: LCOV version 1.14