11#include "llvm/Support/ErrorHandling.h"
12#include "llvm/Support/Threading.h"
22 int err = ::pthread_rwlock_init(&
m_rwlock,
nullptr);
27 int err = ::pthread_rwlock_destroy(&
m_rwlock);
42 return ::pthread_rwlock_unlock(&
m_rwlock) == 0;
64 if (other.m_lock && other.m_thread != llvm::get_threadid())
65 llvm::report_fatal_error(
66 "ProcessRunLocker moved across threads while held");
67 assert(!
m_lock &&
"move-construct into a held ProcessRunLocker");
70 other.m_lock =
nullptr;
76 if (other.m_lock && other.m_thread != llvm::get_threadid())
77 llvm::report_fatal_error(
78 "ProcessRunLocker move-assigned across threads while held");
82 other.m_lock =
nullptr;
96 const uint64_t this_thread = llvm::get_threadid();
127 const uint64_t this_thread = llvm::get_threadid();
134 llvm::report_fatal_error(
135 "ProcessRunLocker destroyed on a different thread while held");
137 bool release_rwlock =
false;
139 std::lock_guard<std::mutex> guard(
m_lock->m_recursion_mutex);
140 auto it =
m_lock->m_recursion.find(this_thread);
142 it !=
m_lock->m_recursion.end() &&
143 "ProcessRunLocker released without a matching TryLock on this thread");
144 if (it ==
m_lock->m_recursion.end()) {
148 if (--it->second == 0) {
149 m_lock->m_recursion.erase(it);
150 release_rwlock =
true;
RAII helper around the read-lock side of ProcessRunLock.
ProcessRunLocker & operator=(ProcessRunLocker &&other)
ProcessRunLocker()=default
bool TryLock(ProcessRunLock *lock)
Try to acquire the read lock.
std::mutex m_recursion_mutex
bool SetStopped()
Set the process to stopped.
bool SetRunning()
Set the process to running.
llvm::DenseMap< uint64_t, uint32_t > m_recursion
A class that represents a running process on the host machine.