From a5025edc2081f08faec8a5f417f43ea9187e03ce Mon Sep 17 00:00:00 2001 From: Jakub Nowacki Date: Mon, 15 Sep 2025 15:35:18 +0000 Subject: [PATCH] fix: make initializeEngine() thread-safe Related-To: NEO-15630 Signed-off-by: Jakub Nowacki --- .../aub_command_stream_receiver_hw_base.inl | 17 +++++++++-------- .../tbx_command_stream_receiver_hw.inl | 14 +++++++------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/shared/source/command_stream/aub_command_stream_receiver_hw_base.inl b/shared/source/command_stream/aub_command_stream_receiver_hw_base.inl index 96f3837043..372a7c4f77 100644 --- a/shared/source/command_stream/aub_command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/aub_command_stream_receiver_hw_base.inl @@ -152,11 +152,14 @@ const std::string AUBCommandStreamReceiverHw::getFileName() { template void AUBCommandStreamReceiverHw::initializeEngine() { - auto streamLocked = lockStream(); - isEngineInitialized = true; - - if (hardwareContextController) { - hardwareContextController->initialize(); + if (!isEngineInitialized) { + auto streamLocked = lockStream(); + if (!isEngineInitialized) { + isEngineInitialized = true; + if (hardwareContextController) { + hardwareContextController->initialize(); + } + } } } @@ -315,9 +318,7 @@ bool AUBCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxA return false; } - if (!isEngineInitialized) { - initializeEngine(); - } + initializeEngine(); bool ownsLock = !gfxAllocation.isLocked(); uint64_t gpuAddress; diff --git a/shared/source/command_stream/tbx_command_stream_receiver_hw.inl b/shared/source/command_stream/tbx_command_stream_receiver_hw.inl index 8b77737138..6c895f261f 100644 --- a/shared/source/command_stream/tbx_command_stream_receiver_hw.inl +++ b/shared/source/command_stream/tbx_command_stream_receiver_hw.inl @@ -129,11 +129,13 @@ void TbxCommandStreamReceiverHw::protectCPUMemoryFromWritesIfTbxFault template void TbxCommandStreamReceiverHw::initializeEngine() { - isEngineInitialized = true; + if (!isEngineInitialized) { + isEngineInitialized = true; - if (hardwareContextController) { - hardwareContextController->initialize(); - return; + if (hardwareContextController) { + hardwareContextController->initialize(); + return; + } } DEBUG_BREAK_IF(this->aubManager); } @@ -270,9 +272,7 @@ bool TbxCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxA this->protectCPUMemoryFromWritesIfTbxFaultable(&gfxAllocation, cpuAddress, size); - if (!isEngineInitialized) { - initializeEngine(); - } + initializeEngine(); if (aubManager) { this->writeMemoryWithAubManager(gfxAllocation, isChunkCopy, gpuVaChunkOffset, chunkSize);