File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
lldb/source/Plugins/LanguageRuntime/Swift Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ // ===----------------- LockGuarded.h ----------------------------*- C++ -*-===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ // ===----------------------------------------------------------------------===//
12
+
13
+ #ifndef liblldb_SwiftLockGuarded_h_
14
+ #define liblldb_SwiftLockGuarded_h_
15
+
16
+ #include < mutex>
17
+
18
+ namespace lldb_private {
19
+ // / A generic wrapper around a resource which holds a lock to ensure
20
+ // / exclusive access.
21
+ template <typename Resource> struct LockGuarded {
22
+ LockGuarded (Resource *resource, std::recursive_mutex &mutex)
23
+ : m_resource(resource), m_lock(mutex, std::adopt_lock) {}
24
+
25
+ LockGuarded () = default ;
26
+
27
+ Resource *operator ->() const { return m_resource; }
28
+
29
+ Resource *operator *() const { return m_resource; }
30
+
31
+ operator bool () const { return m_resource != nullptr ; }
32
+
33
+ private:
34
+ Resource *m_resource;
35
+ std::unique_lock<std::recursive_mutex> m_lock;
36
+ };
37
+
38
+ } // namespace lldb_private
39
+ #endif
You can’t perform that action at this time.
0 commit comments