DPC++ Runtime
Runtime libraries for oneAPI DPC++
locked.hpp
Go to the documentation of this file.
1 //==---------------- locked.hpp - Reference with lock -----------*- C++-*---==//
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 
11 #include <sycl/detail/defines.hpp>
12 
13 #include <functional>
14 #include <mutex>
15 
16 namespace sycl {
18 namespace detail {
23 template <typename T> class Locked {
24  std::reference_wrapper<T> m_Value;
25  std::unique_lock<std::mutex> m_Lock;
26 
27 public:
28  Locked(T &v, std::mutex &mutex) : m_Value{v}, m_Lock{mutex} {}
29 
30  T &get() const { return m_Value.get(); }
31 };
32 } // namespace detail
33 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
34 } // namespace sycl
Represents a reference to value with appropriate lock acquired.
Definition: locked.hpp:23
Locked(T &v, std::mutex &mutex)
Definition: locked.hpp:28
#define __SYCL_INLINE_VER_NAMESPACE(X)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14