mirror of
https://github.com/intel/compute-runtime.git
synced 2025-06-28 17:58:30 +08:00

Change-Id: I5496ea963e68e0ef1e107c860112b7123d38aa81 Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
19 lines
435 B
C++
19 lines
435 B
C++
/*
|
|
* Copyright (C) 2019 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
template <typename Type>
|
|
void interlockedMax(std::atomic<Type> &dest, Type newVal) {
|
|
Type oldVal = dest;
|
|
Type maxVal = oldVal < newVal ? newVal : oldVal;
|
|
while (!std::atomic_compare_exchange_weak(&dest, &oldVal, maxVal)) {
|
|
oldVal = dest;
|
|
maxVal = oldVal < newVal ? newVal : oldVal;
|
|
}
|
|
} |