mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +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
|
||||
*
|
||||
@@ -20,6 +20,10 @@ struct MockMapOperationsHandler : public MapOperationsHandler {
|
||||
using MapOperationsHandler::mappedPointers;
|
||||
};
|
||||
|
||||
struct MockMapOperationsStorage : public MapOperationsStorage {
|
||||
using MapOperationsStorage::handlers;
|
||||
};
|
||||
|
||||
struct MapOperationsHandlerMtTests : public ::testing::Test {
|
||||
MockMapOperationsHandler mockHandler;
|
||||
MockGraphicsAllocation mockAllocation;
|
||||
@@ -79,4 +83,50 @@ TEST_F(MapOperationsHandlerMtTests, giveMapOperationsHandlerWhenAddingFindingAnd
|
||||
t3.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
|
||||
|
||||
Reference in New Issue
Block a user