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 CALLBACK_THREAD_MANAGER_H
12 : #define CALLBACK_THREAD_MANAGER_H
13 :
14 : #include <map>
15 : #include <mutex>
16 : #include "hccl/base.h"
17 :
18 : namespace hccl {
19 :
20 : class ThreadStreamManager {
21 : public:
22 6 : static ThreadStreamManager& Instance()
23 : {
24 6 : static ThreadStreamManager instance;
25 6 : return instance;
26 : }
27 :
28 : bool StreamHasBeenReged(rtStream_t stream);
29 : HcclResult RegTidAndStream(u64 tid, rtStream_t stream);
30 : HcclResult GetStreamByTid(u64 tid, rtStream_t& stream);
31 : void ReleaseTidAndStream(rtStream_t stream);
32 :
33 : private:
34 1 : ThreadStreamManager() = default;
35 1 : ~ThreadStreamManager() = default;
36 : std::map<rtStream_t, u64> streamTidMap_; // stream被注册的map
37 : std::mutex mapMutex_; // 锁stream被注册的map
38 : };
39 : } // namespace hccl
40 : #endif // CALLBACK_THREAD_MANAGER_H
|