70 lines · cpp
1//===-- ProcessRunLock.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-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Host/ProcessRunLock.h"10#include "lldb/Host/windows/windows.h"11 12static PSRWLOCK GetLock(lldb::rwlock_t lock) {13 return static_cast<PSRWLOCK>(lock);14}15 16static bool ReadLock(lldb::rwlock_t rwlock) {17 ::AcquireSRWLockShared(GetLock(rwlock));18 return true;19}20 21static bool ReadUnlock(lldb::rwlock_t rwlock) {22 ::ReleaseSRWLockShared(GetLock(rwlock));23 return true;24}25 26static bool WriteLock(lldb::rwlock_t rwlock) {27 ::AcquireSRWLockExclusive(GetLock(rwlock));28 return true;29}30 31static bool WriteUnlock(lldb::rwlock_t rwlock) {32 ::ReleaseSRWLockExclusive(GetLock(rwlock));33 return true;34}35 36using namespace lldb_private;37 38ProcessRunLock::ProcessRunLock() : m_running(false) {39 m_rwlock = new SRWLOCK;40 InitializeSRWLock(GetLock(m_rwlock));41}42 43ProcessRunLock::~ProcessRunLock() { delete static_cast<SRWLOCK *>(m_rwlock); }44 45bool ProcessRunLock::ReadTryLock() {46 ::ReadLock(m_rwlock);47 if (m_running == false)48 return true;49 ::ReadUnlock(m_rwlock);50 return false;51}52 53bool ProcessRunLock::ReadUnlock() { return ::ReadUnlock(m_rwlock); }54 55bool ProcessRunLock::SetRunning() {56 WriteLock(m_rwlock);57 bool was_stopped = !m_running;58 m_running = true;59 WriteUnlock(m_rwlock);60 return was_stopped;61}62 63bool ProcessRunLock::SetStopped() {64 WriteLock(m_rwlock);65 bool was_running = m_running;66 m_running = false;67 WriteUnlock(m_rwlock);68 return was_running;69}70