Skip to content

Commit 967bb12

Browse files
committed
Don't use shared_ptr
1 parent 9cfcb74 commit 967bb12

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

unified-runtime/source/loader/layers/sanitizer/tsan/tsan_interceptor.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ ur_result_t DeviceInfo::allocShadowMemory() {
6969
return UR_RESULT_SUCCESS;
7070
}
7171

72-
void ContextInfo::insertAllocInfo(ur_device_handle_t Device,
73-
std::shared_ptr<TsanAllocInfo> &AI) {
72+
void ContextInfo::insertAllocInfo(ur_device_handle_t Device, TsanAllocInfo AI) {
7473
if (Device) {
7574
std::scoped_lock<ur_shared_mutex> Guard(AllocInfosMapMutex);
76-
AllocInfosMap[Device].emplace_back(AI);
75+
AllocInfosMap[Device].emplace_back(std::move(AI));
7776
} else {
7877
for (auto Device : DeviceList) {
7978
std::scoped_lock<ur_shared_mutex> Guard(AllocInfosMapMutex);
80-
AllocInfosMap[Device].emplace_back(AI);
79+
AllocInfosMap[Device].emplace_back(std::move(AI));
8180
}
8281
}
8382
}
@@ -103,11 +102,9 @@ ur_result_t TsanInterceptor::allocateMemory(ur_context_handle_t Context,
103102
Context, Device, Properties, Pool, Size, &Allocated));
104103
}
105104

106-
auto AI = std::make_shared<TsanAllocInfo>(
107-
TsanAllocInfo{reinterpret_cast<uptr>(Allocated), Size});
108-
105+
auto AI = TsanAllocInfo{reinterpret_cast<uptr>(Allocated), Size};
109106
// For updating shadow memory
110-
CI->insertAllocInfo(Device, AI);
107+
CI->insertAllocInfo(Device, std::move(AI));
111108

112109
*ResultPtr = Allocated;
113110
return UR_RESULT_SUCCESS;
@@ -153,10 +150,8 @@ ur_result_t TsanInterceptor::registerDeviceGlobals(ur_program_handle_t Program)
153150

154151
for (size_t i = 0; i < NumOfDeviceGlobal; i++) {
155152
const auto &GVInfo = GVInfos[i];
156-
auto AI = std::make_shared<TsanAllocInfo>(
157-
TsanAllocInfo{GVInfo.Addr, GVInfo.Size});
158-
159-
ContextInfo->insertAllocInfo(Device, AI);
153+
auto AI = TsanAllocInfo{GVInfo.Addr, GVInfo.Size};
154+
ContextInfo->insertAllocInfo(Device, std::move(AI));
160155
}
161156
}
162157

@@ -275,9 +270,10 @@ TsanInterceptor::updateShadowMemory(std::shared_ptr<ContextInfo> &CI,
275270
ur_queue_handle_t Queue) {
276271
std::scoped_lock<ur_shared_mutex> Guard(CI->AllocInfosMapMutex);
277272
for (auto &AllocInfo : CI->AllocInfosMap[DI->Handle]) {
278-
UR_CALL(DI->Shadow->CleanShadow(Queue, AllocInfo->AllocBegin,
279-
AllocInfo->AllocSize));
273+
UR_CALL(DI->Shadow->CleanShadow(Queue, AllocInfo.AllocBegin,
274+
AllocInfo.AllocSize));
280275
}
276+
CI->AllocInfosMap[DI->Handle].clear();
281277
return UR_RESULT_SUCCESS;
282278
}
283279

unified-runtime/source/loader/layers/sanitizer/tsan/tsan_interceptor.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ struct ContextInfo {
4848
std::vector<ur_device_handle_t> DeviceList;
4949

5050
ur_shared_mutex AllocInfosMapMutex;
51-
std::unordered_map<ur_device_handle_t,
52-
std::vector<std::shared_ptr<TsanAllocInfo>>>
51+
std::unordered_map<ur_device_handle_t, std::vector<TsanAllocInfo>>
5352
AllocInfosMap;
5453

5554
explicit ContextInfo(ur_context_handle_t Context) : Handle(Context) {
@@ -68,8 +67,7 @@ struct ContextInfo {
6867

6968
ContextInfo &operator=(const ContextInfo &) = delete;
7069

71-
void insertAllocInfo(ur_device_handle_t Device,
72-
std::shared_ptr<TsanAllocInfo> &AI);
70+
void insertAllocInfo(ur_device_handle_t Device, TsanAllocInfo AI);
7371
};
7472

7573
struct DeviceGlobalInfo {

0 commit comments

Comments
 (0)