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 : #include "callback_thread_manager.h"
12 : #include "log.h"
13 :
14 : namespace hccl {
15 :
16 3 : bool ThreadStreamManager::StreamHasBeenReged(void *stream)
17 : {
18 3 : return streamTidMap_.find(stream) != streamTidMap_.end();
19 : }
20 :
21 1 : HcclResult ThreadStreamManager::RegTidAndStream(u64 tid, rtStream_t stream)
22 : {
23 1 : CHK_PTR_NULL(stream);
24 :
25 1 : std::unique_lock<std::mutex> lock(mapMutex_);
26 1 : streamTidMap_[stream] = tid;
27 :
28 1 : return HCCL_SUCCESS;
29 1 : }
30 :
31 2 : HcclResult ThreadStreamManager::GetStreamByTid(u64 tid, rtStream_t &stream)
32 : {
33 2 : std::unique_lock<std::mutex> lock(mapMutex_);
34 2 : std::map<rtStream_t, u64>::iterator it;
35 2 : for (it = streamTidMap_.begin(); it != streamTidMap_.end(); it++) {
36 1 : if (it->second == tid) {
37 1 : stream = it->first;
38 1 : return HCCL_SUCCESS;
39 : }
40 : }
41 1 : return HCCL_E_NOT_FOUND;
42 2 : }
43 :
44 1 : void ThreadStreamManager::ReleaseTidAndStream(rtStream_t stream)
45 : {
46 1 : std::unique_lock<std::mutex> lock(mapMutex_);
47 1 : if (StreamHasBeenReged(stream)) {
48 1 : streamTidMap_.erase(stream);
49 : }
50 1 : }
51 :
52 : }
|