Fix threading issue in mt_tests

Resolves: NEO-5165

Change-Id: I1258cff22541c395c74c999fc7dd45be5e430dd1
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2020-11-02 13:22:26 +01:00
committed by sys_ocldev
parent 80076a808c
commit e34c44b425
2 changed files with 11 additions and 2 deletions

View File

@ -49,20 +49,23 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro
GraphicsAllocation *createdAllocations[maxThreads];
std::thread threads[maxThreads];
std::atomic<size_t> index(0);
std::atomic<size_t> allocateCount(0);
auto createFunction = [&]() {
size_t indexFree = index++;
AllocationProperties properties(0, false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER, false, {});
createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false);
EXPECT_NE(nullptr, createdAllocations[indexFree]);
EXPECT_GE(1u, memoryManager->peekSharedBosSize());
allocateCount++;
};
for (size_t i = 0; i < maxThreads; i++) {
threads[i] = std::thread(createFunction);
}
while (index < maxThreads) {
EXPECT_GE(1u, memoryManager->sharingBufferObjects.size());
while (allocateCount < maxThreads) {
EXPECT_GE(1u, memoryManager->peekSharedBosSize());
}
for (size_t i = 0; i < maxThreads; i++) {