DPC++ Runtime
Runtime libraries for oneAPI DPC++
spinlock.hpp
Go to the documentation of this file.
1 //==-------------------- spinlock.hpp --- Spin lock ------------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
12 
13 #include <atomic>
14 #include <thread>
15 
17 namespace sycl {
18 namespace detail {
27 class SpinLock {
28 public:
29  void lock() {
30  while (MLock.test_and_set(std::memory_order_acquire))
31  std::this_thread::yield();
32  }
33  void unlock() { MLock.clear(std::memory_order_release); }
34 
35 private:
36  std::atomic_flag MLock = ATOMIC_FLAG_INIT;
37 };
38 } // namespace detail
39 } // namespace sycl
40 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::SpinLock
SpinLock is a synchronization primitive, that uses atomic variable and causes thread trying acquire l...
Definition: spinlock.hpp:27
sycl
Definition: invoke_simd.hpp:68
defines.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::SpinLock::lock
void lock()
Definition: spinlock.hpp:29
cl::sycl::detail::SpinLock::unlock
void unlock()
Definition: spinlock.hpp:33
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12