diff --git a/shared/source/command_stream/host_function.cpp b/shared/source/command_stream/host_function.cpp index b94726e6bd..b130657e5b 100644 --- a/shared/source/command_stream/host_function.cpp +++ b/shared/source/command_stream/host_function.cpp @@ -46,21 +46,37 @@ uint64_t HostFunctionStreamer::getHostFunctionId() const { void HostFunctionStreamer::signalHostFunctionCompletion(const HostFunction &hostFunction) { if (hostFunction.isInOrder) { - *hostFunctionIdAddress = HostFunctionStatus::completed; - isBusy.store(false, std::memory_order_release); + setHostFunctionIdAsCompleted(); + endInOrderExecution(); } } void HostFunctionStreamer::prepareForExecution(const HostFunction &hostFunction) { if (hostFunction.isInOrder) { - isBusy.store(true, std::memory_order_release); + startInOrderExecution(); } else { - *hostFunctionIdAddress = HostFunctionStatus::completed; + setHostFunctionIdAsCompleted(); } pendingHostFunctions.fetch_sub(1, std::memory_order_acq_rel); } +void HostFunctionStreamer::setHostFunctionIdAsCompleted() { + *hostFunctionIdAddress = HostFunctionStatus::completed; +} + +void HostFunctionStreamer::endInOrderExecution() { + inOrderExecutionInProgress.store(false, std::memory_order_release); +} + +void HostFunctionStreamer::startInOrderExecution() { + inOrderExecutionInProgress.store(true, std::memory_order_release); +} + +bool HostFunctionStreamer::isInOrderExecutionInProgress() const { + return inOrderExecutionInProgress.load(std::memory_order_acquire); +} + HostFunction HostFunctionStreamer::getHostFunction() { std::unique_lock lock(hostFunctionsMutex); auto hostFunctionId = getHostFunctionId(); @@ -107,7 +123,7 @@ uint64_t HostFunctionStreamer::isHostFunctionReadyToExecute() const { return false; } - if (isBusy.load(std::memory_order_acquire)) { + if (isInOrderExecutionInProgress()) { return false; } diff --git a/shared/source/command_stream/host_function.h b/shared/source/command_stream/host_function.h index 18153d071f..f08cf39582 100644 --- a/shared/source/command_stream/host_function.h +++ b/shared/source/command_stream/host_function.h @@ -66,6 +66,11 @@ class HostFunctionStreamer { void prepareForExecution(const HostFunction &hostFunction); private: + void setHostFunctionIdAsCompleted(); + void startInOrderExecution(); + void endInOrderExecution(); + bool isInOrderExecutionInProgress() const; + std::mutex hostFunctionsMutex; std::unordered_map hostFunctions; volatile uint64_t *hostFunctionIdAddress = nullptr; // 0 bit - used to signal that host function is pending or completed @@ -73,7 +78,7 @@ class HostFunctionStreamer { std::function downloadAllocationImpl; std::atomic nextHostFunctionId{1}; std::atomic pendingHostFunctions{0}; - std::atomic isBusy{false}; + std::atomic inOrderExecutionInProgress{false}; const bool isTbx = false; };