1 //===-- ProcessRunLock.cpp --------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _WIN32 11 #include "lldb/Host/ProcessRunLock.h" 12 13 namespace lldb_private { 14 15 ProcessRunLock::ProcessRunLock() : m_running(false) { 16 int err = ::pthread_rwlock_init(&m_rwlock, NULL); 17 (void)err; 18 //#if LLDB_CONFIGURATION_DEBUG 19 // assert(err == 0); 20 //#endif 21 } 22 23 ProcessRunLock::~ProcessRunLock() { 24 int err = ::pthread_rwlock_destroy(&m_rwlock); 25 (void)err; 26 //#if LLDB_CONFIGURATION_DEBUG 27 // assert(err == 0); 28 //#endif 29 } 30 31 bool ProcessRunLock::ReadTryLock() { 32 ::pthread_rwlock_rdlock(&m_rwlock); 33 if (m_running == false) { 34 return true; 35 } 36 ::pthread_rwlock_unlock(&m_rwlock); 37 return false; 38 } 39 40 bool ProcessRunLock::ReadUnlock() { 41 return ::pthread_rwlock_unlock(&m_rwlock) == 0; 42 } 43 44 bool ProcessRunLock::SetRunning() { 45 ::pthread_rwlock_wrlock(&m_rwlock); 46 m_running = true; 47 ::pthread_rwlock_unlock(&m_rwlock); 48 return true; 49 } 50 51 bool ProcessRunLock::TrySetRunning() { 52 bool r; 53 54 if (::pthread_rwlock_trywrlock(&m_rwlock) == 0) { 55 r = !m_running; 56 m_running = true; 57 ::pthread_rwlock_unlock(&m_rwlock); 58 return r; 59 } 60 return false; 61 } 62 63 bool ProcessRunLock::SetStopped() { 64 ::pthread_rwlock_wrlock(&m_rwlock); 65 m_running = false; 66 ::pthread_rwlock_unlock(&m_rwlock); 67 return true; 68 } 69 } 70 71 #endif 72