LLDB mainline
SBMutex.h
Go to the documentation of this file.
1//===-- SBMutex.h ---------------------------------------------------------===//
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#ifndef LLDB_API_SBMUTEX_H
10#define LLDB_API_SBMUTEX_H
11
12#include "lldb/API/SBDefines.h"
13#include "lldb/lldb-forward.h"
14#include <memory>
15
16namespace lldb {
17
19public:
20 SBMutex();
21 SBMutex(const SBMutex &rhs);
22 const SBMutex &operator=(const SBMutex &rhs);
23 ~SBMutex();
24
25 /// Returns true if this lock has ownership of the underlying mutex.
26 bool IsValid() const;
27
28 /// Blocking operation that takes ownership of this lock.
29 void lock() const;
30
31 /// Releases ownership of this lock.
32 void unlock() const;
33
34 /// Tries to lock the mutex. Returns immediately. On successful lock
35 /// acquisition returns true, otherwise returns false.
36 bool try_lock() const;
37
38private:
39 // Private constructor used by SBTarget to create the Target API mutex.
40 // Requires a friend declaration.
41 SBMutex(lldb::TargetSP target_sp);
42 friend class SBTarget;
43
44 class MutexVariant;
45 std::shared_ptr<MutexVariant> m_opaque_sp;
46};
47
48} // namespace lldb
49
50#endif
#define LLDB_API
Definition SBDefines.h:28
Holds either a standalone std::recursive_mutex (default-constructed SBMutex, no Target to resolve thr...
Definition SBMutex.cpp:24
bool IsValid() const
Returns true if this lock has ownership of the underlying mutex.
Definition SBMutex.cpp:66
void unlock() const
Releases ownership of this lock.
Definition SBMutex.cpp:79
friend class SBTarget
Definition SBMutex.h:42
bool try_lock() const
Tries to lock the mutex.
Definition SBMutex.cpp:86
std::shared_ptr< MutexVariant > m_opaque_sp
Definition SBMutex.h:45
const SBMutex & operator=(const SBMutex &rhs)
Definition SBMutex.cpp:52
void lock() const
Blocking operation that takes ownership of this lock.
Definition SBMutex.cpp:72
std::shared_ptr< lldb_private::Target > TargetSP