Files
compute-runtime/shared/source/helpers/mt_helpers.h
Warchulski, Jaroslaw 0dc5fb3e51 Cleanup includes 24
Cleaned up files:
opencl/source/mem_obj/image.h
opencl/source/platform/platform.h
shared/source/command_stream/preemption.h
shared/source/helpers/mt_helpers.h
shared/source/memory_manager/unified_memory_manager.h

Related-To: NEO-5548
Signed-off-by: Warchulski, Jaroslaw <jaroslaw.warchulski@intel.com>
2023-01-10 07:56:16 +01:00

39 lines
1019 B
C++

/*
* Copyright (C) 2019-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <atomic>
namespace NEO {
namespace MultiThreadHelpers {
template <typename Type>
inline bool atomicCompareExchangeWeakSpin(std::atomic<Type> &destination,
Type &expectedValue,
const Type desiredValue) {
const Type currentValue = destination;
if (currentValue == expectedValue) {
if (destination.compare_exchange_weak(expectedValue, desiredValue)) {
return true;
}
} else {
expectedValue = currentValue;
}
return false;
}
template <typename Type>
void interlockedMax(std::atomic<Type> &dest, Type newVal) {
Type oldVal = dest;
Type maxVal = oldVal < newVal ? newVal : oldVal;
while (!atomicCompareExchangeWeakSpin(dest, oldVal, maxVal)) {
maxVal = oldVal < newVal ? newVal : oldVal;
}
}
} // namespace MultiThreadHelpers
} // namespace NEO