2018-02-08 23:00:20 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2018 Intel Corporation
|
2018-02-08 23:00:20 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-02-08 23:00:20 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
class SpinLock {
|
|
|
|
public:
|
|
|
|
void enter(std::atomic_flag &spinLock) {
|
|
|
|
while (spinLock.test_and_set(std::memory_order_acquire)) {
|
|
|
|
};
|
|
|
|
}
|
|
|
|
void leave(std::atomic_flag &spinLock) {
|
|
|
|
spinLock.clear(std::memory_order_release);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-06-13 03:54:39 +08:00
|
|
|
} // namespace OCLRT
|