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 EXCEPTION_CALLBACK_MGR_H
12 : #define EXCEPTION_CALLBACK_MGR_H
13 :
14 : #include <vector>
15 : #include <mutex>
16 : #include <shared_mutex>
17 : #include <cstdint>
18 : #include "hccl_types.h"
19 : #include "hcomm/hcomm_exception.h"
20 :
21 : namespace hcomm {
22 :
23 : class ExceptionCallbackMgr {
24 : public:
25 : static ExceptionCallbackMgr& GetInstance();
26 :
27 : HcclResult Register(HcommExceptionCallback cb, void* userData);
28 : HcclResult Unregister(HcommExceptionCallback cb);
29 : void NotifyAll(const HcommExceptionInfo& exceptionInfo);
30 : bool IsEmpty();
31 :
32 : private:
33 1 : ExceptionCallbackMgr() = default;
34 1 : ~ExceptionCallbackMgr() = default;
35 : ExceptionCallbackMgr(const ExceptionCallbackMgr&) = delete;
36 : ExceptionCallbackMgr& operator=(const ExceptionCallbackMgr&) = delete;
37 :
38 : struct CallbackEntry {
39 : HcommExceptionCallback cb{nullptr};
40 : void* userData{nullptr};
41 : };
42 :
43 : std::shared_mutex mutex_;
44 : std::vector<CallbackEntry> callbacks_;
45 : };
46 :
47 : } // namespace hcomm
48 :
49 : #endif
|