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"
11#include "lldb/Utility/Instrumentation.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>()) {
20 LLDB_INSTRUMENT_VA(this);
21}
22
23SBMutex::SBMutex(const SBMutex &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
24 LLDB_INSTRUMENT_VA(this);
25}
26
27const SBMutex &SBMutex::operator=(const SBMutex &rhs) {
28 LLDB_INSTRUMENT_VA(this);
29
30 m_opaque_sp = rhs.m_opaque_sp;
31 return *this;
32}
33
34SBMutex::SBMutex(lldb::TargetSP target_sp)
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
40SBMutex::~SBMutex() { LLDB_INSTRUMENT_VA(this); }
41
42bool SBMutex::IsValid() const {
43 LLDB_INSTRUMENT_VA(this);
44
45 return static_cast<bool>(m_opaque_sp);
46}
47
48void SBMutex::lock() const {
49 LLDB_INSTRUMENT_VA(this);
50
51 if (m_opaque_sp)
52 m_opaque_sp->lock();
53}
54
55void SBMutex::unlock() const {
56 LLDB_INSTRUMENT_VA(this);
57
58 if (m_opaque_sp)
59 m_opaque_sp->unlock();
60}
61

source code of lldb/source/API/SBMutex.cpp