Files
compute-runtime/runtime/utilities/spinlock.h
Maciej Plewka 9e52684f5b Change namespace from OCLRT to NEO
Change-Id: If965c79d70392db26597aea4c2f3b7ae2820fe96
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
2019-03-26 15:48:19 +01:00

39 lines
663 B
C++

/*
* Copyright (C) 2018-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "runtime/helpers/properties_helper.h"
#include <atomic>
namespace NEO {
class SpinLock : NonCopyableOrMovableClass {
public:
SpinLock() = default;
~SpinLock() = default;
void lock() {
while (flag.test_and_set(std::memory_order_acquire))
;
}
bool try_lock() { // NOLINT
return flag.test_and_set(std::memory_order_acquire) == false;
}
void unlock() {
flag.clear(std::memory_order_release);
}
protected:
std::atomic_flag flag = ATOMIC_FLAG_INIT;
};
} // namespace NEO