LCOV - code coverage report
Current view: top level - base_comm/resources/endpoint_pairs/channels - acl_device_slab_guard.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.0 % 15 12
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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 CHANNEL_ACL_DEVICE_SLAB_GUARD_H
      12              : #define CHANNEL_ACL_DEVICE_SLAB_GUARD_H
      13              : 
      14              : #include "adapter_rts.h"
      15              : #include "log.h"
      16              : 
      17              : namespace hcomm {
      18              : 
      19              : class AclDeviceSlabGuard {
      20              : public:
      21              :     AclDeviceSlabGuard() = default;
      22           15 :     ~AclDeviceSlabGuard()
      23              :     {
      24           15 :         if (ptr_ != nullptr) {
      25            0 :             HcclResult ret = hrtFree(ptr_);
      26            0 :             if (ret != HCCL_SUCCESS) {
      27            0 :                 HCCL_WARNING("[AclDeviceSlabGuard] hrtFree failed, ptr[%p], size[%zu], ret[%d]", ptr_, size_, ret);
      28              :             }
      29              :         }
      30           15 :     }
      31              : 
      32           13 :     void Reset(void* ptr, size_t size)
      33              :     {
      34           13 :         ptr_ = ptr;
      35           13 :         size_ = size;
      36           13 :     }
      37              : 
      38           13 :     void* Release()
      39              :     {
      40           13 :         void* ptr = ptr_;
      41           13 :         ptr_ = nullptr;
      42           13 :         size_ = 0;
      43           13 :         return ptr;
      44              :     }
      45              : 
      46              : private:
      47              :     void* ptr_{nullptr};
      48              :     size_t size_{0};
      49              : };
      50              : 
      51              : } // namespace hcomm
      52              : 
      53              : #endif // CHANNEL_ACL_DEVICE_SLAB_GUARD_H
        

Generated by: LCOV version 2.0-1