mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 07:14:10 +08:00
fix: add missing lock in MapOperationsStorage::getInfoForHostPtr
https://github.com/intel/compute-runtime/issues/640 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
21e8595fef
commit
04afb63717
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018-2022 Intel Corporation
|
* Copyright (C) 2018-2023 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
@@ -105,6 +105,7 @@ MapOperationsHandler *NEO::MapOperationsStorage::getHandlerIfExists(cl_mem memOb
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool NEO::MapOperationsStorage::getInfoForHostPtr(const void *ptr, size_t size, MapInfo &outInfo) {
|
bool NEO::MapOperationsStorage::getInfoForHostPtr(const void *ptr, size_t size, MapInfo &outInfo) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
for (auto &entry : handlers) {
|
for (auto &entry : handlers) {
|
||||||
if (entry.second.findInfoForHostPtr(ptr, size, outInfo)) {
|
if (entry.second.findInfoForHostPtr(ptr, size, outInfo)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018-2022 Intel Corporation
|
* Copyright (C) 2018-2023 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
@@ -20,6 +20,10 @@ struct MockMapOperationsHandler : public MapOperationsHandler {
|
|||||||
using MapOperationsHandler::mappedPointers;
|
using MapOperationsHandler::mappedPointers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MockMapOperationsStorage : public MapOperationsStorage {
|
||||||
|
using MapOperationsStorage::handlers;
|
||||||
|
};
|
||||||
|
|
||||||
struct MapOperationsHandlerMtTests : public ::testing::Test {
|
struct MapOperationsHandlerMtTests : public ::testing::Test {
|
||||||
MockMapOperationsHandler mockHandler;
|
MockMapOperationsHandler mockHandler;
|
||||||
MockGraphicsAllocation mockAllocation;
|
MockGraphicsAllocation mockAllocation;
|
||||||
@@ -79,4 +83,50 @@ TEST_F(MapOperationsHandlerMtTests, giveMapOperationsHandlerWhenAddingFindingAnd
|
|||||||
t3.join();
|
t3.join();
|
||||||
t4.join();
|
t4.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(MapOperationsHandlerMtTests, giveMapOperationsStorageWhenAddingIteratingAndRemovingThenExecuteSafely) {
|
||||||
|
std::atomic<bool> removed = false;
|
||||||
|
std::atomic<bool> t1Started = false;
|
||||||
|
std::atomic<bool> t2Started = false;
|
||||||
|
std::atomic<bool> t3Started = false;
|
||||||
|
|
||||||
|
MockMapOperationsStorage mockStorage{};
|
||||||
|
auto find = [&](std::atomic<bool> *threadStarted) {
|
||||||
|
while (!removed.load()) {
|
||||||
|
for (auto &ptr : mappedPtrs) {
|
||||||
|
MapInfo out;
|
||||||
|
mockStorage.getInfoForHostPtr(ptr, 1, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
threadStarted->store(true);
|
||||||
|
std::this_thread::yield();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
auto remove = [&]() {
|
||||||
|
while (!t1Started.load() || !t2Started.load() || !t3Started.load()) {
|
||||||
|
std::this_thread::yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr auto numHandlers = 100u;
|
||||||
|
for (size_t i = 0; i < numHandlers; i++) {
|
||||||
|
|
||||||
|
mockStorage.getHandler(reinterpret_cast<cl_mem>(i));
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < numHandlers; i++) {
|
||||||
|
mockStorage.removeHandler(reinterpret_cast<cl_mem>(i));
|
||||||
|
}
|
||||||
|
removed.store(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::thread t1(find, &t1Started);
|
||||||
|
std::thread t2(find, &t2Started);
|
||||||
|
std::thread t3(find, &t3Started);
|
||||||
|
std::thread t4(remove);
|
||||||
|
|
||||||
|
t1.join();
|
||||||
|
t2.join();
|
||||||
|
t3.join();
|
||||||
|
t4.join();
|
||||||
|
}
|
||||||
} // namespace NEO
|
} // namespace NEO
|
||||||
|
|||||||
Reference in New Issue
Block a user