Index: include/lldb/Core/Event.h =================================================================== --- include/lldb/Core/Event.h +++ include/lldb/Core/Event.h @@ -12,6 +12,7 @@ // C Includes // C++ Includes +#include #include #include @@ -141,7 +142,8 @@ } 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); } Index: include/lldb/Core/Listener.h =================================================================== --- include/lldb/Core/Listener.h +++ include/lldb/Core/Listener.h @@ -12,6 +12,7 @@ // C Includes // C++ Includes +#include #include #include #include @@ -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 @@ // 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 @@ typedef std::vector broadcaster_manager_collection; bool - FindNextEventInternal(Mutex::Locker& lock, + FindNextEventInternal(std::unique_lock &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 @@ 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 Index: include/lldb/Core/ThreadSafeDenseMap.h =================================================================== --- include/lldb/Core/ThreadSafeDenseMap.h +++ include/lldb/Core/ThreadSafeDenseMap.h @@ -12,46 +12,41 @@ // C Includes // C++ Includes +#include // Other libraries and framework includes #include "llvm/ADT/DenseMap.h" // Project includes -#include "lldb/Host/Mutex.h" namespace lldb_private { -template +template 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 @@ 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 @@ 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 Index: include/lldb/Core/ThreadSafeDenseSet.h =================================================================== --- include/lldb/Core/ThreadSafeDenseSet.h +++ include/lldb/Core/ThreadSafeDenseSet.h @@ -12,61 +12,56 @@ // C Includes // C++ Includes +#include // Other libraries and framework includes #include "llvm/ADT/DenseSet.h" // Project includes -#include "lldb/Host/Mutex.h" namespace lldb_private { - - template - class ThreadSafeDenseSet + +template +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() + { + std::lock_guard<_MutexType> guard(m_mutex); + m_set.clear(); + } + +protected: + LLVMSetType m_set; + _MutexType m_mutex; +}; + } // namespace lldb_private #endif // liblldb_ThreadSafeDenseSet_h_ Index: include/lldb/Host/Condition.h =================================================================== --- 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_ Index: include/lldb/Host/Editline.h =================================================================== --- include/lldb/Host/Editline.h +++ include/lldb/Host/Editline.h @@ -54,7 +54,6 @@ #include #include -#include "lldb/Host/Condition.h" #include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/FileSpec.h" #include "lldb/Host/Predicate.h" Index: include/lldb/Host/Mutex.h =================================================================== --- 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 -#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_ Index: include/lldb/Host/Predicate.h =================================================================== --- include/lldb/Host/Predicate.h +++ include/lldb/Host/Predicate.h @@ -15,11 +15,12 @@ #include // C++ Includes +#include +#include + // 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 @@ T GetValue () const { - Mutex::Locker locker(m_mutex); + std::lock_guard guard(m_mutex); T value = m_value; return value; } @@ -120,7 +121,7 @@ void SetValue (T value, PredicateBroadcastType broadcast_type) { - Mutex::Locker locker(m_mutex); + std::lock_guard 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 @@ void SetValueBits (T bits, PredicateBroadcastType broadcast_type) { - Mutex::Locker locker(m_mutex); + std::lock_guard 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 @@ void ResetValueBits (T bits, PredicateBroadcastType broadcast_type) { - Mutex::Locker locker(m_mutex); + std::lock_guard 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 @@ /// 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 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 @@ /// 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 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 @@ /// @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 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 @@ //------------------------------------------------------------------ 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 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 @@ /// @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 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 @@ // 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 @@ 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); Index: include/lldb/Host/ProcessRunLock.h =================================================================== --- include/lldb/Host/ProcessRunLock.h +++ 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. Index: include/lldb/Target/Process.h =================================================================== --- include/lldb/Target/Process.h +++ include/lldb/Target/Process.h @@ -16,6 +16,7 @@ #include // C++ Includes +#include #include #include #include @@ -2888,12 +2889,9 @@ // 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 @@ -2915,8 +2913,7 @@ 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 //-------------------------------------------------------------------------------------- @@ -3506,21 +3503,20 @@ 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); Index: source/API/SBListener.cpp =================================================================== --- source/API/SBListener.cpp +++ 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 @@ 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 @@ { 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 @@ { 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; Index: source/Core/Communication.cpp =================================================================== --- source/Core/Communication.cpp +++ source/Core/Communication.cpp @@ -156,18 +156,14 @@ 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 @@ // Wait for the synchronization event. EventSP event_sp; - listener_sp->WaitForEvent(nullptr, event_sp); + listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp); } void Index: source/Core/Debugger.cpp =================================================================== --- source/Core/Debugger.cpp +++ source/Core/Debugger.cpp @@ -1608,7 +1608,7 @@ 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 @@ // 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(); } Index: source/Core/Listener.cpp =================================================================== --- source/Core/Listener.cpp +++ 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 @@ } // 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 @@ Listener::Clear() { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); - std::lock_guard guard(m_broadcasters_mutex); + std::lock_guard 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 @@ } m_broadcasters.clear(); - Mutex::Locker event_locker(m_events_mutex); + std::lock_guard events_guard(m_events_mutex); m_events.clear(); size_t num_managers = m_broadcaster_managers.size(); @@ -96,7 +95,7 @@ // Scope for "locker" // Tell the broadcaster to add this object as a listener { - std::lock_guard guard(m_broadcasters_mutex); + std::lock_guard 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 @@ // Scope for "locker" // Tell the broadcaster to add this object as a listener { - std::lock_guard guard(m_broadcasters_mutex); + std::lock_guard 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 @@ { // Scope for "locker" { - std::lock_guard guard(m_broadcasters_mutex); + std::lock_guard broadcasters_guard(m_broadcasters_mutex); m_broadcasters.erase (broadcaster->GetBroadcasterImpl()); } // Remove the broadcaster from our set of broadcasters @@ -171,13 +170,13 @@ { // Scope for "broadcasters_locker" { - std::lock_guard guard(m_broadcasters_mutex); + std::lock_guard broadcasters_guard(m_broadcasters_mutex); m_broadcasters.erase (broadcaster->GetBroadcasterImpl()); } // Scope for "event_locker" { - Mutex::Locker event_locker(m_events_mutex); + std::lock_guard 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 @@ static_cast(this), m_name.c_str(), static_cast(event_sp.get())); - Mutex::Locker locker(m_events_mutex); + std::lock_guard 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 @@ }; 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 &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 @@ // 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 @@ Event * Listener::PeekAtNextEvent () { - Mutex::Locker lock(m_events_mutex); + std::unique_lock 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 @@ Event * Listener::PeekAtNextEventForBroadcaster (Broadcaster *broadcaster) { - Mutex::Locker lock(m_events_mutex); + std::unique_lock 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 @@ Event * Listener::PeekAtNextEventForBroadcasterWithType (Broadcaster *broadcaster, uint32_t event_type_mask) { - Mutex::Locker lock(m_events_mutex); + std::unique_lock 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 @@ 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 guard(m_events_mutex); + return FindNextEventInternal(guard, broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask, + event_sp, true); } bool @@ -395,20 +391,17 @@ } 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(this), static_cast(timeout), - m_name.c_str()); + log->Printf("%p Listener::WaitForEventsInternal (timeout = %llu us) for %s", static_cast(this), + static_cast(timeout.count()), m_name.c_str()); - Mutex::Locker lock(m_events_mutex); + std::unique_lock lock(m_events_mutex); while (true) { @@ -418,23 +411,26 @@ } 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(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(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(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(this), + m_name.c_str()); return false; } } @@ -444,24 +440,21 @@ } 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); } Index: source/Host/CMakeLists.txt =================================================================== --- source/Host/CMakeLists.txt +++ source/Host/CMakeLists.txt @@ -4,7 +4,6 @@ endmacro() add_host_subdirectory(common - common/Condition.cpp common/File.cpp common/FileCache.cpp common/FileSpec.cpp @@ -17,7 +16,6 @@ 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 @@ 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 @@ windows/HostProcessWindows.cpp windows/HostThreadWindows.cpp windows/LockFileWindows.cpp - windows/Mutex.cpp windows/PipeWindows.cpp windows/ProcessLauncherWindows.cpp windows/ProcessRunLock.cpp Index: source/Host/common/Condition.cpp =================================================================== --- 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 - -#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; -} Index: source/Host/common/Host.cpp =================================================================== --- source/Host/common/Host.cpp +++ source/Host/common/Host.cpp @@ -620,14 +620,8 @@ 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 @@ // 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 { Index: source/Host/common/Mutex.cpp =================================================================== --- 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 -#endif -#include -#include - -#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 -#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 -#endif - -#if ENABLE_MUTEX_ERROR_CHECKING -#include - -enum MutexAction -{ - eMutexActionInitialized, - eMutexActionDestroyed, - eMutexActionAssertInitialized -}; - -static bool -error_check_mutex (pthread_mutex_t *m, MutexAction action) -{ - typedef std::set 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 - - Index: source/Host/posix/ConnectionFileDescriptorPosix.cpp =================================================================== --- source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -877,11 +877,7 @@ 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; } Index: source/Host/windows/Condition.cpp =================================================================== --- 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 - -#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(malloc(sizeof(CONDITION_VARIABLE))); - InitializeConditionVariable(static_cast(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(m_condition)); - return 0; -} - -//---------------------------------------------------------------------- -// Unblocks one thread waiting for the condition variable -//---------------------------------------------------------------------- -int -Condition::Signal () -{ - WakeConditionVariable(static_cast(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(m_condition), static_cast(mutex.m_mutex), wait); - - if (timed_out != NULL) - { - if ((err == 0) && GetLastError() == ERROR_TIMEOUT) - *timed_out = true; - else - *timed_out = false; - } - - return err == 0; -} - Index: source/Host/windows/Mutex.cpp =================================================================== --- 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 -#include - -#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 -#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(malloc(sizeof(CRITICAL_SECTION))); - InitializeCriticalSection(static_cast(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(malloc(sizeof(CRITICAL_SECTION))); - InitializeCriticalSection(static_cast(m_mutex)); -} - -//---------------------------------------------------------------------- -// Destructor. -// -// Destroys the mutex owned by this object. -//---------------------------------------------------------------------- -Mutex::~Mutex() -{ - DeleteCriticalSection(static_cast(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(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(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(m_mutex)); - return 0; -} Index: source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h =================================================================== --- source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h +++ 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" Index: source/Plugins/Platform/Linux/PlatformLinux.cpp =================================================================== --- source/Plugins/Platform/Linux/PlatformLinux.cpp +++ source/Plugins/Platform/Linux/PlatformLinux.cpp @@ -699,7 +699,8 @@ // 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) { Index: source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h =================================================================== --- source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h +++ source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h @@ -249,7 +249,7 @@ uint32_t timeout_usec); bool - WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr); + WaitForNotRunningPrivate(const std::chrono::microseconds &timeout); void MakeRequestPacketHeader (CommandType request_type, Index: source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp =================================================================== --- source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp +++ source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp @@ -210,11 +210,10 @@ return (lock = std::unique_lock(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, timeout, NULL); } size_t Index: source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp =================================================================== --- source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp +++ source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp @@ -941,7 +941,7 @@ 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(std::chrono::microseconds(0), event_sp)) { uint32_t event_type = event_sp->GetType(); if (log) Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h @@ -12,6 +12,8 @@ // C Includes // C++ Includes +#include +#include #include #include #include @@ -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 @@ size_t payload_length); bool - GetSequenceMutex(Mutex::Locker& locker, const char *failure_message = nullptr); + GetSequenceMutex(std::unique_lock &lock, const char *failure_message = nullptr); PacketType CheckForPacket (const uint8_t *src, @@ -285,9 +286,9 @@ 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 m_public_is_running; Predicate m_private_is_running; @@ -320,7 +321,7 @@ bool sync_on_timeout); bool - WaitForNotRunningPrivate (const TimeValue *timeout_ptr); + WaitForNotRunningPrivate(const std::chrono::microseconds &timeout); bool CompressionIsEnabled () @@ -364,8 +365,8 @@ private: std::queue 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; Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -152,23 +152,22 @@ //---------------------------------------------------------------------- // 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::PacketResult GDBRemoteCommunication::SendPacket (const char *payload, size_t payload_length) { - Mutex::Locker locker(m_sequence_mutex); + std::lock_guard guard(m_sequence_mutex); return SendPacketNoLock (payload, payload_length); } @@ -323,20 +322,19 @@ } bool -GDBRemoteCommunication::GetSequenceMutex (Mutex::Locker& locker, const char *failure_message) +GDBRemoteCommunication::GetSequenceMutex(std::unique_lock &lock, const char *failure_message) { if (IsRunning()) - return locker.TryLock (m_sequence_mutex, failure_message); + return (lock = std::unique_lock(m_sequence_mutex, std::try_to_lock)).owns_lock(); - locker.Lock (m_sequence_mutex); + lock = std::unique_lock(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::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 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 @@ return PacketResult::ErrorDisconnected; // Loop while not timed out - } while (TimeValue::Now() < timeout); + } return PacketResult::ErrorReplyTimeout; } @@ -1479,12 +1479,11 @@ // scope for the mutex { // lock down the packet queue - Mutex::Locker locker(m_packet_queue_mutex); + std::lock_guard 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(); } } Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -105,9 +105,7 @@ SendAsyncSignal (int signo); bool - SendInterrupt (Mutex::Locker &locker, - uint32_t seconds_to_wait_for_stop, - bool &timed_out); + SendInterrupt(std::unique_lock &lock, uint32_t seconds_to_wait_for_stop, bool &timed_out); lldb::pid_t GetCurrentProcessID (bool allow_lazy = true); Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -701,9 +701,10 @@ std::string &response_string ) { - Mutex::Locker locker; - if (!GetSequenceMutex(locker, - "ProcessGDBRemote::SendPacketsAndConcatenateResponses() failed due to not getting the sequence mutex")) + std::unique_lock 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) @@ -802,7 +803,7 @@ ) { PacketResult packet_result = PacketResult::ErrorSendFailed; - Mutex::Locker locker; + std::unique_lock lock; Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); // In order to stop async notifications from being processed in the middle of the @@ -810,7 +811,7 @@ 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); } @@ -829,19 +830,22 @@ 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 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( + until - std::chrono::system_clock::now()), + &timed_out)) { if (log) log->Printf ("async: got response"); @@ -857,7 +861,10 @@ } // 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( + until - std::chrono::system_clock::now()), + &timed_out)) { if (log) { @@ -1026,7 +1033,7 @@ log->Printf("GDBRemoteCommunicationClient::%s ()", __FUNCTION__); // we want to lock down packet sending while we continue - Mutex::Locker locker(m_sequence_mutex); + std::lock_guard guard(m_sequence_mutex); // here we broadcast this before we even send the packet!! // this signals doContinue() to exit @@ -1075,7 +1082,7 @@ if (log) log->Printf ("GDBRemoteCommunicationClient::%s ()", __FUNCTION__); - Mutex::Locker locker(m_sequence_mutex); + std::lock_guard guard(m_sequence_mutex); StateType state = eStateRunning; m_public_is_running.SetValue (true, eBroadcastNever); @@ -1375,8 +1382,8 @@ std::lock_guard guard(m_async_mutex); m_async_signal = signo; bool timed_out = false; - Mutex::Locker locker; - if (SendInterrupt (locker, 1, timed_out)) + std::unique_lock lock; + if (SendInterrupt(lock, 1, timed_out)) return true; m_async_signal = -1; return false; @@ -1393,12 +1400,8 @@ // (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 &lock, + uint32_t seconds_to_wait_for_stop, bool &timed_out) { timed_out = false; Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)); @@ -1406,7 +1409,7 @@ 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"); @@ -1425,13 +1428,8 @@ 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"); @@ -3627,10 +3625,10 @@ GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector &thread_ids, bool &sequence_mutex_unavailable) { - Mutex::Locker locker; + std::unique_lock 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; @@ -4177,8 +4175,8 @@ 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 lock; + if (GetSequenceMutex(lock, "Didn't get sequence mutex for p packet.")) { const bool thread_suffix_supported = GetThreadSuffixSupported(); @@ -4202,8 +4200,8 @@ 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 lock; + if (GetSequenceMutex(lock, "Didn't get sequence mutex for g packet.")) { const bool thread_suffix_supported = GetThreadSuffixSupported(); @@ -4230,8 +4228,8 @@ return false; m_supports_QSaveRegisterState = eLazyBoolYes; - Mutex::Locker locker; - if (GetSequenceMutex (locker, "Didn't get sequence mutex for QSaveRegisterState.")) + std::unique_lock lock; + if (GetSequenceMutex(lock, "Didn't get sequence mutex for QSaveRegisterState.")) { const bool thread_suffix_supported = GetThreadSuffixSupported(); if (thread_suffix_supported || SetCurrentThread(tid)) @@ -4272,9 +4270,9 @@ // 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 lock; + if (GetSequenceMutex(lock, "Didn't get sequence mutex for QRestoreRegisterState.")) { const bool thread_suffix_supported = GetThreadSuffixSupported(); if (thread_suffix_supported || SetCurrentThread(tid)) @@ -4504,8 +4502,10 @@ 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 lock; + if (GetSequenceMutex( + lock, + "GDBRemoteCommunicationClient::ServeSymbolLookups() failed due to not getting the sequence mutex")) { StreamString packet; packet.PutCString ("qSymbol::"); Index: source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -401,8 +401,8 @@ 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 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 @@ 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 lock; + if (gdb_comm.GetSequenceMutex(lock, "Didn't get sequence mutex for read all registers.")) { SyncThreadState(process); @@ -679,8 +679,8 @@ 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 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()); Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp =================================================================== --- source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -1590,9 +1590,6 @@ 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 @@ 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 @@ Error error; bool timed_out = false; - Mutex::Locker locker; + std::unique_lock lock; if (m_public_state.GetValue() == eStateAttaching) { @@ -2727,7 +2724,7 @@ } 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 @@ { 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)) Index: source/Target/Process.cpp =================================================================== --- source/Target/Process.cpp +++ source/Target/Process.cpp @@ -978,10 +978,8 @@ 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 @@ } 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 @@ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); if (log) - log->Printf ("Process::%s (timeout = %p)", __FUNCTION__, - static_cast(timeout)); + log->Printf("Process::%s (timeout = %llu)", __FUNCTION__, static_cast(timeout.count())); if (!wait_always && StateIsStoppedState(state, true) && @@ -1029,7 +1022,7 @@ 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 @@ } 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 @@ } 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(timeout)); + log->Printf("Process::%s (timeout = %llu, event_sp)...", __FUNCTION__, + static_cast(timeout.count())); ListenerSP listener_sp = hijack_listener_sp; if (!listener_sp) @@ -1332,9 +1325,8 @@ } if (log) - log->Printf ("Process::%s (timeout = %p, event_sp) => %s", - __FUNCTION__, static_cast(timeout), - StateAsCString(state)); + log->Printf("Process::%s (timeout = %llu, event_sp) => %s", __FUNCTION__, + static_cast(timeout.count()), StateAsCString(state)); return state; } @@ -1367,13 +1359,13 @@ } 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(timeout)); + log->Printf("Process::%s (timeout = %llu, event_sp)...", __FUNCTION__, + static_cast(timeout.count())); StateType state = eStateInvalid; if (m_private_state_listener_sp->WaitForEventForBroadcasterWithType (timeout, @@ -1387,20 +1379,20 @@ // 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(timeout), - state == eStateInvalid ? "TIMEOUT" : StateAsCString(state)); + log->Printf("Process::%s (timeout = %llu, event_sp) => %s", __FUNCTION__, + static_cast(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(timeout)); + log->Printf("Process::%s (timeout = %llu, event_sp)...", __FUNCTION__, + static_cast(timeout.count())); if (control_only) return m_private_state_listener_sp->WaitForEventForBroadcaster(timeout, &m_private_state_control_broadcaster, event_sp); @@ -1751,7 +1743,7 @@ 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 @@ } 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 @@ 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 @@ // 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 @@ 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 @@ } // 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) @@ -3646,10 +3632,7 @@ 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(); @@ -4122,12 +4105,9 @@ 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 @@ -4323,7 +4303,7 @@ 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) @@ -5348,9 +5328,6 @@ 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; @@ -5451,6 +5428,7 @@ #endif TimeValue one_thread_timeout; TimeValue final_timeout; + std::chrono::microseconds timeout = std::chrono::microseconds(0); while (true) { @@ -5481,10 +5459,7 @@ } } - 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) @@ -5549,33 +5524,16 @@ 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; @@ -5586,11 +5544,15 @@ 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(std::chrono::system_clock::now().time_since_epoch().count()), + static_cast( + std::chrono::time_point(timeout) + .time_since_epoch() + .count())); } else { @@ -5608,7 +5570,7 @@ } else #endif - got_event = listener_sp->WaitForEvent (timeout_ptr, event_sp); + got_event = listener_sp->WaitForEvent(timeout, event_sp); if (got_event) { @@ -5807,10 +5769,7 @@ 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) { Index: source/Target/Target.cpp =================================================================== --- source/Target/Target.cpp +++ source/Target/Target.cpp @@ -3103,8 +3103,9 @@ 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 @@ 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 @@ } 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)