1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
//===-- SBMutex.cpp -------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/API/SBMutex.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/Instrumentation.h"
#include "lldb/lldb-forward.h"
#include <memory>
#include <mutex>
using namespace lldb;
using namespace lldb_private;
SBMutex::SBMutex() : m_opaque_sp(std::make_shared<std::recursive_mutex>()) {
LLDB_INSTRUMENT_VA(this);
}
SBMutex::SBMutex(const SBMutex &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
LLDB_INSTRUMENT_VA(this);
}
const SBMutex &SBMutex::operator=(const SBMutex &rhs) {
LLDB_INSTRUMENT_VA(this);
m_opaque_sp = rhs.m_opaque_sp;
return *this;
}
SBMutex::SBMutex(lldb::TargetSP target_sp)
: m_opaque_sp(std::shared_ptr<std::recursive_mutex>(
target_sp, &target_sp->GetAPIMutex())) {
LLDB_INSTRUMENT_VA(this, target_sp);
}
SBMutex::~SBMutex() { LLDB_INSTRUMENT_VA(this); }
bool SBMutex::IsValid() const {
LLDB_INSTRUMENT_VA(this);
return static_cast<bool>(m_opaque_sp);
}
void SBMutex::lock() const {
LLDB_INSTRUMENT_VA(this);
if (m_opaque_sp)
m_opaque_sp->lock();
}
void SBMutex::unlock() const {
LLDB_INSTRUMENT_VA(this);
if (m_opaque_sp)
m_opaque_sp->unlock();
}
|