LLDB mainline
SBMutex.cpp
Go to the documentation of this file.
1//===-- SBMutex.cpp -------------------------------------------------------===//
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#include "lldb/API/SBMutex.h"
10#include "lldb/Target/Target.h"
12#include "lldb/lldb-forward.h"
13#include <memory>
14#include <mutex>
15
16using namespace lldb;
17using namespace lldb_private;
18
19SBMutex::SBMutex() : m_opaque_sp(std::make_shared<std::recursive_mutex>()) {
21}
22
23SBMutex::SBMutex(const SBMutex &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
25}
26
29
31 return *this;
32}
33
35 : m_opaque_sp(std::shared_ptr<std::recursive_mutex>(
36 target_sp, &target_sp->GetAPIMutex())) {
37 LLDB_INSTRUMENT_VA(this, target_sp);
38}
39
41
42bool SBMutex::IsValid() const {
44
45 return static_cast<bool>(m_opaque_sp);
46}
47
48void SBMutex::lock() const {
50
51 if (m_opaque_sp)
52 m_opaque_sp->lock();
53}
54
55void SBMutex::unlock() const {
57
58 if (m_opaque_sp)
59 m_opaque_sp->unlock();
60}
#define LLDB_INSTRUMENT_VA(...)
bool IsValid() const
Returns true if this lock has ownership of the underlying mutex.
Definition: SBMutex.cpp:42
void unlock() const
Releases ownership of this lock.
Definition: SBMutex.cpp:55
std::shared_ptr< std::recursive_mutex > m_opaque_sp
Definition: SBMutex.h:40
const SBMutex & operator=(const SBMutex &rhs)
Definition: SBMutex.cpp:27
void lock() const
Blocking operation that takes ownership of this lock.
Definition: SBMutex.cpp:48
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:456