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

            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 SHARED_JETTY_MGR_H
      12              : #define SHARED_JETTY_MGR_H
      13              : 
      14              : #include <cstdint>
      15              : #include <memory>
      16              : #include <mutex>
      17              : #include <unordered_set>
      18              : #include <unordered_map>
      19              : #include "hccl/hccl_types.h"
      20              : #include "hcomm_res_defs.h"
      21              : #include "hcomm_channel.h"
      22              : 
      23              : namespace hcomm {
      24              : 
      25              : /**
      26              :  * @note 职责:管理共享 Jetty 的 channel 注册记录,用于 endpoint 销毁前校验。
      27              :  *       当 IS_SHARED_QUEUE=true 时,HcommChannelCreateWithConfig 通过本管理器注册 Channel,
      28              :  *       HcommChannelDestroy 通过本管理器注销 Channel,
      29              :  *       HcommEndpointDestroy 通过本管理器校验所有共享 Jetty 的 Channel 是否已销毁。
      30              :  *       底层 jetty 句柄的缓存与引用计数由 Endpoint::sharedJettyCtx_ 管理(见 endpoint.h),
      31              :  *       本管理器仅维护 channelHandle 集合用于销毁校验,不持有 jetty 句柄。
      32              :  */
      33              : class SharedJettyMgr {
      34              : public:
      35              :     struct SharedJettyContext {
      36              :         uint32_t channelCount{0};
      37              :         std::unordered_set<ChannelHandle> channelHandles;
      38              :     };
      39              : 
      40              :     static SharedJettyMgr& GetInstance();
      41              : 
      42              :     /**
      43              :      * @brief 注册 Channel 到共享 Jetty 上下文
      44              :      * @param[in] endpointHandle Endpoint 句柄
      45              :      * @param[in] channels 要注册的 Channel 句柄数组
      46              :      * @param[in] channelNum Channel 数量
      47              :      * @return HcclResult 执行结果
      48              :      */
      49              :     HcclResult RegisterChannels(EndpointHandle endpointHandle, const ChannelHandle* channels, uint32_t channelNum);
      50              : 
      51              :     /**
      52              :      * @brief 注销 Channel
      53              :      * @param[in] channels 要注销的 Channel 句柄数组
      54              :      * @param[in] channelNum Channel 数量
      55              :      * @return HcclResult 执行结果
      56              :      */
      57              :     HcclResult UnregisterChannels(const ChannelHandle* channels, uint32_t channelNum);
      58              : 
      59              :     /**
      60              :      * @brief 校验 Endpoint 是否可以销毁(所有共享 Jetty 的 Channel 已销毁)
      61              :      * @param[in] endpointHandle Endpoint 句柄
      62              :      * @return HcclResult HCCL_SUCCESS 表示可以销毁,HCCL_E_UNAVAIL 表示仍有 Channel 未销毁
      63              :      */
      64              :     HcclResult CheckEndpointDestroy(EndpointHandle endpointHandle);
      65              : 
      66              :     /**
      67              :      * @brief 判断 Endpoint 是否已存在共享 Jetty 上下文
      68              :      */
      69              :     bool HasContext(EndpointHandle endpointHandle);
      70              : 
      71              : private:
      72            4 :     SharedJettyMgr() = default;
      73            4 :     ~SharedJettyMgr() = default;
      74              :     SharedJettyMgr(const SharedJettyMgr&) = delete;
      75              :     SharedJettyMgr& operator=(const SharedJettyMgr&) = delete;
      76              : 
      77              :     std::mutex mtx_;
      78              :     std::unordered_map<EndpointHandle, SharedJettyContext> contexts_;
      79              : };
      80              : 
      81              : } // namespace hcomm
      82              : 
      83              : #endif // SHARED_JETTY_MGR_H
        

Generated by: LCOV version 2.0-1