summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Core/Event.h4
-rw-r--r--lldb/include/lldb/Core/Listener.h34
-rw-r--r--lldb/include/lldb/Core/ThreadSafeDenseMap.h27
-rw-r--r--lldb/include/lldb/Core/ThreadSafeDenseSet.h89
-rw-r--r--lldb/include/lldb/Host/Condition.h123
-rw-r--r--lldb/include/lldb/Host/Editline.h1
-rw-r--r--lldb/include/lldb/Host/Mutex.h313
-rw-r--r--lldb/include/lldb/Host/Predicate.h146
-rw-r--r--lldb/include/lldb/Host/ProcessRunLock.h1
-rw-r--r--lldb/include/lldb/Target/Process.h24
-rw-r--r--lldb/source/API/SBListener.cpp31
-rw-r--r--lldb/source/Core/Communication.cpp14
-rw-r--r--lldb/source/Core/Debugger.cpp4
-rw-r--r--lldb/source/Core/Listener.cpp113
-rw-r--r--lldb/source/Host/CMakeLists.txt4
-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
-rw-r--r--lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp6
-rw-r--r--lldb/source/Host/windows/Condition.cpp98
-rw-r--r--lldb/source/Host/windows/Mutex.cpp109
-rw-r--r--lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h1
-rw-r--r--lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp3
-rw-r--r--lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp5
-rw-r--r--lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h2
-rw-r--r--lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp2
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp61
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h15
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp86
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h4
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp12
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp11
-rw-r--r--lldb/source/Target/Process.cpp137
-rw-r--r--lldb/source/Target/Target.cpp11
34 files changed, 404 insertions, 1605 deletions
diff --git a/lldb/include/lldb/Core/Event.h b/lldb/include/lldb/Core/Event.h
index 1ae0fc83b27..43ca58fc750 100644
--- a/lldb/include/lldb/Core/Event.h
+++ b/lldb/include/lldb/Core/Event.h
@@ -12,6 +12,7 @@
// C Includes
// C++ Includes
+#include <chrono>
#include <memory>
#include <string>
@@ -141,7 +142,8 @@ public:
}
bool
- WaitForEventReceived (const TimeValue *abstime = nullptr, bool *timed_out = nullptr)
+ WaitForEventReceived(const std::chrono::microseconds &abstime = std::chrono::microseconds(0),
+ bool *timed_out = nullptr)
{
return m_predicate.WaitForValueEqualTo(true, abstime, timed_out);
}
diff --git a/lldb/include/lldb/Core/Listener.h b/lldb/include/lldb/Core/Listener.h
index 1057cf35c6d..b108d1fff8e 100644
--- a/lldb/include/lldb/Core/Listener.h
+++ b/lldb/include/lldb/Core/Listener.h
@@ -12,6 +12,7 @@
// C Includes
// C++ Includes
+#include <chrono>
#include <list>
#include <map>
#include <mutex>
@@ -21,8 +22,6 @@
// Other libraries and framework includes
// Project includes
#include "lldb/lldb-private.h"
-#include "lldb/Core/Broadcaster.h"
-#include "lldb/Host/Condition.h"
#include "lldb/Core/Event.h"
namespace lldb_private {
@@ -87,19 +86,15 @@ public:
// Returns true if an event was received, false if we timed out.
bool
- WaitForEvent (const TimeValue *timeout,
- lldb::EventSP &event_sp);
+ WaitForEvent(const std::chrono::microseconds &timeout, lldb::EventSP &event_sp);
bool
- WaitForEventForBroadcaster (const TimeValue *timeout,
- Broadcaster *broadcaster,
- lldb::EventSP &event_sp);
+ WaitForEventForBroadcaster(const std::chrono::microseconds &timeout, Broadcaster *broadcaster,
+ lldb::EventSP &event_sp);
bool
- WaitForEventForBroadcasterWithType (const TimeValue *timeout,
- Broadcaster *broadcaster,
- uint32_t event_type_mask,
- lldb::EventSP &event_sp);
+ WaitForEventForBroadcasterWithType(const std::chrono::microseconds &timeout, Broadcaster *broadcaster,
+ uint32_t event_type_mask, lldb::EventSP &event_sp);
Event *
PeekAtNextEvent ();
@@ -151,13 +146,10 @@ private:
typedef std::vector<lldb::BroadcasterManagerWP> broadcaster_manager_collection;
bool
- FindNextEventInternal(Mutex::Locker& lock,
+ FindNextEventInternal(std::unique_lock<std::mutex> &lock,
Broadcaster *broadcaster, // nullptr for any broadcaster
const ConstString *sources, // nullptr for any event
- uint32_t num_sources,
- uint32_t event_type_mask,
- lldb::EventSP &event_sp,
- bool remove);
+ uint32_t num_sources, uint32_t event_type_mask, lldb::EventSP &event_sp, bool remove);
bool
GetNextEventInternal(Broadcaster *broadcaster, // nullptr for any broadcaster
@@ -167,19 +159,17 @@ private:
lldb::EventSP &event_sp);
bool
- WaitForEventsInternal(const TimeValue *timeout,
+ WaitForEventsInternal(const std::chrono::microseconds &timeout,
Broadcaster *broadcaster, // nullptr for any broadcaster
const ConstString *sources, // nullptr for any event
- uint32_t num_sources,
- uint32_t event_type_mask,
- lldb::EventSP &event_sp);
+ uint32_t num_sources, uint32_t event_type_mask, lldb::EventSP &event_sp);
std::string m_name;
broadcaster_collection m_broadcasters;
std::recursive_mutex m_broadcasters_mutex; // Protects m_broadcasters
event_collection m_events;
- Mutex m_events_mutex; // Protects m_broadcasters and m_events
- Condition m_events_condition;
+ std::mutex m_events_mutex; // Protects m_broadcasters and m_events
+ std::condition_variable m_events_condition;
broadcaster_manager_collection m_broadcaster_managers;
void
diff --git a/lldb/include/lldb/Core/ThreadSafeDenseMap.h b/lldb/include/lldb/Core/ThreadSafeDenseMap.h
index 6b2b59b7617..7397d412ad6 100644
--- a/lldb/include/lldb/Core/ThreadSafeDenseMap.h
+++ b/lldb/include/lldb/Core/ThreadSafeDenseMap.h
@@ -12,46 +12,41 @@
// C Includes
// C++ Includes
+#include <mutex>
// Other libraries and framework includes
#include "llvm/ADT/DenseMap.h"
// Project includes
-#include "lldb/Host/Mutex.h"
namespace lldb_private {
-template <typename _KeyType, typename _ValueType>
+template <typename _KeyType, typename _ValueType, typename _MutexType = std::mutex>
class ThreadSafeDenseMap
{
public:
typedef llvm::DenseMap<_KeyType,_ValueType> LLVMMapType;
-
- ThreadSafeDenseMap(unsigned map_initial_capacity = 0,
- Mutex::Type mutex_type = Mutex::eMutexTypeNormal) :
- m_map(map_initial_capacity),
- m_mutex(mutex_type)
- {
- }
-
+
+ ThreadSafeDenseMap(unsigned map_initial_capacity = 0) : m_map(map_initial_capacity), m_mutex() {}
+
void
Insert (_KeyType k, _ValueType v)
{
- Mutex::Locker locker(m_mutex);
+ std::lock_guard<_MutexType> guard(m_mutex);
m_map.insert(std::make_pair(k,v));
}
void
Erase (_KeyType k)
{
- Mutex::Locker locker(m_mutex);
+ std::lock_guard<_MutexType> guard(m_mutex);
m_map.erase(k);
}
_ValueType
Lookup (_KeyType k)
{
- Mutex::Locker locker(m_mutex);
+ std::lock_guard<_MutexType> guard(m_mutex);
return m_map.lookup(k);
}
@@ -59,7 +54,7 @@ public:
Lookup (_KeyType k,
_ValueType& v)
{
- Mutex::Locker locker(m_mutex);
+ std::lock_guard<_MutexType> guard(m_mutex);
auto iter = m_map.find(k),
end = m_map.end();
if (iter == end)
@@ -71,13 +66,13 @@ public:
void
Clear ()
{
- Mutex::Locker locker(m_mutex);
+ std::lock_guard<_MutexType> guard(m_mutex);
m_map.clear();
}
protected:
LLVMMapType m_map;
- Mutex m_mutex;
+ _MutexType m_mutex;
};
} // namespace lldb_private
diff --git a/lldb/include/lldb/Core/ThreadSafeDenseSet.h b/lldb/include/lldb/Core/ThreadSafeDenseSet.h
index e019c70ed5e..c0e58fd42d3 100644
--- a/lldb/include/lldb/Core/ThreadSafeDenseSet.h
+++ b/lldb/include/lldb/Core/ThreadSafeDenseSet.h
@@ -12,61 +12,56 @@
// C Includes
// C++ Includes
+#include <mutex>
// Other libraries and framework includes
#include "llvm/ADT/DenseSet.h"
// Project includes
-#include "lldb/Host/Mutex.h"
namespace lldb_private {
-
- template <typename _ElementType>
- class ThreadSafeDenseSet
+
+template <typename _ElementType, typename _MutexType = std::mutex>
+class ThreadSafeDenseSet
+{
+public:
+ typedef llvm::DenseSet<_ElementType> LLVMSetType;
+
+ ThreadSafeDenseSet(unsigned set_initial_capacity = 0) : m_set(set_initial_capacity), m_mutex() {}
+
+ void
+ Insert(_ElementType e)
{
- public:
- typedef llvm::DenseSet<_ElementType> LLVMSetType;
-
- ThreadSafeDenseSet(unsigned set_initial_capacity = 0,
- Mutex::Type mutex_type = Mutex::eMutexTypeNormal) :
- m_set(set_initial_capacity),
- m_mutex(mutex_type)
- {
- }
-
- void
- Insert (_ElementType e)
- {
- Mutex::Locker locker(m_mutex);
- m_set.insert(e);
- }
-
- void
- Erase (_ElementType e)
- {
- Mutex::Locker locker(m_mutex);
- m_set.erase(e);
- }
-
- bool
- Lookup (_ElementType e)
- {
- Mutex::Locker locker(m_mutex);
- return (m_set.count(e) > 0);
- }
-
- void
- Clear ()
- {
- Mutex::Locker locker(m_mutex);
- m_set.clear();
- }
-
- protected:
- LLVMSetType m_set;
- Mutex m_mutex;
- };
-
+ std::lock_guard<_MutexType> guard(m_mutex);
+ m_set.insert(e);
+ }
+
+ void
+ Erase(_ElementType e)
+ {
+ std::lock_guard<_MutexType> guard(m_mutex);
+ m_set.erase(e);
+ }
+
+ bool
+ Lookup(_ElementType e)
+ {
+ std::lock_guard<_MutexType> guard(m_mutex);
+ return (m_set.count(e) > 0);
+ }
+
+ void
+ Clear()
+ {
+ stds::lock_guard<_MutexType> guard(m_mutex);
+ m_set.clear();
+ }
+
+protected:
+ LLVMSetType m_set;
+ _MutexType m_mutex;
+};
+
} // namespace lldb_private
#endif // liblldb_ThreadSafeDenseSet_h_
diff --git a/lldb/include/lldb/Host/Condition.h b/lldb/include/lldb/Host/Condition.h
deleted file mode 100644
index bd793c65e0f..00000000000
--- a/lldb/include/lldb/Host/Condition.h
+++ /dev/null
@@ -1,123 +0,0 @@
-//===-- Condition.h ---------------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_Condition_h_
-#define liblldb_Condition_h_
-
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-// Project includes
-#include "lldb/lldb-types.h"
-#include "lldb/Host/Mutex.h"
-
-namespace lldb_private {
-
-class TimeValue;
-
-//----------------------------------------------------------------------
-/// @class Condition Condition.h "lldb/Host/Condition.h"
-/// @brief A C++ wrapper class for pthread condition variables.
-///
-/// A class that wraps up a pthread condition (pthread_cond_t). The
-/// class will create a pthread condition when an instance is
-/// constructed, and destroy it when it is destructed. It also provides
-/// access to the standard pthread condition calls.
-//----------------------------------------------------------------------
-class Condition
-{
-public:
- //------------------------------------------------------------------
- /// Default constructor
- ///
- /// The default constructor will initialize a new pthread condition
- /// and maintain the condition in the object state.
- //------------------------------------------------------------------
- Condition ();
-
- //------------------------------------------------------------------
- /// Destructor
- ///
- /// Destroys the pthread condition that the object owns.
- //------------------------------------------------------------------
- ~Condition ();
-
- //------------------------------------------------------------------
- /// Unblock all threads waiting for a condition variable
- ///
- /// @return
- /// The return value from \c pthread_cond_broadcast()
- //------------------------------------------------------------------
- int
- Broadcast ();
-
- //------------------------------------------------------------------
- /// Unblocks one thread waiting for the condition variable
- ///
- /// @return
- /// The return value from \c pthread_cond_signal()
- //------------------------------------------------------------------
- int
- Signal ();
-
- //------------------------------------------------------------------
- /// Wait for the condition variable to be signaled.
- ///
- /// The Wait() function atomically blocks the current thread
- /// waiting on this object's condition variable, and unblocks
- /// \a mutex. The waiting thread unblocks only after another thread
- /// signals or broadcasts this object's condition variable.
- ///
- /// If \a abstime is non-nullptr, this function will return when the
- /// system time reaches the time specified in \a abstime if the
- /// condition variable doesn't get unblocked. If \a abstime is nullptr
- /// this function will wait for an infinite amount of time for the
- /// condition variable to be unblocked.
- ///
- /// The current thread re-acquires the lock on \a mutex following
- /// the wait.
- ///
- /// @param[in] mutex
- /// The mutex to use in the \c pthread_cond_timedwait() or
- /// \c pthread_cond_wait() calls.
- ///
- /// @param[in] abstime
- /// An absolute time at which to stop waiting if non-nullptr, else
- /// wait an infinite amount of time for the condition variable
- /// toget signaled.
- ///
- /// @param[out] timed_out
- /// If not nullptr, will be set to true if the wait timed out, and
- // false otherwise.
- ///
- /// @see Condition::Broadcast()
- /// @see Condition::Signal()
- //------------------------------------------------------------------
- int
- Wait(Mutex &mutex, const TimeValue *abstime = nullptr, bool *timed_out = nullptr);
-
-protected:
- //------------------------------------------------------------------
- // Member variables
- //------------------------------------------------------------------
- lldb::condition_t m_condition; ///< The condition variable.
-
- //------------------------------------------------------------------
- /// Get accessor to the pthread condition object.
- ///
- /// @return
- /// A pointer to the condition variable owned by this object.
- //------------------------------------------------------------------
- lldb::condition_t *
- GetCondition ();
-};
-
-} // namespace lldb_private
-
-#endif // liblldb_Condition_h_
diff --git a/lldb/include/lldb/Host/Editline.h b/lldb/include/lldb/Host/Editline.h
index 43c0eccf37d..95266162e9a 100644
--- a/lldb/include/lldb/Host/Editline.h
+++ b/lldb/include/lldb/Host/Editline.h
@@ -54,7 +54,6 @@
#include <string>
#include <vector>
-#include "lldb/Host/Condition.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Predicate.h"
diff --git a/lldb/include/lldb/Host/Mutex.h b/lldb/include/lldb/Host/Mutex.h
deleted file mode 100644
index 5a529fb4554..00000000000
--- a/lldb/include/lldb/Host/Mutex.h
+++ /dev/null
@@ -1,313 +0,0 @@
-//===-- Mutex.h -------------------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_Mutex_h_
-#define liblldb_Mutex_h_
-
-// C Includes
-// C++ Includes
-#ifdef LLDB_CONFIGURATION_DEBUG
-#include <string>
-#endif
-
-// Other libraries and framework includes
-// Project includes
-#include "lldb/lldb-types.h"
-
-namespace lldb_private {
-
-//----------------------------------------------------------------------
-/// @class Mutex Mutex.h "lldb/Host/Mutex.h"
-/// @brief A C++ wrapper class for pthread mutexes.
-//----------------------------------------------------------------------
-class Mutex
-{
-public:
- friend class Locker;
- friend class Condition;
-
- enum Type
- {
- eMutexTypeNormal, ///< Mutex that can't recursively entered by the same thread
- eMutexTypeRecursive ///< Mutex can be recursively entered by the same thread
- };
-
- //------------------------------------------------------------------
- /// @class Mutex::Locker
- ///
- /// A scoped locking class that allows a variety of pthread mutex
- /// objects to have a mutex locked when an Mutex::Locker
- /// object is created, and unlocked when it goes out of scope or
- /// when the Mutex::Locker::Reset(pthread_mutex_t *)
- /// is called. This provides an exception safe way to lock a mutex
- /// in a scope.
- //------------------------------------------------------------------
- class Locker
- {
- public:
- //--------------------------------------------------------------
- /// 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
- /// Mutex::Locker::Reset(pthread_mutex_t *) method.
- ///
- /// @see Mutex::Locker::Reset(pthread_mutex_t *)
- //--------------------------------------------------------------
- Locker();
-
- //--------------------------------------------------------------
- /// Constructor with a Mutex object.
- ///
- /// This will create a scoped mutex locking object that extracts
- /// the mutex owned by \a m and locks it.
- ///
- /// @param[in] m
- /// An instance of a Mutex object that contains a
- /// valid mutex object.
- //--------------------------------------------------------------
- Locker(Mutex& m);
-
- //--------------------------------------------------------------
- /// Constructor with a Mutex object pointer.
- ///
- /// This will create a scoped mutex locking object that extracts
- /// the mutex owned by a m and locks it.
- ///
- /// @param[in] m
- /// A pointer to instance of a Mutex object that
- /// contains a valid mutex object.
- //--------------------------------------------------------------
- Locker(Mutex* m);
-
- //--------------------------------------------------------------
- /// Destructor
- ///
- /// Unlocks any valid pthread_mutex_t that this object may
- /// contain.
- //--------------------------------------------------------------
- ~Locker();
-
- //--------------------------------------------------------------
- /// Change the contained mutex.
- ///
- /// Unlock the current mutex in this object (if it contains a
- /// valid mutex) and lock the new \a mutex object if it is
- /// non-nullptr.
- //--------------------------------------------------------------
- void
- Lock (Mutex &mutex);
-
- void
- Lock (Mutex *mutex)
- {
- if (mutex)
- Lock(*mutex);
- }
-
- //--------------------------------------------------------------
- /// Change the contained mutex only if the mutex can be locked.
- ///
- /// Unlock the current mutex in this object (if it contains a
- /// valid mutex) and try to lock \a mutex. If \a mutex can be
- /// locked this object will take ownership of the lock and will
- /// unlock it when it goes out of scope or Reset or TryLock are
- /// called again. If the mutex is already locked, this object
- /// will not take ownership of the mutex.
- ///
- /// @return
- /// Returns \b true if the lock was acquired and the this
- /// object will unlock the mutex when it goes out of scope,
- /// returns \b false otherwise.
- //--------------------------------------------------------------
- bool
- TryLock(Mutex &mutex, const char *failure_message = nullptr);
-
- bool
- TryLock(Mutex *mutex, const char *failure_message = nullptr)
- {
- if (mutex)
- return TryLock(*mutex, failure_message);
- else
- return false;
- }
-
- void
- Unlock ();
-
- protected:
- //--------------------------------------------------------------
- /// Member variables
- //--------------------------------------------------------------
- Mutex *m_mutex_ptr;
-
- private:
- Locker(const Locker&);
- const Locker& operator=(const Locker&);
- };
-
- //------------------------------------------------------------------
- /// Default constructor.
- ///
- /// Creates a pthread mutex with no attributes.
- //------------------------------------------------------------------
- Mutex();
-
- //------------------------------------------------------------------
- /// Default constructor.
- ///
- /// Creates a pthread mutex with \a type as the mutex type.
- /// Valid values for \a type include:
- /// @li Mutex::Type::eMutexTypeNormal
- /// @li Mutex::Type::eMutexTypeRecursive
- ///
- /// @param[in] type
- /// The type of the mutex.
- ///
- /// @see ::pthread_mutexattr_settype()
- //------------------------------------------------------------------
- Mutex(Mutex::Type type);
-
- //------------------------------------------------------------------
- /// Destructor.
- ///
- /// Destroys the mutex owned by this object.
- //------------------------------------------------------------------
-#ifdef LLDB_CONFIGURATION_DEBUG
- virtual
-#endif
- ~Mutex();
-
- //------------------------------------------------------------------
- /// Lock the mutex.
- ///
- /// Locks the mutex owned by this object. If the mutex is already
- /// locked, the calling thread will block until the mutex becomes
- /// available.
- ///
- /// @return
- /// The error code from \c pthread_mutex_lock().
- //------------------------------------------------------------------
-#ifdef LLDB_CONFIGURATION_DEBUG
- virtual
-#endif
- int
- Lock();
-
- //------------------------------------------------------------------
- /// Try to lock the mutex.
- ///
- /// 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.
- ///
- /// @return
- /// The error code from \c pthread_mutex_trylock().
- //------------------------------------------------------------------
-#ifdef LLDB_CONFIGURATION_DEBUG
- virtual
-#endif
- int
- TryLock(const char *failure_message = nullptr);
-
- //------------------------------------------------------------------
- /// Unlock the mutex.
- ///
- /// If the current thread holds the lock on the owned mutex, then
- /// Unlock() will unlock the mutex. Calling Unlock() on this object
- /// when the calling thread does not hold the lock will result in
- /// undefined behavior.
- ///
- /// @return
- /// The error code from \c pthread_mutex_unlock().
- //------------------------------------------------------------------
-#ifdef LLDB_CONFIGURATION_DEBUG
- virtual
-#endif
- int
- Unlock();
-
-protected:
- //------------------------------------------------------------------
- // Member variables
- //------------------------------------------------------------------
- // TODO: Hide the mutex in the implementation file in case we ever need to port to an
- // architecture that doesn't have pthread mutexes.
- lldb::mutex_t m_mutex; ///< The OS mutex object.
-
-private:
- //------------------------------------------------------------------
- /// Mutex get accessor.
- ///
- /// @return
- /// A pointer to the pthread mutex object owned by this object.
- //------------------------------------------------------------------
- lldb::mutex_t *
- GetMutex();
-
- Mutex(const Mutex&);
- const Mutex& operator=(const Mutex&);
-};
-
-#ifdef LLDB_CONFIGURATION_DEBUG
-class TrackingMutex : public Mutex
-{
-public:
- TrackingMutex() : Mutex() {}
- TrackingMutex(Mutex::Type type) : Mutex (type) {}
-
- virtual
- ~TrackingMutex() = default;
-
- virtual int
- Unlock ();
-
- virtual int
- TryLock(const char *failure_message = nullptr)
- {
- int return_value = Mutex::TryLock();
- if (return_value != 0 && failure_message != nullptr)
- {
- m_failure_message.assign(failure_message);
- m_thread_that_tried = pthread_self();
- }
- return return_value;
- }
-
-protected:
- pthread_t m_thread_that_tried;
- std::string m_failure_message;
-};
-
-class LoggingMutex : public Mutex
-{
-public:
- LoggingMutex() : Mutex(),m_locked(false) {}
- LoggingMutex(Mutex::Type type) : Mutex (type),m_locked(false) {}
-
- virtual
- ~LoggingMutex() = default;
-
- virtual int
- Lock ();
-
- virtual int
- Unlock ();
-
- virtual int
- TryLock(const char *failure_message = nullptr);
-
-protected:
- bool m_locked;
-};
-#endif // LLDB_CONFIGURATION_DEBUG
-
-} // namespace lldb_private
-
-#endif // liblldb_Mutex_h_
diff --git a/lldb/include/lldb/Host/Predicate.h b/lldb/include/lldb/Host/Predicate.h
index 4f386dc1dd0..7ad376db06a 100644
--- a/lldb/include/lldb/Host/Predicate.h
+++ b/lldb/include/lldb/Host/Predicate.h
@@ -15,11 +15,12 @@
#include <time.h>
// C++ Includes
+#include <condition_variable>
+#include <mutex>
+
// Other libraries and framework includes
// Project includes
#include "lldb/lldb-defines.h"
-#include "lldb/Host/Mutex.h"
-#include "lldb/Host/Condition.h"
//#define DB_PTHREAD_LOG_EVENTS
@@ -97,7 +98,7 @@ public:
T
GetValue () const
{
- Mutex::Locker locker(m_mutex);
+ std::lock_guard<std::mutex> guard(m_mutex);
T value = m_value;
return value;
}
@@ -120,7 +121,7 @@ public:
void
SetValue (T value, PredicateBroadcastType broadcast_type)
{
- Mutex::Locker locker(m_mutex);
+ std::lock_guard<std::mutex> guard(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (value = 0x%8.8x, broadcast_type = %i)\n", __FUNCTION__, value, broadcast_type);
#endif
@@ -148,7 +149,7 @@ public:
void
SetValueBits (T bits, PredicateBroadcastType broadcast_type)
{
- Mutex::Locker locker(m_mutex);
+ std::lock_guard<std::mutex> guard(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (bits = 0x%8.8x, broadcast_type = %i)\n", __FUNCTION__, bits, broadcast_type);
#endif
@@ -176,7 +177,7 @@ public:
void
ResetValueBits (T bits, PredicateBroadcastType broadcast_type)
{
- Mutex::Locker locker(m_mutex);
+ std::lock_guard<std::mutex> guard(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (bits = 0x%8.8x, broadcast_type = %i)\n", __FUNCTION__, bits, broadcast_type);
#endif
@@ -213,21 +214,30 @@ public:
/// occurred.
//------------------------------------------------------------------
T
- WaitForSetValueBits(T bits, const TimeValue *abstime = nullptr)
+ WaitForSetValueBits(T bits, const std::chrono::microseconds &timeout = std::chrono::microseconds(0))
{
- int err = 0;
// pthread_cond_timedwait() or pthread_cond_wait() will atomically
// unlock the mutex and wait for the condition to be set. When either
// function returns, they will re-lock the mutex. We use an auto lock/unlock
- // class (Mutex::Locker) to allow us to return at any point in this
+ // class (std::lock_guard) to allow us to return at any point in this
// function and not have to worry about unlocking the mutex.
- Mutex::Locker locker(m_mutex);
+ std::unique_lock<std::mutex> lock(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
- printf("%s (bits = 0x%8.8x, abstime = %p), m_value = 0x%8.8x\n", __FUNCTION__, bits, abstime, m_value);
+ printf("%s (bits = 0x%8.8x, timeout = %llu), m_value = 0x%8.8x\n", __FUNCTION__, bits, timeout.count(),
+ m_value);
#endif
- while (err == 0 && ((m_value & bits) == 0))
+ while ((m_value & bits) == 0)
{
- err = m_condition.Wait (m_mutex, abstime);
+ if (timeout == std::chrono::microseconds(0))
+ {
+ m_condition.wait(lock);
+ }
+ else
+ {
+ std::cv_status result = m_condition.wait_for(lock, timeout);
+ if (result == std::cv_status::timeout)
+ break;
+ }
}
#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (bits = 0x%8.8x), m_value = 0x%8.8x, returning 0x%8.8x\n", __FUNCTION__, bits, m_value, m_value & bits);
@@ -262,23 +272,31 @@ public:
/// unrecoverable error occurs.
//------------------------------------------------------------------
T
- WaitForResetValueBits(T bits, const TimeValue *abstime = nullptr)
+ WaitForResetValueBits(T bits, const std::chrono::microseconds &timeout = std::chrono::microseconds(0))
{
- int err = 0;
-
// pthread_cond_timedwait() or pthread_cond_wait() will atomically
// unlock the mutex and wait for the condition to be set. When either
// function returns, they will re-lock the mutex. We use an auto lock/unlock
- // class (Mutex::Locker) to allow us to return at any point in this
+ // class (std::lock_guard) to allow us to return at any point in this
// function and not have to worry about unlocking the mutex.
- Mutex::Locker locker(m_mutex);
+ std::unique_lock<std::mutex> lock(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
- printf("%s (bits = 0x%8.8x, abstime = %p), m_value = 0x%8.8x\n", __FUNCTION__, bits, abstime, m_value);
+ printf("%s (bits = 0x%8.8x, timeout = %llu), m_value = 0x%8.8x\n", __FUNCTION__, bits, timeout.count(),
+ m_value);
#endif
- while (err == 0 && ((m_value & bits) != 0))
+ while ((m_value & bits) != 0)
{
- err = m_condition.Wait (m_mutex, abstime);
+ if (timeout == std::chrono::microseconds(0))
+ {
+ m_condition.wait(lock);
+ }
+ else
+ {
+ std::cv_status result = m_condition.wait_for(lock, timeout);
+ if (result == std::cv_status::timeout)
+ break;
+ }
}
#ifdef DB_PTHREAD_LOG_EVENTS
@@ -317,25 +335,39 @@ public:
/// @li \b false otherwise
//------------------------------------------------------------------
bool
- WaitForValueEqualTo(T value, const TimeValue *abstime = nullptr, bool *timed_out = nullptr)
+ WaitForValueEqualTo(T value, const std::chrono::microseconds &timeout = std::chrono::microseconds(0),
+ bool *timed_out = nullptr)
{
- int err = 0;
// pthread_cond_timedwait() or pthread_cond_wait() will atomically
// unlock the mutex and wait for the condition to be set. When either
// function returns, they will re-lock the mutex. We use an auto lock/unlock
- // class (Mutex::Locker) to allow us to return at any point in this
+ // class (std::lock_guard) to allow us to return at any point in this
// function and not have to worry about unlocking the mutex.
- Mutex::Locker locker(m_mutex);
+ std::unique_lock<std::mutex> lock(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
- printf("%s (value = 0x%8.8x, abstime = %p), m_value = 0x%8.8x\n", __FUNCTION__, value, abstime, m_value);
+ printf("%s (value = 0x%8.8x, timeout = %llu), m_value = 0x%8.8x\n", __FUNCTION__, value, timeout.count(),
+ m_value);
#endif
if (timed_out)
*timed_out = false;
- while (err == 0 && m_value != value)
+ while (m_value != value)
{
- err = m_condition.Wait (m_mutex, abstime, timed_out);
+ if (timeout == std::chrono::microseconds(0))
+ {
+ m_condition.wait(lock);
+ }
+ else
+ {
+ std::cv_status result = m_condition.wait_for(lock, timeout);
+ if (result == std::cv_status::timeout)
+ {
+ if (timed_out)
+ *timed_out = true;
+ break;
+ }
+ }
}
return m_value == value;
@@ -378,26 +410,39 @@ public:
//------------------------------------------------------------------
bool
WaitForValueEqualToAndSetValueTo(T wait_value, T new_value,
- const TimeValue *abstime = nullptr,
+ const std::chrono::microseconds &timeout = std::chrono::microseconds(0),
bool *timed_out = nullptr)
{
- int err = 0;
// pthread_cond_timedwait() or pthread_cond_wait() will atomically
// unlock the mutex and wait for the condition to be set. When either
// function returns, they will re-lock the mutex. We use an auto lock/unlock
- // class (Mutex::Locker) to allow us to return at any point in this
+ // class (std::lock_guard) to allow us to return at any point in this
// function and not have to worry about unlocking the mutex.
- Mutex::Locker locker(m_mutex);
+ std::unique_lock<std::mutex> lock(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
- printf("%s (wait_value = 0x%8.8x, new_value = 0x%8.8x, abstime = %p), m_value = 0x%8.8x\n", __FUNCTION__, wait_value, new_value, abstime, m_value);
+ printf("%s (wait_value = 0x%8.8x, new_value = 0x%8.8x, timeout = %llu), m_value = 0x%8.8x\n", __FUNCTION__,
+ wait_value, new_value, timeout.count(), m_value);
#endif
if (timed_out)
*timed_out = false;
- while (err == 0 && m_value != wait_value)
+ while (m_value != wait_value)
{
- err = m_condition.Wait (m_mutex, abstime, timed_out);
+ if (timeout == std::chrono::microseconds(0))
+ {
+ m_condition.wait(lock);
+ }
+ else
+ {
+ std::cv_status result = m_condition.wait_for(m_mutex, timeout);
+ if (result == std::cv_status::timeout)
+ {
+ if (timed_out)
+ *timed_out = true;
+ break;
+ }
+ }
}
if (m_value == wait_value)
@@ -438,21 +483,31 @@ public:
/// @li \b false otherwise
//------------------------------------------------------------------
bool
- WaitForValueNotEqualTo(T value, T &new_value, const TimeValue *abstime = nullptr)
+ WaitForValueNotEqualTo(T value, T &new_value,
+ const std::chrono::microseconds &timeout = std::chrono::microseconds(0))
{
- int err = 0;
// pthread_cond_timedwait() or pthread_cond_wait() will atomically
// unlock the mutex and wait for the condition to be set. When either
// function returns, they will re-lock the mutex. We use an auto lock/unlock
- // class (Mutex::Locker) to allow us to return at any point in this
+ // class (std::lock_guard) to allow us to return at any point in this
// function and not have to worry about unlocking the mutex.
- Mutex::Locker locker(m_mutex);
+ std::unique_lock<std::mutex> lock(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
- printf("%s (value = 0x%8.8x, abstime = %p), m_value = 0x%8.8x\n", __FUNCTION__, value, abstime, m_value);
+ printf("%s (value = 0x%8.8x, timeout = %llu), m_value = 0x%8.8x\n", __FUNCTION__, value, timeout.count(),
+ m_value);
#endif
- while (err == 0 && m_value == value)
+ while (m_value == value)
{
- err = m_condition.Wait (m_mutex, abstime);
+ if (timeout == std::chrono::microseconds(0))
+ {
+ m_condition.wait(lock);
+ }
+ else
+ {
+ std::cv_status result = m_condition.wait_for(lock, timeout);
+ if (result == std::cv_status::timeout)
+ break;
+ }
}
if (m_value != value)
@@ -469,8 +524,9 @@ protected:
// blocking between the main thread and the spotlight index thread.
//----------------------------------------------------------------------
T m_value; ///< The templatized value T that we are protecting access to
- mutable Mutex m_mutex; ///< The mutex to use when accessing the data
- Condition m_condition; ///< The pthread condition variable to use for signaling that data available or changed.
+ mutable std::mutex m_mutex; ///< The mutex to use when accessing the data
+ std::condition_variable
+ m_condition; ///< The pthread condition variable to use for signaling that data available or changed.
private:
//------------------------------------------------------------------
@@ -496,7 +552,7 @@ private:
printf("%s (old_value = 0x%8.8x, broadcast_type = %i) m_value = 0x%8.8x, broadcast = %u\n", __FUNCTION__, old_value, broadcast_type, m_value, broadcast);
#endif
if (broadcast)
- m_condition.Broadcast();
+ m_condition.notify_all();
}
DISALLOW_COPY_AND_ASSIGN(Predicate);
diff --git a/lldb/include/lldb/Host/ProcessRunLock.h b/lldb/include/lldb/Host/ProcessRunLock.h
index 797939a7ede..df437ebbc5a 100644
--- a/lldb/include/lldb/Host/ProcessRunLock.h
+++ b/lldb/include/lldb/Host/ProcessRunLock.h
@@ -18,7 +18,6 @@
// Other libraries and framework includes
// Project includes
#include "lldb/lldb-defines.h"
-#include "lldb/Host/Condition.h"
//----------------------------------------------------------------------
/// Enumerations for broadcasting.
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index 2ecc772ca19..4ae835612cb 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -16,6 +16,7 @@
#include <limits.h>
// C++ Includes
+#include <chrono>
#include <list>
#include <memory>
#include <mutex>
@@ -2920,12 +2921,9 @@ public:
// function releases the run lock after the stop. Setting use_run_lock to false
// will avoid this behavior.
lldb::StateType
- WaitForProcessToStop(const TimeValue *timeout,
- lldb::EventSP *event_sp_ptr = nullptr,
- bool wait_always = true,
- lldb::ListenerSP hijack_listener = lldb::ListenerSP(),
- Stream *stream = nullptr,
- bool use_run_lock = true);
+ WaitForProcessToStop(const std::chrono::microseconds &timeout, lldb::EventSP *event_sp_ptr = nullptr,
+ bool wait_always = true, lldb::ListenerSP hijack_listener = lldb::ListenerSP(),
+ Stream *stream = nullptr, bool use_run_lock = true);
uint32_t
GetIOHandlerID () const
@@ -2947,8 +2945,7 @@ public:
SyncIOHandler (uint32_t iohandler_id, uint64_t timeout_msec);
lldb::StateType
- WaitForStateChangedEvents(const TimeValue *timeout,
- lldb::EventSP &event_sp,
+ WaitForStateChangedEvents(const std::chrono::microseconds &timeout, lldb::EventSP &event_sp,
lldb::ListenerSP hijack_listener); // Pass an empty ListenerSP to use builtin listener
//--------------------------------------------------------------------------------------
@@ -3538,21 +3535,20 @@ protected:
HaltPrivate();
lldb::StateType
- WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
+ WaitForProcessStopPrivate(const std::chrono::microseconds &timeout, lldb::EventSP &event_sp);
// This waits for both the state change broadcaster, and the control broadcaster.
// If control_only, it only waits for the control broadcaster.
bool
- WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only);
+ WaitForEventsPrivate(const std::chrono::microseconds &timeout, lldb::EventSP &event_sp, bool control_only);
lldb::StateType
- WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
+ WaitForStateChangedEventsPrivate(const std::chrono::microseconds &timeout, lldb::EventSP &event_sp);
lldb::StateType
- WaitForState (const TimeValue *timeout,
- const lldb::StateType *match_states,
- const uint32_t num_match_states);
+ WaitForState(const std::chrono::microseconds &timeout, const lldb::StateType *match_states,
+ const uint32_t num_match_states);
size_t
WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error);
diff --git a/lldb/source/API/SBListener.cpp b/lldb/source/API/SBListener.cpp
index 8e63de0b769..28abf3b2a79 100644
--- a/lldb/source/API/SBListener.cpp
+++ b/lldb/source/API/SBListener.cpp
@@ -17,7 +17,6 @@
#include "lldb/Core/Listener.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamString.h"
-#include "lldb/Host/TimeValue.h"
using namespace lldb;
@@ -202,15 +201,14 @@ SBListener::WaitForEvent (uint32_t timeout_secs, SBEvent &event)
if (m_opaque_sp)
{
- TimeValue time_value;
+ std::chrono::microseconds timeout = std::chrono::microseconds(0);
if (timeout_secs != UINT32_MAX)
{
assert (timeout_secs != 0); // Take this out after all calls with timeout set to zero have been removed....
- time_value = TimeValue::Now();
- time_value.OffsetWithSeconds (timeout_secs);
+ timeout = std::chrono::seconds(timeout_secs);
}
EventSP event_sp;
- if (m_opaque_sp->WaitForEvent (time_value.IsValid() ? &time_value : NULL, event_sp))
+ if (m_opaque_sp->WaitForEvent(timeout, event_sp))
{
event.reset (event_sp);
success = true;
@@ -247,16 +245,11 @@ SBListener::WaitForEventForBroadcaster
{
if (m_opaque_sp && broadcaster.IsValid())
{
- TimeValue time_value;
+ std::chrono::microseconds timeout = std::chrono::microseconds(0);
if (num_seconds != UINT32_MAX)
- {
- time_value = TimeValue::Now();
- time_value.OffsetWithSeconds (num_seconds);
- }
+ timeout = std::chrono::seconds(num_seconds);
EventSP event_sp;
- if (m_opaque_sp->WaitForEventForBroadcaster (time_value.IsValid() ? &time_value : NULL,
- broadcaster.get(),
- event_sp))
+ if (m_opaque_sp->WaitForEventForBroadcaster(timeout, broadcaster.get(), event_sp))
{
event.reset (event_sp);
return true;
@@ -278,17 +271,11 @@ SBListener::WaitForEventForBroadcasterWithType
{
if (m_opaque_sp && broadcaster.IsValid())
{
- TimeValue time_value;
+ std::chrono::microseconds timeout = std::chrono::microseconds(0);
if (num_seconds != UINT32_MAX)
- {
- time_value = TimeValue::Now();
- time_value.OffsetWithSeconds (num_seconds);
- }
+ timeout = std::chrono::seconds(num_seconds);
EventSP event_sp;
- if (m_opaque_sp->WaitForEventForBroadcasterWithType (time_value.IsValid() ? &time_value : NULL,
- broadcaster.get(),
- event_type_mask,
- event_sp))
+ if (m_opaque_sp->WaitForEventForBroadcasterWithType(timeout, broadcaster.get(), event_type_mask, event_sp))
{
event.reset (event_sp);
return true;
diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp
index f1dcb95e8af..dbd0f775eeb 100644
--- a/lldb/source/Core/Communication.cpp
+++ b/lldb/source/Core/Communication.cpp
@@ -156,18 +156,14 @@ Communication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, Connectio
status = eConnectionStatusNoConnection;
return 0;
}
- // Set the timeout appropriately
- TimeValue timeout_time;
- if (timeout_usec != UINT32_MAX)
- {
- timeout_time = TimeValue::Now();
- timeout_time.OffsetWithMicroSeconds (timeout_usec);
- }
ListenerSP listener_sp(Listener::MakeListener("Communication::Read"));
listener_sp->StartListeningForEvents (this, eBroadcastBitReadThreadGotBytes | eBroadcastBitReadThreadDidExit);
EventSP event_sp;
- while (listener_sp->WaitForEvent (timeout_time.IsValid() ? &timeout_time : nullptr, event_sp))
+ std::chrono::microseconds timeout = std::chrono::microseconds(0);
+ if (timeout_usec != UINT32_MAX)
+ timeout = std::chrono::microseconds(timeout_usec);
+ while (listener_sp->WaitForEvent(timeout, event_sp))
{
const uint32_t event_type = event_sp->GetType();
if (event_type & eBroadcastBitReadThreadGotBytes)
@@ -439,7 +435,7 @@ Communication::SynchronizeWithReadThread ()
// Wait for the synchronization event.
EventSP event_sp;
- listener_sp->WaitForEvent(nullptr, event_sp);
+ listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp);
}
void
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 34608d0193f..a30ce674f3a 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -1608,7 +1608,7 @@ Debugger::DefaultEventHandler()
while (!done)
{
EventSP event_sp;
- if (listener_sp->WaitForEvent(nullptr, event_sp))
+ if (listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp))
{
if (event_sp)
{
@@ -1705,7 +1705,7 @@ Debugger::StartEventHandlerThread()
// eBroadcastBitEventThreadIsListening so we don't need to check the event, we just need
// to wait an infinite amount of time for it (nullptr timeout as the first parameter)
lldb::EventSP event_sp;
- listener_sp->WaitForEvent(nullptr, event_sp);
+ listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp);
}
return m_event_handler_thread.IsJoinable();
}
diff --git a/lldb/source/Core/Listener.cpp b/lldb/source/Core/Listener.cpp
index 15a69878468..f675110c2c8 100644
--- a/lldb/source/Core/Listener.cpp
+++ b/lldb/source/Core/Listener.cpp
@@ -19,7 +19,6 @@
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Event.h"
-#include "lldb/Host/TimeValue.h"
using namespace lldb;
using namespace lldb_private;
@@ -41,7 +40,7 @@ namespace
} // anonymous namespace
Listener::Listener(const char *name)
- : m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(), m_events_mutex(Mutex::eMutexTypeNormal)
+ : m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(), m_events_mutex()
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
if (log != nullptr)
@@ -63,7 +62,7 @@ void
Listener::Clear()
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
- std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ std::lock_guard<std::recursive_mutex> broadcasters_guard(m_broadcasters_mutex);
broadcaster_collection::iterator pos, end = m_broadcasters.end();
for (pos = m_broadcasters.begin(); pos != end; ++pos)
{
@@ -73,7 +72,7 @@ Listener::Clear()
}
m_broadcasters.clear();
- Mutex::Locker event_locker(m_events_mutex);
+ std::lock_guard<std::mutex> events_guard(m_events_mutex);
m_events.clear();
size_t num_managers = m_broadcaster_managers.size();
@@ -96,7 +95,7 @@ Listener::StartListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask
// Scope for "locker"
// Tell the broadcaster to add this object as a listener
{
- std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ std::lock_guard<std::recursive_mutex> broadcasters_guard(m_broadcasters_mutex);
Broadcaster::BroadcasterImplWP impl_wp(broadcaster->GetBroadcasterImpl());
m_broadcasters.insert(std::make_pair(impl_wp, BroadcasterInfo(event_mask)));
}
@@ -123,7 +122,7 @@ Listener::StartListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask
// Scope for "locker"
// Tell the broadcaster to add this object as a listener
{
- std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ std::lock_guard<std::recursive_mutex> broadcasters_guard(m_broadcasters_mutex);
Broadcaster::BroadcasterImplWP impl_wp(broadcaster->GetBroadcasterImpl());
m_broadcasters.insert(std::make_pair(impl_wp,
BroadcasterInfo(event_mask, callback, callback_user_data)));
@@ -154,7 +153,7 @@ Listener::StopListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask)
{
// Scope for "locker"
{
- std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ std::lock_guard<std::recursive_mutex> broadcasters_guard(m_broadcasters_mutex);
m_broadcasters.erase (broadcaster->GetBroadcasterImpl());
}
// Remove the broadcaster from our set of broadcasters
@@ -171,13 +170,13 @@ Listener::BroadcasterWillDestruct (Broadcaster *broadcaster)
{
// Scope for "broadcasters_locker"
{
- std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ std::lock_guard<std::recursive_mutex> broadcasters_guard(m_broadcasters_mutex);
m_broadcasters.erase (broadcaster->GetBroadcasterImpl());
}
// Scope for "event_locker"
{
- Mutex::Locker event_locker(m_events_mutex);
+ std::lock_guard<std::mutex> events_guard(m_events_mutex);
// Remove all events for this broadcaster object.
event_collection::iterator pos = m_events.begin();
while (pos != m_events.end())
@@ -212,9 +211,9 @@ Listener::AddEvent (EventSP &event_sp)
static_cast<void*>(this), m_name.c_str(),
static_cast<void*>(event_sp.get()));
- Mutex::Locker locker(m_events_mutex);
+ std::lock_guard<std::mutex> guard(m_events_mutex);
m_events.push_back (event_sp);
- m_events_condition.Broadcast();
+ m_events_condition.notify_all();
}
class EventBroadcasterMatches
@@ -279,15 +278,11 @@ private:
};
bool
-Listener::FindNextEventInternal
-(
- Mutex::Locker& lock,
- Broadcaster *broadcaster, // nullptr for any broadcaster
- const ConstString *broadcaster_names, // nullptr for any event
- uint32_t num_broadcaster_names,
- uint32_t event_type_mask,
- EventSP &event_sp,
- bool remove)
+Listener::FindNextEventInternal(std::unique_lock<std::mutex> &lock,
+ Broadcaster *broadcaster, // nullptr for any broadcaster
+ const ConstString *broadcaster_names, // nullptr for any event
+ uint32_t num_broadcaster_names, uint32_t event_type_mask, EventSP &event_sp,
+ bool remove)
{
// NOTE: callers of this function must lock m_events_mutex using a Mutex::Locker
// and pass the locker as the first argument. m_events_mutex is no longer recursive.
@@ -325,7 +320,7 @@ Listener::FindNextEventInternal
// Unlock the event queue here. We've removed this event and are about to return
// it so it should be okay to get the next event off the queue here - and it might
// be useful to do that in the "DoOnRemoval".
- lock.Unlock();
+ lock.unlock();
event_sp->DoOnRemoval();
}
return true;
@@ -338,9 +333,9 @@ Listener::FindNextEventInternal
Event *
Listener::PeekAtNextEvent ()
{
- Mutex::Locker lock(m_events_mutex);
+ std::unique_lock<std::mutex> guard(m_events_mutex);
EventSP event_sp;
- if (FindNextEventInternal(lock, nullptr, nullptr, 0, 0, event_sp, false))
+ if (FindNextEventInternal(guard, nullptr, nullptr, 0, 0, event_sp, false))
return event_sp.get();
return nullptr;
}
@@ -348,9 +343,9 @@ Listener::PeekAtNextEvent ()
Event *
Listener::PeekAtNextEventForBroadcaster (Broadcaster *broadcaster)
{
- Mutex::Locker lock(m_events_mutex);
+ std::unique_lock<std::mutex> guard(m_events_mutex);
EventSP event_sp;
- if (FindNextEventInternal(lock, broadcaster, nullptr, 0, 0, event_sp, false))
+ if (FindNextEventInternal(guard, broadcaster, nullptr, 0, 0, event_sp, false))
return event_sp.get();
return nullptr;
}
@@ -358,9 +353,9 @@ Listener::PeekAtNextEventForBroadcaster (Broadcaster *broadcaster)
Event *
Listener::PeekAtNextEventForBroadcasterWithType (Broadcaster *broadcaster, uint32_t event_type_mask)
{
- Mutex::Locker lock(m_events_mutex);
+ std::unique_lock<std::mutex> guard(m_events_mutex);
EventSP event_sp;
- if (FindNextEventInternal(lock, broadcaster, nullptr, 0, event_type_mask, event_sp, false))
+ if (FindNextEventInternal(guard, broadcaster, nullptr, 0, event_type_mask, event_sp, false))
return event_sp.get();
return nullptr;
}
@@ -372,8 +367,9 @@ Listener::GetNextEventInternal(Broadcaster *broadcaster, // nullptr
uint32_t event_type_mask,
EventSP &event_sp)
{
- Mutex::Locker lock(m_events_mutex);
- return FindNextEventInternal (lock, broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask, event_sp, true);
+ std::unique_lock<std::mutex> guard(m_events_mutex);
+ return FindNextEventInternal(guard, broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask,
+ event_sp, true);
}
bool
@@ -395,20 +391,17 @@ Listener::GetNextEventForBroadcasterWithType (Broadcaster *broadcaster, uint32_t
}
bool
-Listener::WaitForEventsInternal(const TimeValue *timeout,
+Listener::WaitForEventsInternal(const std::chrono::microseconds &timeout,
Broadcaster *broadcaster, // nullptr for any broadcaster
const ConstString *broadcaster_names, // nullptr for any event
- uint32_t num_broadcaster_names,
- uint32_t event_type_mask,
- EventSP &event_sp)
+ uint32_t num_broadcaster_names, uint32_t event_type_mask, EventSP &event_sp)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS));
if (log != nullptr)
- log->Printf ("%p Listener::WaitForEventsInternal (timeout = { %p }) for %s",
- static_cast<void*>(this), static_cast<const void*>(timeout),
- m_name.c_str());
+ log->Printf("%p Listener::WaitForEventsInternal (timeout = %llu us) for %s", static_cast<void *>(this),
+ static_cast<unsigned long long>(timeout.count()), m_name.c_str());
- Mutex::Locker lock(m_events_mutex);
+ std::unique_lock<std::mutex> lock(m_events_mutex);
while (true)
{
@@ -418,23 +411,26 @@ Listener::WaitForEventsInternal(const TimeValue *timeout,
}
else
{
- bool timed_out = false;
- if (m_events_condition.Wait(m_events_mutex, timeout, &timed_out) != 0)
+ std::cv_status result = std::cv_status::no_timeout;
+ if (timeout == std::chrono::microseconds(0))
+ m_events_condition.wait(lock);
+ else
+ result = m_events_condition.wait_for(lock, timeout);
+
+ if (result == std::cv_status::timeout)
{
- if (timed_out)
- {
- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS);
- if (log != nullptr)
- log->Printf ("%p Listener::WaitForEventsInternal() timed out for %s",
- static_cast<void*>(this), m_name.c_str());
- }
- else
- {
- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS);
- if (log != nullptr)
- log->Printf ("%p Listener::WaitForEventsInternal() unknown error for %s",
- static_cast<void*>(this), m_name.c_str());
- }
+ log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS);
+ if (log)
+ log->Printf("%p Listener::WaitForEventsInternal() timed out for %s", static_cast<void *>(this),
+ m_name.c_str());
+ return false;
+ }
+ else if (result != std::cv_status::no_timeout)
+ {
+ log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS);
+ if (log)
+ log->Printf("%p Listener::WaitForEventsInternal() unknown error for %s", static_cast<void *>(this),
+ m_name.c_str());
return false;
}
}
@@ -444,24 +440,21 @@ Listener::WaitForEventsInternal(const TimeValue *timeout,
}
bool
-Listener::WaitForEventForBroadcasterWithType(const TimeValue *timeout,
- Broadcaster *broadcaster,
- uint32_t event_type_mask,
- EventSP &event_sp)
+Listener::WaitForEventForBroadcasterWithType(const std::chrono::microseconds &timeout, Broadcaster *broadcaster,
+ uint32_t event_type_mask, EventSP &event_sp)
{
return WaitForEventsInternal(timeout, broadcaster, nullptr, 0, event_type_mask, event_sp);
}
bool
-Listener::WaitForEventForBroadcaster(const TimeValue *timeout,
- Broadcaster *broadcaster,
+Listener::WaitForEventForBroadcaster(const std::chrono::microseconds &timeout, Broadcaster *broadcaster,
EventSP &event_sp)
{
return WaitForEventsInternal(timeout, broadcaster, nullptr, 0, 0, event_sp);
}
bool
-Listener::WaitForEvent (const TimeValue *timeout, EventSP &event_sp)
+Listener::WaitForEvent(const std::chrono::microseconds &timeout, EventSP &event_sp)
{
return WaitForEventsInternal(timeout, nullptr, nullptr, 0, 0, event_sp);
}
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index 94f6975b91c..2b4b4211b0b 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -4,7 +4,6 @@ macro(add_host_subdirectory group)
endmacro()
add_host_subdirectory(common
- common/Condition.cpp
common/File.cpp
common/FileCache.cpp
common/FileSpec.cpp
@@ -17,7 +16,6 @@ add_host_subdirectory(common
common/HostThread.cpp
common/IOObject.cpp
common/LockFileBase.cpp
- common/Mutex.cpp
common/MonitoringProcessLauncher.cpp
common/NativeBreakpoint.cpp
common/NativeBreakpointList.cpp
@@ -60,7 +58,6 @@ add_host_subdirectory(posix
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
add_host_subdirectory(windows
- windows/Condition.cpp
windows/ConnectionGenericFileWindows.cpp
windows/EditLineWin.cpp
windows/FileSystem.cpp
@@ -69,7 +66,6 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
windows/HostProcessWindows.cpp
windows/HostThreadWindows.cpp
windows/LockFileWindows.cpp
- windows/Mutex.cpp
windows/PipeWindows.cpp
windows/ProcessLauncherWindows.cpp
windows/ProcessRunLock.cpp
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
-
-
diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
index 53004e5d691..5d6a8938e00 100644
--- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
+++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
@@ -877,11 +877,7 @@ ConnectionFileDescriptor::GetListeningPort(uint32_t timeout_sec)
if (timeout_sec == UINT32_MAX)
m_port_predicate.WaitForValueNotEqualTo(0, bound_port);
else
- {
- TimeValue timeout = TimeValue::Now();
- timeout.OffsetWithSeconds(timeout_sec);
- m_port_predicate.WaitForValueNotEqualTo(0, bound_port, &timeout);
- }
+ m_port_predicate.WaitForValueNotEqualTo(0, bound_port, std::chrono::seconds(timeout_sec));
return bound_port;
}
diff --git a/lldb/source/Host/windows/Condition.cpp b/lldb/source/Host/windows/Condition.cpp
deleted file mode 100644
index 2f16ad77d7a..00000000000
--- a/lldb/source/Host/windows/Condition.cpp
+++ /dev/null
@@ -1,98 +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"
-#include "lldb/Host/windows/windows.h"
-
-
-using namespace lldb_private;
-
-//----------------------------------------------------------------------
-// Default constructor
-//
-// The default constructor will initialize a new pthread condition
-// and maintain the condition in the object state.
-//----------------------------------------------------------------------
-Condition::Condition () :
- m_condition()
-{
- m_condition = static_cast<PCONDITION_VARIABLE>(malloc(sizeof(CONDITION_VARIABLE)));
- InitializeConditionVariable(static_cast<PCONDITION_VARIABLE>(m_condition));
-}
-
-//----------------------------------------------------------------------
-// Destructor
-//
-// Destroys the pthread condition that the object owns.
-//----------------------------------------------------------------------
-Condition::~Condition ()
-{
- free(m_condition);
-}
-
-//----------------------------------------------------------------------
-// Unblock all threads waiting for a condition variable
-//----------------------------------------------------------------------
-int
-Condition::Broadcast ()
-{
- WakeAllConditionVariable(static_cast<PCONDITION_VARIABLE>(m_condition));
- return 0;
-}
-
-//----------------------------------------------------------------------
-// Unblocks one thread waiting for the condition variable
-//----------------------------------------------------------------------
-int
-Condition::Signal ()
-{
- WakeConditionVariable(static_cast<PCONDITION_VARIABLE>(m_condition));
- return 0;
-}
-
-//----------------------------------------------------------------------
-// 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)
-{
- DWORD wait = INFINITE;
- if (abstime != NULL) {
- int wval = (*abstime - TimeValue::Now()) / 1000000;
- if (wval < 0) wval = 0;
-
- wait = wval;
- }
-
- int err = SleepConditionVariableCS(static_cast<PCONDITION_VARIABLE>(m_condition), static_cast<PCRITICAL_SECTION>(mutex.m_mutex), wait);
-
- if (timed_out != NULL)
- {
- if ((err == 0) && GetLastError() == ERROR_TIMEOUT)
- *timed_out = true;
- else
- *timed_out = false;
- }
-
- return err == 0;
-}
-
diff --git a/lldb/source/Host/windows/Mutex.cpp b/lldb/source/Host/windows/Mutex.cpp
deleted file mode 100644
index ed90f46eb54..00000000000
--- a/lldb/source/Host/windows/Mutex.cpp
+++ /dev/null
@@ -1,109 +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"
-#include "lldb/Host/windows/windows.h"
-
-#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
-
-using namespace lldb_private;
-
-//----------------------------------------------------------------------
-// Default constructor.
-//
-// Creates a pthread mutex with no attributes.
-//----------------------------------------------------------------------
-Mutex::Mutex () :
- m_mutex()
-{
- m_mutex = static_cast<PCRITICAL_SECTION>(malloc(sizeof(CRITICAL_SECTION)));
- InitializeCriticalSection(static_cast<PCRITICAL_SECTION>(m_mutex));
-}
-
-//----------------------------------------------------------------------
-// Default constructor.
-//
-// Creates a pthread mutex with "type" as the mutex type.
-//----------------------------------------------------------------------
-Mutex::Mutex (Mutex::Type type) :
- m_mutex()
-{
- m_mutex = static_cast<PCRITICAL_SECTION>(malloc(sizeof(CRITICAL_SECTION)));
- InitializeCriticalSection(static_cast<PCRITICAL_SECTION>(m_mutex));
-}
-
-//----------------------------------------------------------------------
-// Destructor.
-//
-// Destroys the mutex owned by this object.
-//----------------------------------------------------------------------
-Mutex::~Mutex()
-{
- DeleteCriticalSection(static_cast<PCRITICAL_SECTION>(m_mutex));
- free(m_mutex);
-}
-
-//----------------------------------------------------------------------
-// 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);
-
- EnterCriticalSection(static_cast<PCRITICAL_SECTION>(m_mutex));
- return 0;
-}
-
-//----------------------------------------------------------------------
-// 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)
-{
- return TryEnterCriticalSection(static_cast<PCRITICAL_SECTION>(m_mutex)) == 0;
-}
-
-//----------------------------------------------------------------------
-// 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()
-{
- LeaveCriticalSection(static_cast<PCRITICAL_SECTION>(m_mutex));
- return 0;
-}
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h
index 98042188b18..18195044be8 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h
@@ -22,7 +22,6 @@
#include "lldb/Host/FileSpec.h"
#include "lldb/Core/StructuredData.h"
#include "lldb/Core/UUID.h"
-#include "lldb/Host/Mutex.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/SafeMachO.h"
diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
index 846e350eec5..404cc873d9e 100644
--- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -699,7 +699,8 @@ PlatformLinux::DebugProcess (ProcessLaunchInfo &launch_info,
// Handle the hijacking of process events.
if (listener_sp)
{
- const StateType state = process_sp->WaitForProcessToStop (NULL, NULL, false, listener_sp);
+ const StateType state =
+ process_sp->WaitForProcessToStop(std::chrono::microseconds(0), NULL, false, listener_sp);
if (state == eStateStopped)
{
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
index 29a0d58f708..b0a6a54616c 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
@@ -210,11 +210,10 @@ CommunicationKDP::GetSequenceMutex(std::unique_lock<std::recursive_mutex> &lock)
return (lock = std::unique_lock<std::recursive_mutex>(m_sequence_mutex, std::try_to_lock)).owns_lock();
}
-
bool
-CommunicationKDP::WaitForNotRunningPrivate (const TimeValue *timeout_ptr)
+CommunicationKDP::WaitForNotRunningPrivate(const std::chrono::microseconds &timeout)
{
- return m_is_running.WaitForValueEqualTo (false, timeout_ptr, NULL);
+ return m_is_running.WaitForValueEqualTo(false, timoeut, NULL);
}
size_t
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
index 89e55a561e7..fe77cbb9ae4 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
@@ -249,7 +249,7 @@ protected:
uint32_t timeout_usec);
bool
- WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr);
+ WaitForNotRunningPrivate(const std::chrono::microseconds &timeout);
void
MakeRequestPacketHeader (CommandType request_type,
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
index 898677df616..7782f42d916 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
@@ -941,7 +941,7 @@ ProcessKDP::AsyncThread (void *arg)
if (log)
log->Printf ("ProcessKDP::AsyncThread (pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp)...",
pid);
- if (listener_sp->WaitForEvent (NULL, event_sp))
+ if (listener_sp->WaitForEvent(stsd::chrono::micrseconds(0), event_sp))
{
uint32_t event_type = event_sp->GetType();
if (log)
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index f164b1411be..9d6b976fb3b 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -152,23 +152,22 @@ GDBRemoteCommunication::History::Dump (Log *log) const
//----------------------------------------------------------------------
// GDBRemoteCommunication constructor
//----------------------------------------------------------------------
-GDBRemoteCommunication::GDBRemoteCommunication(const char *comm_name,
- const char *listener_name) :
- Communication(comm_name),
+GDBRemoteCommunication::GDBRemoteCommunication(const char *comm_name, const char *listener_name)
+ : Communication(comm_name),
#ifdef LLDB_CONFIGURATION_DEBUG
- m_packet_timeout (1000),
+ m_packet_timeout(1000),
#else
- m_packet_timeout (1),
+ m_packet_timeout(1),
#endif
- m_echo_number(0),
- m_supports_qEcho (eLazyBoolCalculate),
- m_sequence_mutex (Mutex::eMutexTypeRecursive),
- m_public_is_running (false),
- m_private_is_running (false),
- m_history (512),
- m_send_acks (true),
- m_compression_type (CompressionType::None),
- m_listen_url ()
+ m_echo_number(0),
+ m_supports_qEcho(eLazyBoolCalculate),
+ m_sequence_mutex(),
+ m_public_is_running(false),
+ m_private_is_running(false),
+ m_history(512),
+ m_send_acks(true),
+ m_compression_type(CompressionType::None),
+ m_listen_url()
{
}
@@ -229,7 +228,7 @@ GDBRemoteCommunication::SendNack ()
GDBRemoteCommunication::PacketResult
GDBRemoteCommunication::SendPacket (const char *payload, size_t payload_length)
{
- Mutex::Locker locker(m_sequence_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_sequence_mutex);
return SendPacketNoLock (payload, payload_length);
}
@@ -323,20 +322,19 @@ GDBRemoteCommunication::GetAck ()
}
bool
-GDBRemoteCommunication::GetSequenceMutex (Mutex::Locker& locker, const char *failure_message)
+GDBRemoteCommunication::GetSequenceMutex(std::unique_lock<std::recursive_mutex> &lock, const char *failure_message)
{
if (IsRunning())
- return locker.TryLock (m_sequence_mutex, failure_message);
+ return (lock = std::unique_lock<std::recursive_mutex>(m_sequence_mutex, std::try_to_lock)).owns_lock();
- locker.Lock (m_sequence_mutex);
+ lock = std::unique_lock<std::recursive_mutex>(m_sequence_mutex);
return true;
}
-
bool
-GDBRemoteCommunication::WaitForNotRunningPrivate (const TimeValue *timeout_ptr)
+GDBRemoteCommunication::WaitForNotRunningPrivate(const std::chrono::microseconds &timeout)
{
- return m_private_is_running.WaitForValueEqualTo (false, timeout_ptr, NULL);
+ return m_private_is_running.WaitForValueEqualTo(false, timeout, NULL);
}
GDBRemoteCommunication::PacketResult
@@ -356,20 +354,22 @@ GDBRemoteCommunication::ReadPacket (StringExtractorGDBRemote &response, uint32_t
GDBRemoteCommunication::PacketResult
GDBRemoteCommunication::PopPacketFromQueue (StringExtractorGDBRemote &response, uint32_t timeout_usec)
{
- // Calculate absolute timeout value
- TimeValue timeout = TimeValue::Now();
- timeout.OffsetWithMicroSeconds(timeout_usec);
+ auto until = std::chrono::system_clock::now() + std::chrono::microseconds(timeout_usec);
- do
+ while (true)
{
// scope for the mutex
{
// lock down the packet queue
- Mutex::Locker locker(m_packet_queue_mutex);
+ std::unique_lock<std::mutex> lock(m_packet_queue_mutex);
// Wait on condition variable.
if (m_packet_queue.size() == 0)
- m_condition_queue_not_empty.Wait(m_packet_queue_mutex, &timeout);
+ {
+ std::cv_status result = m_condition_queue_not_empty.wait_until(lock, until);
+ if (result == std::cv_status::timeout)
+ break;
+ }
if (m_packet_queue.size() > 0)
{
@@ -389,7 +389,7 @@ GDBRemoteCommunication::PopPacketFromQueue (StringExtractorGDBRemote &response,
return PacketResult::ErrorDisconnected;
// Loop while not timed out
- } while (TimeValue::Now() < timeout);
+ }
return PacketResult::ErrorReplyTimeout;
}
@@ -1479,12 +1479,11 @@ void GDBRemoteCommunication::AppendBytesToCache (const uint8_t * bytes, size_t l
// scope for the mutex
{
// lock down the packet queue
- Mutex::Locker locker(m_packet_queue_mutex);
+ std::lock_guard<std::mutex> guard(m_packet_queue_mutex);
// push a new packet into the queue
m_packet_queue.push(packet);
// Signal condition variable that we have a packet
- m_condition_queue_not_empty.Signal();
-
+ m_condition_queue_not_empty.notify_one();
}
}
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index 2a01bcec260..23568cd4b36 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -12,6 +12,8 @@
// C Includes
// C++ Includes
+#include <condition_variable>
+#include <mutex>
#include <string>
#include <queue>
#include <vector>
@@ -22,7 +24,6 @@
#include "lldb/Core/Communication.h"
#include "lldb/Core/Listener.h"
#include "lldb/Host/HostThread.h"
-#include "lldb/Host/Mutex.h"
#include "lldb/Host/Predicate.h"
#include "lldb/Host/TimeValue.h"
#include "lldb/Interpreter/Args.h"
@@ -114,7 +115,7 @@ public:
size_t payload_length);
bool
- GetSequenceMutex(Mutex::Locker& locker, const char *failure_message = nullptr);
+ GetSequenceMutex(std::unique_lock<std::recursive_mutex> &lock, const char *failure_message = nullptr);
PacketType
CheckForPacket (const uint8_t *src,
@@ -285,9 +286,9 @@ protected:
uint32_t m_echo_number;
LazyBool m_supports_qEcho;
#ifdef ENABLE_MUTEX_ERROR_CHECKING
- TrackingMutex m_sequence_mutex;
+#error TrackingMutex is no longer supported
#else
- Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time
+ std::recursive_mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time
#endif
Predicate<bool> m_public_is_running;
Predicate<bool> m_private_is_running;
@@ -320,7 +321,7 @@ protected:
bool sync_on_timeout);
bool
- WaitForNotRunningPrivate (const TimeValue *timeout_ptr);
+ WaitForNotRunningPrivate(const std::chrono::microseconds &timeout);
bool
CompressionIsEnabled ()
@@ -364,8 +365,8 @@ protected:
private:
std::queue<StringExtractorGDBRemote> m_packet_queue; // The packet queue
- lldb_private::Mutex m_packet_queue_mutex; // Mutex for accessing queue
- Condition m_condition_queue_not_empty; // Condition variable to wait for packets
+ std::mutex m_packet_queue_mutex; // Mutex for accessing queue
+ std::condition_variable m_condition_queue_not_empty; // Condition variable to wait for packets
HostThread m_listen_thread;
std::string m_listen_url;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index ba018be812b..a9ecd939614 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -720,9 +720,10 @@ GDBRemoteCommunicationClient::SendPacketsAndConcatenateResponses
std::string &response_string
)
{
- Mutex::Locker locker;
- if (!GetSequenceMutex(locker,
- "ProcessGDBRemote::SendPacketsAndConcatenateResponses() failed due to not getting the sequence mutex"))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (!GetSequenceMutex(
+ lock,
+ "ProcessGDBRemote::SendPacketsAndConcatenateResponses() failed due to not getting the sequence mutex"))
{
Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS));
if (log)
@@ -821,7 +822,7 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
)
{
PacketResult packet_result = PacketResult::ErrorSendFailed;
- Mutex::Locker locker;
+ std::unique_lock<std::recursive_mutex> lock;
Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
// In order to stop async notifications from being processed in the middle of the
@@ -829,7 +830,7 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
static ListenerSP hijack_listener_sp(Listener::MakeListener("lldb.NotifyHijacker"));
HijackBroadcaster(hijack_listener_sp, eBroadcastBitGdbReadThreadGotNotify);
- if (GetSequenceMutex (locker))
+ if (GetSequenceMutex(lock))
{
packet_result = SendPacketAndWaitForResponseNoLock (payload, payload_length, response);
}
@@ -848,19 +849,22 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
log->Printf ("async: async packet = %s", m_async_packet.c_str());
bool timed_out = false;
- if (SendInterrupt(locker, 2, timed_out))
+ if (SendInterrupt(lock, 2, timed_out))
{
if (m_interrupt_sent)
{
m_interrupt_sent = false;
- TimeValue timeout_time;
- timeout_time = TimeValue::Now();
- timeout_time.OffsetWithSeconds (m_packet_timeout);
+
+ std::chrono::time_point<std::chrono::system_clock> until;
+ until = std::chrono::system_clock::now() + std::chrono::seconds(m_packet_timeout);
if (log)
log->Printf ("async: sent interrupt");
- if (m_async_packet_predicate.WaitForValueEqualTo (false, &timeout_time, &timed_out))
+ if (m_async_packet_predicate.WaitForValueEqualTo(
+ false, std::chrono::duration_cast<std::chrono::microseconds>(
+ until - std::chrono::system_clock::now()),
+ &timed_out))
{
if (log)
log->Printf ("async: got response");
@@ -876,7 +880,10 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
}
// Make sure we wait until the continue packet has been sent again...
- if (m_private_is_running.WaitForValueEqualTo (true, &timeout_time, &timed_out))
+ if (m_private_is_running.WaitForValueEqualTo(
+ true, std::chrono::duration_cast<std::chrono::microseconds>(
+ until - std::chrono::system_clock::now()),
+ &timed_out))
{
if (log)
{
@@ -1045,7 +1052,7 @@ GDBRemoteCommunicationClient::SendvContPacket
log->Printf("GDBRemoteCommunicationClient::%s ()", __FUNCTION__);
// we want to lock down packet sending while we continue
- Mutex::Locker locker(m_sequence_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_sequence_mutex);
// here we broadcast this before we even send the packet!!
// this signals doContinue() to exit
@@ -1094,7 +1101,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
if (log)
log->Printf ("GDBRemoteCommunicationClient::%s ()", __FUNCTION__);
- Mutex::Locker locker(m_sequence_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_sequence_mutex);
StateType state = eStateRunning;
m_public_is_running.SetValue (true, eBroadcastNever);
@@ -1394,8 +1401,8 @@ GDBRemoteCommunicationClient::SendAsyncSignal (int signo)
std::lock_guard<std::recursive_mutex> guard(m_async_mutex);
m_async_signal = signo;
bool timed_out = false;
- Mutex::Locker locker;
- if (SendInterrupt (locker, 1, timed_out))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (SendInterrupt(lock, 1, timed_out))
return true;
m_async_signal = -1;
return false;
@@ -1412,12 +1419,8 @@ GDBRemoteCommunicationClient::SendAsyncSignal (int signo)
// (gdb remote protocol requires this), and do what we need to do, then resume.
bool
-GDBRemoteCommunicationClient::SendInterrupt
-(
- Mutex::Locker& locker,
- uint32_t seconds_to_wait_for_stop,
- bool &timed_out
-)
+GDBRemoteCommunicationClient::SendInterrupt(std::unique_lock<std::recursive_mutex> &lock,
+ uint32_t seconds_to_wait_for_stop, bool &timed_out)
{
timed_out = false;
Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS));
@@ -1425,7 +1428,7 @@ GDBRemoteCommunicationClient::SendInterrupt
if (IsRunning())
{
// Only send an interrupt if our debugserver is running...
- if (GetSequenceMutex (locker))
+ if (GetSequenceMutex(lock))
{
if (log)
log->Printf ("SendInterrupt () - got sequence mutex without having to interrupt");
@@ -1444,13 +1447,8 @@ GDBRemoteCommunicationClient::SendInterrupt
m_interrupt_sent = true;
if (seconds_to_wait_for_stop)
{
- TimeValue timeout;
- if (seconds_to_wait_for_stop)
- {
- timeout = TimeValue::Now();
- timeout.OffsetWithSeconds (seconds_to_wait_for_stop);
- }
- if (m_private_is_running.WaitForValueEqualTo (false, &timeout, &timed_out))
+ if (m_private_is_running.WaitForValueEqualTo(false, std::chrono::seconds(seconds_to_wait_for_stop),
+ &timed_out))
{
if (log)
log->PutCString ("SendInterrupt () - sent interrupt, private state stopped");
@@ -3653,10 +3651,10 @@ size_t
GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
bool &sequence_mutex_unavailable)
{
- Mutex::Locker locker;
+ std::unique_lock<std::recursive_mutex> lock;
thread_ids.clear();
-
- if (GetSequenceMutex (locker, "ProcessGDBRemote::UpdateThreadList() failed due to not getting the sequence mutex"))
+
+ if (GetSequenceMutex(lock, "ProcessGDBRemote::UpdateThreadList() failed due to not getting the sequence mutex"))
{
sequence_mutex_unavailable = false;
StringExtractorGDBRemote response;
@@ -4203,8 +4201,8 @@ GDBRemoteCommunicationClient::AvoidGPackets (ProcessGDBRemote *process)
bool
GDBRemoteCommunicationClient::ReadRegister(lldb::tid_t tid, uint32_t reg, StringExtractorGDBRemote &response)
{
- Mutex::Locker locker;
- if (GetSequenceMutex (locker, "Didn't get sequence mutex for p packet."))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (GetSequenceMutex(lock, "Didn't get sequence mutex for p packet."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();
@@ -4228,8 +4226,8 @@ GDBRemoteCommunicationClient::ReadRegister(lldb::tid_t tid, uint32_t reg, String
bool
GDBRemoteCommunicationClient::ReadAllRegisters (lldb::tid_t tid, StringExtractorGDBRemote &response)
{
- Mutex::Locker locker;
- if (GetSequenceMutex (locker, "Didn't get sequence mutex for g packet."))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (GetSequenceMutex(lock, "Didn't get sequence mutex for g packet."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();
@@ -4256,8 +4254,8 @@ GDBRemoteCommunicationClient::SaveRegisterState (lldb::tid_t tid, uint32_t &save
return false;
m_supports_QSaveRegisterState = eLazyBoolYes;
- Mutex::Locker locker;
- if (GetSequenceMutex (locker, "Didn't get sequence mutex for QSaveRegisterState."))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (GetSequenceMutex(lock, "Didn't get sequence mutex for QSaveRegisterState."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();
if (thread_suffix_supported || SetCurrentThread(tid))
@@ -4298,9 +4296,9 @@ GDBRemoteCommunicationClient::RestoreRegisterState (lldb::tid_t tid, uint32_t sa
// order to be useful
if (m_supports_QSaveRegisterState == eLazyBoolNo)
return false;
-
- Mutex::Locker locker;
- if (GetSequenceMutex (locker, "Didn't get sequence mutex for QRestoreRegisterState."))
+
+ std::unique_lock<std::recursive_mutex> lock;
+ if (GetSequenceMutex(lock, "Didn't get sequence mutex for QRestoreRegisterState."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();
if (thread_suffix_supported || SetCurrentThread(tid))
@@ -4530,8 +4528,10 @@ GDBRemoteCommunicationClient::ServeSymbolLookups(lldb_private::Process *process)
if (m_supports_qSymbol && m_qSymbol_requests_done == false)
{
- Mutex::Locker locker;
- if (GetSequenceMutex(locker, "GDBRemoteCommunicationClient::ServeSymbolLookups() failed due to not getting the sequence mutex"))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (GetSequenceMutex(
+ lock,
+ "GDBRemoteCommunicationClient::ServeSymbolLookups() failed due to not getting the sequence mutex"))
{
StreamString packet;
packet.PutCString ("qSymbol::");
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
index 7088bc0287c..a603fcf4982 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -105,9 +105,7 @@ public:
SendAsyncSignal (int signo);
bool
- SendInterrupt (Mutex::Locker &locker,
- uint32_t seconds_to_wait_for_stop,
- bool &timed_out);
+ SendInterrupt(std::unique_lock<std::recursive_mutex> &lock, uint32_t seconds_to_wait_for_stop, bool &timed_out);
lldb::pid_t
GetCurrentProcessID (bool allow_lazy = true);
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index e5b347c9f72..628efd98c74 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -401,8 +401,8 @@ GDBRemoteRegisterContext::WriteRegisterBytes (const RegisterInfo *reg_info, Data
reg_info->byte_size, // dst length
m_reg_data.GetByteOrder())) // dst byte order
{
- Mutex::Locker locker;
- if (gdb_comm.GetSequenceMutex (locker, "Didn't get sequence mutex for write register."))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (gdb_comm.GetSequenceMutex(lock, "Didn't get sequence mutex for write register."))
{
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
ProcessSP process_sp (m_thread.GetProcess());
@@ -570,8 +570,8 @@ GDBRemoteRegisterContext::ReadAllRegisterValues (lldb::DataBufferSP &data_sp)
const bool use_g_packet = gdb_comm.AvoidGPackets ((ProcessGDBRemote *)process) == false;
- Mutex::Locker locker;
- if (gdb_comm.GetSequenceMutex (locker, "Didn't get sequence mutex for read all registers."))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (gdb_comm.GetSequenceMutex(lock, "Didn't get sequence mutex for read all registers."))
{
SyncThreadState(process);
@@ -679,8 +679,8 @@ GDBRemoteRegisterContext::WriteAllRegisterValues (const lldb::DataBufferSP &data
const bool use_g_packet = gdb_comm.AvoidGPackets ((ProcessGDBRemote *)process) == false;
StringExtractorGDBRemote response;
- Mutex::Locker locker;
- if (gdb_comm.GetSequenceMutex (locker, "Didn't get sequence mutex for write all registers."))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (gdb_comm.GetSequenceMutex(lock, "Didn't get sequence mutex for write all registers."))
{
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
ProcessSP process_sp (m_thread.GetProcess());
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 1cea670bd72..a14c8254041 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1590,9 +1590,6 @@ ProcessGDBRemote::DoResume ()
else
{
EventSP event_sp;
- TimeValue timeout;
- timeout = TimeValue::Now();
- timeout.OffsetWithSeconds (5);
if (!m_async_thread.IsJoinable())
{
error.SetErrorString ("Trying to resume but the async thread is dead.");
@@ -1603,7 +1600,7 @@ ProcessGDBRemote::DoResume ()
m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (continue_packet.GetData(), continue_packet.GetSize()));
- if (listener_sp->WaitForEvent (&timeout, event_sp) == false)
+ if (listener_sp->WaitForEvent(std::chrono::seconds(5), event_sp) == false)
{
error.SetErrorString("Resume timed out.");
if (log)
@@ -2717,7 +2714,7 @@ ProcessGDBRemote::DoHalt (bool &caused_stop)
Error error;
bool timed_out = false;
- Mutex::Locker locker;
+ std::unique_lock<std::recursive_mutex> lock;
if (m_public_state.GetValue() == eStateAttaching)
{
@@ -2727,7 +2724,7 @@ ProcessGDBRemote::DoHalt (bool &caused_stop)
}
else
{
- if (!m_gdb_comm.SendInterrupt (locker, 2, timed_out))
+ if (!m_gdb_comm.SendInterrupt(lock, 2, timed_out))
{
if (timed_out)
error.SetErrorString("timed out sending interrupt packet");
@@ -3860,7 +3857,7 @@ ProcessGDBRemote::AsyncThread (void *arg)
{
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID());
- if (process->m_async_listener_sp->WaitForEvent (NULL, event_sp))
+ if (process->m_async_listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp))
{
const uint32_t event_type = event_sp->GetType();
if (event_sp->BroadcasterIs (&process->m_async_broadcaster))
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index b5a37941768..a46ca6b4f3e 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -978,10 +978,8 @@ Process::SyncIOHandler (uint32_t iohandler_id, uint64_t timeout_msec)
if (!m_process_input_reader)
return;
- TimeValue timeout = TimeValue::Now();
- timeout.OffsetWithMicroSeconds(timeout_msec*1000);
uint32_t new_iohandler_id = 0;
- m_iohandler_sync.WaitForValueNotEqualTo(iohandler_id, new_iohandler_id, &timeout);
+ m_iohandler_sync.WaitForValueNotEqualTo(iohandler_id, new_iohandler_id, std::chrono::milliseconds(timeout_msec));
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
if (log)
@@ -989,12 +987,8 @@ Process::SyncIOHandler (uint32_t iohandler_id, uint64_t timeout_msec)
}
StateType
-Process::WaitForProcessToStop (const TimeValue *timeout,
- EventSP *event_sp_ptr,
- bool wait_always,
- ListenerSP hijack_listener_sp,
- Stream *stream,
- bool use_run_lock)
+Process::WaitForProcessToStop(const std::chrono::microseconds &timeout, EventSP *event_sp_ptr, bool wait_always,
+ ListenerSP hijack_listener_sp, Stream *stream, bool use_run_lock)
{
// We can't just wait for a "stopped" event, because the stopped event may have restarted the target.
// We have to actually check each event, and in the case of a stopped event check the restarted flag
@@ -1009,8 +1003,7 @@ Process::WaitForProcessToStop (const TimeValue *timeout,
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
if (log)
- log->Printf ("Process::%s (timeout = %p)", __FUNCTION__,
- static_cast<const void*>(timeout));
+ log->Printf("Process::%s (timeout = %llu)", __FUNCTION__, static_cast<unsigned long long>(timeout.count()));
if (!wait_always &&
StateIsStoppedState(state, true) &&
@@ -1029,7 +1022,7 @@ Process::WaitForProcessToStop (const TimeValue *timeout,
while (state != eStateInvalid)
{
EventSP event_sp;
- state = WaitForStateChangedEvents (timeout, event_sp, hijack_listener_sp);
+ state = WaitForStateChangedEvents(std::chrono::milliseconds(0), event_sp, hijack_listener_sp);
if (event_sp_ptr && event_sp)
*event_sp_ptr = event_sp;
@@ -1265,8 +1258,7 @@ Process::HandleProcessStateChangedEvent (const EventSP &event_sp,
}
StateType
-Process::WaitForState(const TimeValue *timeout,
- const StateType *match_states,
+Process::WaitForState(const std::chrono::microseconds &timeout, const StateType *match_states,
const uint32_t num_match_states)
{
EventSP event_sp;
@@ -1307,13 +1299,14 @@ Process::RestoreProcessEvents ()
}
StateType
-Process::WaitForStateChangedEvents (const TimeValue *timeout, EventSP &event_sp, ListenerSP hijack_listener_sp)
+Process::WaitForStateChangedEvents(const std::chrono::microseconds &timeout, EventSP &event_sp,
+ ListenerSP hijack_listener_sp)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
if (log)
- log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__,
- static_cast<const void*>(timeout));
+ log->Printf("Process::%s (timeout = %llu, event_sp)...", __FUNCTION__,
+ static_cast<unsigned long long>(timeout.count()));
ListenerSP listener_sp = hijack_listener_sp;
if (!listener_sp)
@@ -1332,9 +1325,8 @@ Process::WaitForStateChangedEvents (const TimeValue *timeout, EventSP &event_sp,
}
if (log)
- log->Printf ("Process::%s (timeout = %p, event_sp) => %s",
- __FUNCTION__, static_cast<const void*>(timeout),
- StateAsCString(state));
+ log->Printf("Process::%s (timeout = %llu, event_sp) => %s", __FUNCTION__,
+ static_cast<unsigned long long>(timeout.count()), StateAsCString(state));
return state;
}
@@ -1367,13 +1359,13 @@ Process::PeekAtStateChangedEvents ()
}
StateType
-Process::WaitForStateChangedEventsPrivate (const TimeValue *timeout, EventSP &event_sp)
+Process::WaitForStateChangedEventsPrivate(const std::chrono::microseconds &timeout, EventSP &event_sp)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
if (log)
- log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__,
- static_cast<const void*>(timeout));
+ log->Printf("Process::%s (timeout = %llu, event_sp)...", __FUNCTION__,
+ static_cast<unsigned long long>(timeout.count()));
StateType state = eStateInvalid;
if (m_private_state_listener_sp->WaitForEventForBroadcasterWithType (timeout,
@@ -1387,20 +1379,20 @@ Process::WaitForStateChangedEventsPrivate (const TimeValue *timeout, EventSP &ev
// to the command-line, and that could disable the log, which would render the
// log we got above invalid.
if (log)
- log->Printf ("Process::%s (timeout = %p, event_sp) => %s",
- __FUNCTION__, static_cast<const void *>(timeout),
- state == eStateInvalid ? "TIMEOUT" : StateAsCString(state));
+ log->Printf("Process::%s (timeout = %llu, event_sp) => %s", __FUNCTION__,
+ static_cast<unsigned long long>(timeout.count()),
+ state == eStateInvalid ? "TIMEOUT" : StateAsCString(state));
return state;
}
bool
-Process::WaitForEventsPrivate (const TimeValue *timeout, EventSP &event_sp, bool control_only)
+Process::WaitForEventsPrivate(const std::chrono::microseconds &timeout, EventSP &event_sp, bool control_only)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
if (log)
- log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__,
- static_cast<const void*>(timeout));
+ log->Printf("Process::%s (timeout = %llu, event_sp)...", __FUNCTION__,
+ static_cast<unsigned long long>(timeout.count()));
if (control_only)
return m_private_state_listener_sp->WaitForEventForBroadcaster(timeout, &m_private_state_control_broadcaster, event_sp);
@@ -1751,7 +1743,7 @@ Process::ResumeSynchronous (Stream *stream)
Error error = PrivateResume();
if (error.Success())
{
- StateType state = WaitForProcessToStop (NULL, NULL, true, listener_sp, stream);
+ StateType state = WaitForProcessToStop(std::chrono::microseconds(0), NULL, true, listener_sp, stream);
const bool must_be_alive = false; // eStateExited is ok, so this must be false
if (!StateIsStoppedState(state, must_be_alive))
error.SetErrorStringWithFormat("process not in stopped state after synchronous resume: %s", StateAsCString(state));
@@ -2891,7 +2883,7 @@ Process::DisableWatchpoint (Watchpoint *watchpoint, bool notify)
}
StateType
-Process::WaitForProcessStopPrivate (const TimeValue *timeout, EventSP &event_sp)
+Process::WaitForProcessStopPrivate(const std::chrono::microseconds &timeout, EventSP &event_sp)
{
StateType state;
// Now wait for the process to launch and return control to us, and then
@@ -2987,10 +2979,7 @@ Process::Launch (ProcessLaunchInfo &launch_info)
else
{
EventSP event_sp;
- TimeValue timeout_time;
- timeout_time = TimeValue::Now();
- timeout_time.OffsetWithSeconds(10);
- StateType state = WaitForProcessStopPrivate(&timeout_time, event_sp);
+ StateType state = WaitForProcessStopPrivate(std::chrono::seconds(10), event_sp);
if (state == eStateInvalid || !event_sp)
{
@@ -3083,7 +3072,7 @@ Process::LoadCore ()
// Wait indefinitely for a stopped event since we just posted one above...
lldb::EventSP event_sp;
- listener_sp->WaitForEvent (nullptr, event_sp);
+ listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp);
StateType state = ProcessEventData::GetStateFromEvent(event_sp.get());
if (!StateIsStoppedState (state, false))
@@ -3502,8 +3491,8 @@ Process::ConnectRemote (Stream *strm, const char *remote_url)
if (GetID() != LLDB_INVALID_PROCESS_ID)
{
EventSP event_sp;
- StateType state = WaitForProcessStopPrivate(nullptr, event_sp);
-
+ StateType state = WaitForProcessStopPrivate(std::chrono::microseconds(0), event_sp);
+
if (state == eStateStopped || state == eStateCrashed)
{
// If we attached and actually have a process on the other end, then
@@ -3612,11 +3601,8 @@ Process::Halt (bool clear_thread_plans, bool use_run_lock)
}
// Wait for 10 second for the process to stop.
- TimeValue timeout_time;
- timeout_time = TimeValue::Now();
- timeout_time.OffsetWithSeconds(10);
- StateType state = WaitForProcessToStop(&timeout_time, &event_sp, true, halt_listener_sp,
- nullptr, use_run_lock);
+ StateType state =
+ WaitForProcessToStop(std::chrono::seconds(10), &event_sp, true, halt_listener_sp, nullptr, use_run_lock);
RestoreProcessEvents();
if (state == eStateInvalid || ! event_sp)
@@ -3649,10 +3635,7 @@ Process::StopForDestroyOrDetach(lldb::EventSP &exit_event_sp)
SendAsyncInterrupt();
// Consume the interrupt event.
- TimeValue timeout (TimeValue::Now());
- timeout.OffsetWithSeconds(10);
-
- StateType state = WaitForProcessToStop (&timeout, &exit_event_sp, true, listener_sp);
+ StateType state = WaitForProcessToStop(std::chrono::seconds(10), &exit_event_sp, true, listener_sp);
RestoreProcessEvents();
@@ -4125,12 +4108,9 @@ Process::ControlPrivateStateThread (uint32_t signal)
while (!receipt_received)
{
bool timed_out = false;
- TimeValue timeout_time;
- timeout_time = TimeValue::Now();
- timeout_time.OffsetWithSeconds(2);
// Check for a receipt for 2 seconds and then check if the private state
// thread is still around.
- receipt_received = event_receipt_sp->WaitForEventReceived (&timeout_time, &timed_out);
+ receipt_received = event_receipt_sp->WaitForEventReceived(std::chrono::seconds(2), &timed_out);
if (!receipt_received)
{
// Check if the private state thread is still around. If it isn't then we are done waiting
@@ -4326,7 +4306,7 @@ Process::RunPrivateStateThread (bool is_secondary_thread)
while (!exit_now)
{
EventSP event_sp;
- WaitForEventsPrivate(nullptr, event_sp, control_only);
+ WaitForEventsPrivate(std::chrono::microseconds(0), event_sp, control_only);
if (event_sp->BroadcasterIs(&m_private_state_control_broadcaster))
{
if (log)
@@ -5351,9 +5331,6 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_pla
lldb::EventSP event_sp;
lldb::StateType stop_state = lldb::eStateInvalid;
- TimeValue* timeout_ptr = nullptr;
- TimeValue real_timeout;
-
bool before_first_timeout = true; // This is set to false the first time that we have to halt the target.
bool do_resume = true;
bool handle_running_event = true;
@@ -5454,6 +5431,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_pla
#endif
TimeValue one_thread_timeout;
TimeValue final_timeout;
+ std::chrono::microseconds timeout = std::chrono::microseconds(0);
while (true)
{
@@ -5484,10 +5462,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_pla
}
}
- TimeValue resume_timeout = TimeValue::Now();
- resume_timeout.OffsetWithMicroSeconds(500000);
-
- got_event = listener_sp->WaitForEvent(&resume_timeout, event_sp);
+ got_event = listener_sp->WaitForEvent(std::chrono::microseconds(500000), event_sp);
if (!got_event)
{
if (log)
@@ -5552,33 +5527,16 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_pla
if (before_first_timeout)
{
if (options.GetTryAllThreads())
- {
- one_thread_timeout = TimeValue::Now();
- one_thread_timeout.OffsetWithMicroSeconds(one_thread_timeout_usec);
- timeout_ptr = &one_thread_timeout;
- }
+ timeout = std::chrono::microseconds(one_thread_timeout_usec);
else
- {
- if (timeout_usec == 0)
- timeout_ptr = nullptr;
- else
- {
- final_timeout = TimeValue::Now();
- final_timeout.OffsetWithMicroSeconds (timeout_usec);
- timeout_ptr = &final_timeout;
- }
- }
+ timeout = std::chrono::microseconds(timeout_usec);
}
else
{
if (timeout_usec == 0)
- timeout_ptr = nullptr;
+ timeout = std::chrono::microseconds(0);
else
- {
- final_timeout = TimeValue::Now();
- final_timeout.OffsetWithMicroSeconds (all_threads_timeout_usec);
- timeout_ptr = &final_timeout;
- }
+ timeout = std::chrono::microseconds(all_threads_timeout_usec);
}
do_resume = true;
@@ -5589,11 +5547,15 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_pla
if (log)
{
- if (timeout_ptr)
+ if (timeout.count())
{
- log->Printf ("Process::RunThreadPlan(): about to wait - now is %" PRIu64 " - endpoint is %" PRIu64,
- TimeValue::Now().GetAsMicroSecondsSinceJan1_1970(),
- timeout_ptr->GetAsMicroSecondsSinceJan1_1970());
+ log->Printf(
+ "Process::RunThreadPlan(): about to wait - now is %llu - endpoint is %llu",
+ static_cast<unsigned long long>(std::chrono::system_clock::now().time_since_epoch().count()),
+ static_cast<unsigned long long>(
+ std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds>(timeout)
+ .time_since_epoch()
+ .count()));
}
else
{
@@ -5611,7 +5573,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_pla
}
else
#endif
- got_event = listener_sp->WaitForEvent (timeout_ptr, event_sp);
+ got_event = listener_sp->WaitForEvent(timeout, event_sp);
if (got_event)
{
@@ -5810,10 +5772,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_pla
if (log)
log->PutCString ("Process::RunThreadPlan(): Halt succeeded.");
- real_timeout = TimeValue::Now();
- real_timeout.OffsetWithMicroSeconds(500000);
-
- got_event = listener_sp->WaitForEvent(&real_timeout, event_sp);
+ got_event = listener_sp->WaitForEvent(std::chrono::microseconds(500000), event_sp);
if (got_event)
{
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 9ef56f01c65..f53e66a7ea0 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -3103,8 +3103,9 @@ Target::Launch (ProcessLaunchInfo &launch_info, Stream *stream)
m_process_sp->HijackProcessEvents(hijack_listener_sp);
}
- StateType state = m_process_sp->WaitForProcessToStop(nullptr, nullptr, false, hijack_listener_sp, nullptr);
-
+ StateType state = m_process_sp->WaitForProcessToStop(std::chrono::microseconds(0), nullptr, false,
+ hijack_listener_sp, nullptr);
+
if (state == eStateStopped)
{
if (!launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
@@ -3114,7 +3115,8 @@ Target::Launch (ProcessLaunchInfo &launch_info, Stream *stream)
error = m_process_sp->PrivateResume();
if (error.Success())
{
- state = m_process_sp->WaitForProcessToStop(nullptr, nullptr, true, hijack_listener_sp, stream);
+ state = m_process_sp->WaitForProcessToStop(std::chrono::microseconds(0), nullptr, true,
+ hijack_listener_sp, stream);
const bool must_be_alive = false; // eStateExited is ok, so this must be false
if (!StateIsStoppedState(state, must_be_alive))
{
@@ -3243,7 +3245,8 @@ Target::Attach (ProcessAttachInfo &attach_info, Stream *stream)
}
else
{
- state = process_sp->WaitForProcessToStop (nullptr, nullptr, false, attach_info.GetHijackListener(), stream);
+ state = process_sp->WaitForProcessToStop(std::chrono::microseconds(0), nullptr, false,
+ attach_info.GetHijackListener(), stream);
process_sp->RestoreProcessEvents ();
if (state != eStateStopped)
OpenPOWER on IntegriCloud