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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _WIN32 10 #include "lldb/Host/ProcessRunLock.h" 11 12 namespace lldb_private { 13 ProcessRunLock()14ProcessRunLock::ProcessRunLock() { 15 int err = ::pthread_rwlock_init(&m_rwlock, nullptr); 16 (void)err; 17 } 18 ~ProcessRunLock()19ProcessRunLock::~ProcessRunLock() { 20 int err = ::pthread_rwlock_destroy(&m_rwlock); 21 (void)err; 22 } 23 ReadTryLock()24bool ProcessRunLock::ReadTryLock() { 25 ::pthread_rwlock_rdlock(&m_rwlock); 26 if (!m_running) { 27 // coverity[missing_unlock] 28 return true; 29 } 30 ::pthread_rwlock_unlock(&m_rwlock); 31 return false; 32 } 33 ReadUnlock()34bool ProcessRunLock::ReadUnlock() { 35 return ::pthread_rwlock_unlock(&m_rwlock) == 0; 36 } 37 SetRunning()38bool ProcessRunLock::SetRunning() { 39 ::pthread_rwlock_wrlock(&m_rwlock); 40 bool was_stopped = !m_running; 41 m_running = true; 42 ::pthread_rwlock_unlock(&m_rwlock); 43 return was_stopped; 44 } 45 SetStopped()46bool ProcessRunLock::SetStopped() { 47 ::pthread_rwlock_wrlock(&m_rwlock); 48 bool was_running = m_running; 49 m_running = false; 50 ::pthread_rwlock_unlock(&m_rwlock); 51 return was_running; 52 } 53 54 } // namespace lldb_private 55 56 #endif 57