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 HCOMM_CCU_INSTANCE_MGR_H
12 : #define HCOMM_CCU_INSTANCE_MGR_H
13 :
14 : #include <mutex>
15 : #include <shared_mutex>
16 : #include <unordered_map>
17 :
18 : #include "ccu_types.h"
19 : #include "ccu_instance.h"
20 :
21 : namespace hcomm {
22 :
23 : class CcuInstanceMgr {
24 : public:
25 : static CcuInstanceMgr &GetInstance(const int32_t deviceLogicId);
26 :
27 : CcuResult Init();
28 : CcuResult Deinit();
29 :
30 : CcuResult Create(CcuInstanceType insType, CcuInsHandle &insHandle);
31 : CcuInstance *Get(CcuInsHandle insHandle) const;
32 : CcuResult Destroy(CcuInsHandle insHandle);
33 :
34 : private:
35 132 : explicit CcuInstanceMgr() = default;
36 : ~CcuInstanceMgr();
37 :
38 : CcuInstanceMgr(const CcuInstanceMgr &that) = delete;
39 : CcuInstanceMgr &operator=(const CcuInstanceMgr &that) = delete;
40 :
41 : private:
42 : bool initializedFlag_{false};
43 : int32_t devLogicId_{-1};
44 : CcuInsHandle instanceId_{0};
45 : mutable std::shared_timed_mutex insMapMutex_;
46 : std::unordered_map<CcuInsHandle, std::unique_ptr<CcuInstance>> insMap_{};
47 : };
48 : }; // namespace hcomm
49 :
50 : #endif // HCOMM_CCU_INSTANCE_MGR_H
|