summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/common
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2016-07-28 17:32:20 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2016-07-28 17:32:20 +0000
commit2d6a9ec9351f974a19eeca4c2326ef9ff701ee37 (patch)
treee306e8382919dfd8618515a84b0cf9f495868bbf /lldb/source/Host/common
parent5ed2b4ba1d87a8f06d7d9c5e7890d913edd44275 (diff)
downloadbcm5719-llvm-2d6a9ec9351f974a19eeca4c2326ef9ff701ee37.tar.gz
bcm5719-llvm-2d6a9ec9351f974a19eeca4c2326ef9ff701ee37.zip
Clean up vestigial remnants of locking primitives
This finally removes the use of the Mutex and Condition classes. This is an intricate patch as the Mutex and Condition classes were tied together. Furthermore, many places had slightly differing uses of time values. Convert timeout values to relative everywhere to permit the use of std::chrono::duration, which is required for the use of std::condition_variable's timeout. Adjust all Condition and related Mutex classes over to std::{,recursive_}mutex and std::condition_variable. This change primarily comes at the cost of breaking the TracingMutex which was based around the Mutex class. It would be possible to write a wrapper to provide similar functionality, but that is beyond the scope of this change. llvm-svn: 277011
Diffstat (limited to 'lldb/source/Host/common')
-rw-r--r--lldb/source/Host/common/Condition.cpp108
-rw-r--r--lldb/source/Host/common/Host.cpp12
-rw-r--r--lldb/source/Host/common/Mutex.cpp398
3 files changed, 2 insertions, 516 deletions
diff --git a/lldb/source/Host/common/Condition.cpp b/lldb/source/Host/common/Condition.cpp
deleted file mode 100644
index 1c1afb4add7..00000000000
--- a/lldb/source/Host/common/Condition.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-//===-- Condition.cpp -------------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include <errno.h>
-
-#include "lldb/Host/Condition.h"
-#include "lldb/Host/TimeValue.h"
-
-
-using namespace lldb_private;
-
-#ifndef _WIN32
-
-//----------------------------------------------------------------------
-// Default constructor
-//
-// The default constructor will initialize a new pthread condition
-// and maintain the condition in the object state.
-//----------------------------------------------------------------------
-Condition::Condition () :
- m_condition()
-{
- ::pthread_cond_init (&m_condition, NULL);
-}
-
-//----------------------------------------------------------------------
-// Destructor
-//
-// Destroys the pthread condition that the object owns.
-//----------------------------------------------------------------------
-Condition::~Condition ()
-{
- ::pthread_cond_destroy (&m_condition);
-}
-
-//----------------------------------------------------------------------
-// Unblock all threads waiting for a condition variable
-//----------------------------------------------------------------------
-int
-Condition::Broadcast ()
-{
- return ::pthread_cond_broadcast (&m_condition);
-}
-
-//----------------------------------------------------------------------
-// Unblocks one thread waiting for the condition variable
-//----------------------------------------------------------------------
-int
-Condition::Signal ()
-{
- return ::pthread_cond_signal (&m_condition);
-}
-
-//----------------------------------------------------------------------
-// The Wait() function atomically blocks the current thread
-// waiting on the owned condition variable, and unblocks the mutex
-// specified by "mutex". The waiting thread unblocks only after
-// another thread calls Signal(), or Broadcast() with the same
-// condition variable, or if "abstime" is valid (non-NULL) this
-// function will return when the system time reaches the time
-// specified in "abstime". If "abstime" is NULL this function will
-// wait for an infinite amount of time for the condition variable
-// to be signaled or broadcasted.
-//
-// The current thread re-acquires the lock on "mutex".
-//----------------------------------------------------------------------
-int
-Condition::Wait (Mutex &mutex, const TimeValue *abstime, bool *timed_out)
-{
- int err = 0;
- do
- {
- if (abstime && abstime->IsValid())
- {
- struct timespec abstime_ts = abstime->GetAsTimeSpec();
- err = ::pthread_cond_timedwait (&m_condition, mutex.GetMutex(), &abstime_ts);
- }
- else
- err = ::pthread_cond_wait (&m_condition, mutex.GetMutex());
- } while (err == EINTR);
-
- if (timed_out != NULL)
- {
- if (err == ETIMEDOUT)
- *timed_out = true;
- else
- *timed_out = false;
- }
-
- return err;
-}
-
-#endif
-
-//----------------------------------------------------------------------
-// Get accessor to the pthread condition object
-//----------------------------------------------------------------------
-lldb::condition_t *
-Condition::GetCondition()
-{
- return &m_condition;
-}
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 5a02c33be83..c5dd105a59b 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -620,14 +620,8 @@ Host::RunShellCommand(const Args &args,
if (error.Success())
{
- TimeValue *timeout_ptr = nullptr;
- TimeValue timeout_time(TimeValue::Now());
- if (timeout_sec > 0) {
- timeout_time.OffsetWithSeconds(timeout_sec);
- timeout_ptr = &timeout_time;
- }
bool timed_out = false;
- shell_info_sp->process_reaped.WaitForValueEqualTo(true, timeout_ptr, &timed_out);
+ shell_info_sp->process_reaped.WaitForValueEqualTo(true, std::chrono::seconds(timeout_sec), &timed_out);
if (timed_out)
{
error.SetErrorString("timed out waiting for shell command to complete");
@@ -635,10 +629,8 @@ Host::RunShellCommand(const Args &args,
// Kill the process since it didn't complete within the timeout specified
Kill (pid, SIGKILL);
// Wait for the monitor callback to get the message
- timeout_time = TimeValue::Now();
- timeout_time.OffsetWithSeconds(1);
timed_out = false;
- shell_info_sp->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out);
+ shell_info_sp->process_reaped.WaitForValueEqualTo(true, std::chrono::seconds(1), &timed_out);
}
else
{
diff --git a/lldb/source/Host/common/Mutex.cpp b/lldb/source/Host/common/Mutex.cpp
deleted file mode 100644
index 98f5321ad67..00000000000
--- a/lldb/source/Host/common/Mutex.cpp
+++ /dev/null
@@ -1,398 +0,0 @@
-//===-- Mutex.cpp -----------------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Host/Mutex.h"
-#include "lldb/Host/Host.h"
-
-#ifndef _WIN32
-#include <pthread.h>
-#endif
-#include <string.h>
-#include <stdio.h>
-
-#if 0
-// This logging is way too verbose to enable even for a log channel.
-// This logging can be enabled by changing the "#if 0", but should be
-// reverted prior to checking in.
-#include <cstdio>
-#define DEBUG_LOG(fmt, ...) printf(fmt, ## __VA_ARGS__)
-#else
-#define DEBUG_LOG(fmt, ...)
-#endif
-
-// Enable extra mutex error checking
-#if 0 // LLDB_CONFIGURATION_DEBUG
-#define ENABLE_MUTEX_ERROR_CHECKING 1
-#include <inttypes.h>
-#endif
-
-#if ENABLE_MUTEX_ERROR_CHECKING
-#include <set>
-
-enum MutexAction
-{
- eMutexActionInitialized,
- eMutexActionDestroyed,
- eMutexActionAssertInitialized
-};
-
-static bool
-error_check_mutex (pthread_mutex_t *m, MutexAction action)
-{
- typedef std::set<pthread_mutex_t *> mutex_set;
- static pthread_mutex_t g_mutex_set_mutex = PTHREAD_MUTEX_INITIALIZER;
- static mutex_set g_initialized_mutex_set;
- static mutex_set g_destroyed_mutex_set;
-
- bool success = true;
- int err;
- // Manually call lock so we don't to any of this error checking
- err = ::pthread_mutex_lock (&g_mutex_set_mutex);
- assert(err == 0);
- switch (action)
- {
- case eMutexActionInitialized:
- // Make sure this isn't already in our initialized mutex set...
- assert (g_initialized_mutex_set.find(m) == g_initialized_mutex_set.end());
- // Remove this from the destroyed set in case it was ever in there
- g_destroyed_mutex_set.erase(m);
- // Add the mutex to the initialized set
- g_initialized_mutex_set.insert(m);
- break;
-
- case eMutexActionDestroyed:
- // Make sure this isn't already in our destroyed mutex set...
- assert (g_destroyed_mutex_set.find(m) == g_destroyed_mutex_set.end());
- // Remove this from the initialized so we can put it into the destroyed set
- g_initialized_mutex_set.erase(m);
- // Add the mutex to the destroyed set
- g_destroyed_mutex_set.insert(m);
- break;
- case eMutexActionAssertInitialized:
- // This function will return true if "m" is in the initialized mutex set
- success = g_initialized_mutex_set.find(m) != g_initialized_mutex_set.end();
- assert (success);
- break;
- }
- // Manually call unlock so we don't to any of this error checking
- err = ::pthread_mutex_unlock (&g_mutex_set_mutex);
- assert(err == 0);
- return success;
-}
-
-#endif
-
-using namespace lldb_private;
-
-//----------------------------------------------------------------------
-// Default constructor.
-//
-// This will create a scoped mutex locking object that doesn't have
-// a mutex to lock. One will need to be provided using the Reset()
-// method.
-//----------------------------------------------------------------------
-Mutex::Locker::Locker () :
- m_mutex_ptr(NULL)
-{
-}
-
-//----------------------------------------------------------------------
-// Constructor with a Mutex object.
-//
-// This will create a scoped mutex locking object that extracts the
-// mutex owned by "m" and locks it.
-//----------------------------------------------------------------------
-Mutex::Locker::Locker (Mutex& m) :
- m_mutex_ptr(NULL)
-{
- Lock (m);
-}
-
-//----------------------------------------------------------------------
-// Constructor with a Mutex object pointer.
-//
-// This will create a scoped mutex locking object that extracts the
-// mutex owned by "m" and locks it.
-//----------------------------------------------------------------------
-Mutex::Locker::Locker (Mutex* m) :
- m_mutex_ptr(NULL)
-{
- if (m)
- Lock (m);
-}
-
-//----------------------------------------------------------------------
-// Destructor
-//
-// Unlocks any owned mutex object (if it is valid).
-//----------------------------------------------------------------------
-Mutex::Locker::~Locker ()
-{
- Unlock();
-}
-
-//----------------------------------------------------------------------
-// Unlock the current mutex in this object (if this owns a valid
-// mutex) and lock the new "mutex" object if it is non-NULL.
-//----------------------------------------------------------------------
-void
-Mutex::Locker::Lock (Mutex &mutex)
-{
- // We already have this mutex locked or both are NULL...
- if (m_mutex_ptr == &mutex)
- return;
-
- Unlock ();
-
- m_mutex_ptr = &mutex;
- m_mutex_ptr->Lock();
-}
-
-void
-Mutex::Locker::Unlock ()
-{
- if (m_mutex_ptr)
- {
- m_mutex_ptr->Unlock ();
- m_mutex_ptr = NULL;
- }
-}
-
-bool
-Mutex::Locker::TryLock (Mutex &mutex, const char *failure_message)
-{
- // We already have this mutex locked!
- if (m_mutex_ptr == &mutex)
- return true;
-
- Unlock ();
-
- if (mutex.TryLock(failure_message) == 0)
- m_mutex_ptr = &mutex;
-
- return m_mutex_ptr != NULL;
-}
-
-#ifndef _WIN32
-
-//----------------------------------------------------------------------
-// Default constructor.
-//
-// Creates a pthread mutex with no attributes.
-//----------------------------------------------------------------------
-Mutex::Mutex () :
- m_mutex()
-{
- int err;
- err = ::pthread_mutex_init (&m_mutex, NULL);
-#if ENABLE_MUTEX_ERROR_CHECKING
- if (err == 0)
- error_check_mutex (&m_mutex, eMutexActionInitialized);
-#endif
- assert(err == 0);
-}
-
-//----------------------------------------------------------------------
-// Default constructor.
-//
-// Creates a pthread mutex with "type" as the mutex type.
-//----------------------------------------------------------------------
-Mutex::Mutex (Mutex::Type type) :
- m_mutex()
-{
- int err;
- ::pthread_mutexattr_t attr;
- err = ::pthread_mutexattr_init (&attr);
- assert(err == 0);
- switch (type)
- {
- case eMutexTypeNormal:
-#if ENABLE_MUTEX_ERROR_CHECKING
- err = ::pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ERRORCHECK);
-#else
- err = ::pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_NORMAL);
-#endif
- break;
-
- case eMutexTypeRecursive:
- err = ::pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
- break;
- }
- assert(err == 0);
- err = ::pthread_mutex_init (&m_mutex, &attr);
-#if ENABLE_MUTEX_ERROR_CHECKING
- if (err == 0)
- error_check_mutex (&m_mutex, eMutexActionInitialized);
-#endif
- assert(err == 0);
- err = ::pthread_mutexattr_destroy (&attr);
- assert(err == 0);
-}
-
-//----------------------------------------------------------------------
-// Destructor.
-//
-// Destroys the mutex owned by this object.
-//----------------------------------------------------------------------
-Mutex::~Mutex()
-{
-#if ENABLE_MUTEX_ERROR_CHECKING
- int err = ::pthread_mutex_destroy (&m_mutex);
- assert(err == 0);
- if (err == 0)
- error_check_mutex (&m_mutex, eMutexActionDestroyed);
- else
- {
- Host::SetCrashDescriptionWithFormat ("%s error: pthread_mutex_destroy() => err = %i (%s)", __PRETTY_FUNCTION__, err, strerror(err));
- assert(err == 0);
- }
- memset (&m_mutex, '\xba', sizeof(m_mutex));
-#else
- ::pthread_mutex_destroy (&m_mutex);
-#endif
-}
-
-//----------------------------------------------------------------------
-// Locks the mutex owned by this object, if the mutex is already
-// locked, the calling thread will block until the mutex becomes
-// available.
-//
-// RETURNS
-// The error code from the pthread_mutex_lock() function call.
-//----------------------------------------------------------------------
-int
-Mutex::Lock()
-{
- DEBUG_LOG ("[%4.4" PRIx64 "/%4.4" PRIx64 "] pthread_mutex_lock (%p)...\n", Host::GetCurrentProcessID(), Host::GetCurrentThreadID(), &m_mutex);
-
-#if ENABLE_MUTEX_ERROR_CHECKING
- error_check_mutex (&m_mutex, eMutexActionAssertInitialized);
-#endif
-
- int err = ::pthread_mutex_lock (&m_mutex);
-
-
-#if ENABLE_MUTEX_ERROR_CHECKING
- if (err)
- {
- Host::SetCrashDescriptionWithFormat ("%s error: pthread_mutex_lock(%p) => err = %i (%s)", __PRETTY_FUNCTION__, &m_mutex, err, strerror(err));
- assert(err == 0);
- }
-#endif
- DEBUG_LOG ("[%4.4" PRIx64 "/%4.4" PRIx64 "] pthread_mutex_lock (%p) => %i\n", Host::GetCurrentProcessID(), Host::GetCurrentThreadID(), &m_mutex, err);
- return err;
-}
-
-//----------------------------------------------------------------------
-// Attempts to lock the mutex owned by this object without blocking.
-// If the mutex is already locked, TryLock() will not block waiting
-// for the mutex, but will return an error condition.
-//
-// RETURNS
-// The error code from the pthread_mutex_trylock() function call.
-//----------------------------------------------------------------------
-int
-Mutex::TryLock(const char *failure_message)
-{
-#if ENABLE_MUTEX_ERROR_CHECKING
- error_check_mutex (&m_mutex, eMutexActionAssertInitialized);
-#endif
-
- int err = ::pthread_mutex_trylock (&m_mutex);
- DEBUG_LOG ("[%4.4" PRIx64 "/%4.4" PRIx64 "] pthread_mutex_trylock (%p) => %i\n", Host::GetCurrentProcessID(), Host::GetCurrentThreadID(), &m_mutex, err);
- return err;
-}
-
-//----------------------------------------------------------------------
-// If the current thread holds the lock on the owned mutex, then
-// Unlock() will unlock the mutex. Calling Unlock() on this object
-// that the calling thread does not hold will result in undefined
-// behavior.
-//
-// RETURNS
-// The error code from the pthread_mutex_unlock() function call.
-//----------------------------------------------------------------------
-int
-Mutex::Unlock()
-{
-#if ENABLE_MUTEX_ERROR_CHECKING
- error_check_mutex (&m_mutex, eMutexActionAssertInitialized);
-#endif
-
- int err = ::pthread_mutex_unlock (&m_mutex);
-
-#if ENABLE_MUTEX_ERROR_CHECKING
- if (err)
- {
- Host::SetCrashDescriptionWithFormat ("%s error: pthread_mutex_unlock(%p) => err = %i (%s)", __PRETTY_FUNCTION__, &m_mutex, err, strerror(err));
- assert(err == 0);
- }
-#endif
- DEBUG_LOG ("[%4.4" PRIx64 "/%4.4" PRIx64 "] pthread_mutex_unlock (%p) => %i\n", Host::GetCurrentProcessID(), Host::GetCurrentThreadID(), &m_mutex, err);
- return err;
-}
-
-#endif
-
-//----------------------------------------------------------------------
-// Mutex get accessor.
-//----------------------------------------------------------------------
-lldb::mutex_t *
-Mutex::GetMutex()
-{
- return &m_mutex;
-}
-
-#ifdef LLDB_CONFIGURATION_DEBUG
-int
-TrackingMutex::Unlock ()
-{
- if (!m_failure_message.empty())
- Host::SetCrashDescriptionWithFormat ("Unlocking lock (on thread %p) that thread: %p failed to get: %s",
- pthread_self(),
- m_thread_that_tried,
- m_failure_message.c_str());
- assert (m_failure_message.empty());
- return Mutex::Unlock();
-}
-
-int
-LoggingMutex::Lock ()
-{
- printf("locking mutex %p by [%4.4" PRIx64 "/%4.4" PRIx64 "]...", this, Host::GetCurrentProcessID(), Host::GetCurrentThreadID());
- int x = Mutex::Lock();
- m_locked = true;
- printf("%d\n",x);
- return x;
-}
-
-int
-LoggingMutex::Unlock ()
-{
- printf("unlocking mutex %p by [%4.4" PRIx64 "/%4.4" PRIx64 "]...", this, Host::GetCurrentProcessID(), Host::GetCurrentThreadID());
- int x = Mutex::Unlock();
- m_locked = false;
- printf("%d\n",x);
- return x;
-}
-
-int
-LoggingMutex::TryLock (const char *failure_message)
-{
- printf("trylocking mutex %p by [%4.4" PRIx64 "/%4.4" PRIx64 "]...", this, Host::GetCurrentProcessID(), Host::GetCurrentThreadID());
- int x = Mutex::TryLock(failure_message);
- if (x == 0)
- m_locked = true;
- printf("%d\n",x);
- return x;
-}
-
-#endif
-
-
OpenPOWER on IntegriCloud