LLDB mainline
lldb_private::TargetAPIMutex Class Reference

A Lockable handle over a Target's API mutex, returned by Target::GetAPIMutex() and backing the public lldb::SBMutex. More...

#include <TargetAPIMutex.h>

Public Member Functions

 TargetAPIMutex ()=default
 TargetAPIMutex (lldb::TargetSP target_sp)
 TargetAPIMutex (TargetAPIMutex &&other) noexcept=default
TargetAPIMutexoperator= (TargetAPIMutex &&other) noexcept=default
 TargetAPIMutex (const TargetAPIMutex &)=delete
TargetAPIMutexoperator= (const TargetAPIMutex &)=delete
void lock ()
bool try_lock ()
void unlock ()

Private Attributes

std::shared_ptr< std::recursive_mutex > m_mutex
 An aliasing shared_ptr into m_target_sp's own mutex, resolved fresh on every lock()/try_lock() call.
lldb::TargetSP m_target_sp

Detailed Description

A Lockable handle over a Target's API mutex, returned by Target::GetAPIMutex() and backing the public lldb::SBMutex.

Behaves like std::recursive_mutex: lock()/try_lock()/unlock() drive the actual synchronization, with the same contract (unlock() without a matching successful lock()/try_lock() is caller error). It carries no RAII of its own; wrap it in std::lock_guard<TargetAPIMutex> or std::unique_lock<TargetAPIMutex> for scope-based locking, exactly as with any other Lockable.

A handle may be constructed on one thread and then locked/unlocked on a different one, so lock()/try_lock() (re-)resolve which real mutex to use fresh on every call, rather than caching a single resolution for the handle's lifetime. The matching unlock() replays the exact resolution that call produced, rather than re-resolving, so the calling thread's policy at unlock() time can't cause it to release the wrong mutex (or fail to release the one it actually holds).

Default-constructed (or moved-from) handles are a genuine no-op: no synchronization primitive is touched at all.

Definition at line 39 of file TargetAPIMutex.h.

Constructor & Destructor Documentation

◆ TargetAPIMutex() [1/4]

lldb_private::TargetAPIMutex::TargetAPIMutex ( )
default

◆ TargetAPIMutex() [2/4]

lldb_private::TargetAPIMutex::TargetAPIMutex ( lldb::TargetSP target_sp)
inlineexplicit

Definition at line 42 of file TargetAPIMutex.h.

References m_target_sp.

◆ TargetAPIMutex() [3/4]

lldb_private::TargetAPIMutex::TargetAPIMutex ( TargetAPIMutex && other)
defaultnoexcept

References TargetAPIMutex().

◆ TargetAPIMutex() [4/4]

lldb_private::TargetAPIMutex::TargetAPIMutex ( const TargetAPIMutex & )
delete

References TargetAPIMutex().

Member Function Documentation

◆ lock()

◆ operator=() [1/2]

TargetAPIMutex & lldb_private::TargetAPIMutex::operator= ( const TargetAPIMutex & )
delete

References TargetAPIMutex().

◆ operator=() [2/2]

TargetAPIMutex & lldb_private::TargetAPIMutex::operator= ( TargetAPIMutex && other)
defaultnoexcept

References TargetAPIMutex().

◆ try_lock()

◆ unlock()

void lldb_private::TargetAPIMutex::unlock ( )
inline

Definition at line 53 of file TargetAPIMutex.h.

References m_mutex.

Member Data Documentation

◆ m_mutex

std::shared_ptr<std::recursive_mutex> lldb_private::TargetAPIMutex::m_mutex
private

An aliasing shared_ptr into m_target_sp's own mutex, resolved fresh on every lock()/try_lock() call.

Shares m_target_sp's control block (keeping the Target alive) while pointing at the mutex living inside it. Null when this handle is a genuine no-op.

Definition at line 63 of file TargetAPIMutex.h.

Referenced by lock(), try_lock(), and unlock().

◆ m_target_sp

lldb::TargetSP lldb_private::TargetAPIMutex::m_target_sp
private

Definition at line 64 of file TargetAPIMutex.h.

Referenced by lock(), TargetAPIMutex(), and try_lock().


The documentation for this class was generated from the following files: