LCOV - code coverage report
Current view: top level - legacy/ascend950/common - referenced.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 5 5
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #ifndef HCCL_REFERENCED_H
      12              : #define HCCL_REFERENCED_H
      13              : 
      14              : namespace Hccl {
      15              : 
      16              : class Referenced {
      17              : public:
      18              :     // 初始化这个类,引用计数设为1,并且将p指向传入的地址
      19           13 :     Referenced() : refCount(0) {}
      20              : 
      21              :     // 引用计数加1
      22           19 :     int Ref() { return ++refCount; }
      23              : 
      24              :     // 引用计数减1
      25            5 :     int Unref() { return --refCount; }
      26              : 
      27              :     // 返回引用计数
      28           26 :     int Count() const { return refCount; }
      29              : 
      30              :     int Clear()
      31              :     {
      32              :         refCount = 0;
      33              :         return refCount;
      34              :     }
      35              :     bool IsZero() const { return refCount == 0; }
      36           40 :     ~Referenced() {}
      37              : 
      38              : private:
      39              :     int refCount; // 引用计数,表示有多少个变量引用这块内存
      40              : };
      41              : 
      42              : } // namespace Hccl
      43              : 
      44              : #endif // HCCL_REFERENCED_H
        

Generated by: LCOV version 2.0-1