LCOV - code coverage report
Current view: top level - vnsw/agent/resource_manager - resource_table.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 34 57 59.6 %
Date: 2026-08-03 02:19:58 Functions: 10 19 52.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include <boost/uuid/uuid_io.hpp>
       6             : #include <cmn/agent_cmn.h>
       7             : #include <cmn/agent.h>
       8             : #include <resource_manager/resource_manager.h>
       9             : #include <resource_manager/resource_table.h>
      10             : #include <resource_manager/index_resource.h>
      11             : 
      12         124 : ResourceKey::ResourceKey(ResourceManager *rm, Resource::Type type) :
      13         124 :     rm_(rm), dirty_(false),
      14         124 :     resource_table_(static_cast<ResourceTable *>(rm->resource_table(type))) {
      15         124 : }
      16             : 
      17         124 : ResourceKey::~ResourceKey() {
      18         124 : }
      19             : 
      20           0 : bool ResourceKey::operator<(const ResourceKey &rhs) const {
      21           0 :     return IsLess(rhs);
      22             : }
      23             : 
      24           0 : ResourceBackupEndKey::ResourceBackupEndKey(ResourceManager *rm) :
      25           0 :     ResourceKey(rm, Resource::INVALID) {
      26           0 : }
      27             : 
      28           0 : ResourceBackupEndKey::~ResourceBackupEndKey() {
      29           0 : }
      30             : 
      31         124 : ResourceData::ResourceData(ResourceManager *rm) :
      32         124 :     rm_(rm) {
      33         124 : }
      34             : 
      35         124 : ResourceData::~ResourceData() {
      36         124 : }
      37             : 
      38             : 
      39          18 : ResourceTable::ResourceTable(ResourceManager *rm) : rm_(rm) {
      40          18 : }
      41             : 
      42          18 : ResourceTable::~ResourceTable() {
      43          18 :     assert(key_data_map_.size() == 0);
      44          18 : }
      45             : 
      46         124 : void ResourceTable::InsertKey(KeyPtr key, DataPtr data) {
      47         124 :     key_data_map_.insert(std::pair<KeyPtr, DataPtr>(key, data));
      48         124 : }
      49             : 
      50         124 : void ResourceTable::DeleteKey(KeyPtr key) {
      51         124 :     key_data_map_.erase(key);
      52         124 : }
      53             : 
      54         124 : ResourceTable::DataPtr ResourceTable::FindKeyPtr(KeyPtr key) {
      55         124 :     KeyDataMapIter it = key_data_map_.find(key);
      56         124 :     if (it == key_data_map_.end()) {
      57           0 :         return DataPtr();
      58             :     }
      59         124 :     return (*it).second;
      60             : }
      61             : 
      62           0 : ResourceData* ResourceTable::FindKey(KeyPtr key) {
      63           0 :     return (FindKeyPtr(key).get());
      64             : }
      65             : 
      66             : // Walk all the etries remove keys are not usable.
      67           0 : void ResourceTable::FlushStale() {
      68           0 :     for (KeyDataMapIter it = key_data_map_.begin();
      69           0 :         it != key_data_map_.end();) {
      70           0 :         KeyPtr key = it->first;
      71           0 :         if (key->dirty()) {
      72           0 :             it++;
      73           0 :             rm_->Release(key);
      74             :         } else {
      75           0 :             it++;
      76             :         }
      77           0 :     }
      78           0 : }
      79             : 
      80             : // Allocate the resource and mark the key usable
      81         124 : ResourceTable::DataPtr ResourceTable::Allocate(KeyPtr key) {
      82         124 :     KeyDataMapIter it = key_data_map_.find(key);
      83         124 :     ResourceManager::DataPtr data = DataPtr();
      84         124 :     if (it == key_data_map_.end()) {
      85         124 :         data = AllocateData(key);
      86         124 :         InsertKey(key, data);
      87         124 :         key->reset_dirty();
      88             :     } else {
      89           0 :         data = (*it).second;
      90           0 :         (*it).first->reset_dirty();
      91             :     }
      92         248 :     return data;
      93           0 : }

Generated by: LCOV version 1.14