From 41ab76bf0aafb35d6d023429560b44637dfb8de6 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 28 Apr 2025 08:41:52 -0700 Subject: [PATCH] Revert "[debugserver] Migrate DNBTimer away from PThreadMutex (NFC) (#137540)" This reverts commit ae71055e6664caf7f74f2e21fb76513bef22a099. --- lldb/tools/debugserver/source/DNBTimer.h | 42 +++++++++++------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/lldb/tools/debugserver/source/DNBTimer.h b/lldb/tools/debugserver/source/DNBTimer.h index 70d14e002cc8..958c24140916 100644 --- a/lldb/tools/debugserver/source/DNBTimer.h +++ b/lldb/tools/debugserver/source/DNBTimer.h @@ -14,6 +14,7 @@ #define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBTIMER_H #include "DNBDefs.h" +#include "PThreadMutex.h" #include #include #include @@ -22,17 +23,17 @@ class DNBTimer { public: // Constructors and Destructors - DNBTimer(bool threadSafe) { + DNBTimer(bool threadSafe) : m_mutexAP() { if (threadSafe) - m_mutex_up = std::make_unique(); + m_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE)); Reset(); } - DNBTimer(const DNBTimer &rhs) { + DNBTimer(const DNBTimer &rhs) : m_mutexAP() { // Create a new mutex to make this timer thread safe as well if // the timer we are copying is thread safe if (rhs.IsThreadSafe()) - m_mutex_up = std::make_unique(); + m_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE)); m_timeval = rhs.m_timeval; } @@ -40,43 +41,35 @@ public: // Create a new mutex to make this timer thread safe as well if // the timer we are copying is thread safe if (rhs.IsThreadSafe()) - m_mutex_up = std::make_unique(); + m_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE)); m_timeval = rhs.m_timeval; return *this; } ~DNBTimer() {} - bool IsThreadSafe() const { return static_cast(m_mutex_up); } + bool IsThreadSafe() const { return m_mutexAP.get() != NULL; } // Reset the time value to now void Reset() { - auto guard = m_mutex_up - ? std::unique_lock() - : std::unique_lock(*m_mutex_up); + PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get()); gettimeofday(&m_timeval, NULL); } // Get the total microseconds since Jan 1, 1970 uint64_t TotalMicroSeconds() const { - auto guard = m_mutex_up - ? std::unique_lock() - : std::unique_lock(*m_mutex_up); + PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get()); return (uint64_t)(m_timeval.tv_sec) * 1000000ull + (uint64_t)m_timeval.tv_usec; } void GetTime(uint64_t &sec, uint32_t &usec) const { - auto guard = m_mutex_up - ? std::unique_lock() - : std::unique_lock(*m_mutex_up); + PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get()); sec = m_timeval.tv_sec; usec = m_timeval.tv_usec; } // Return the number of microseconds elapsed between now and the // m_timeval uint64_t ElapsedMicroSeconds(bool update) { - auto guard = m_mutex_up - ? std::unique_lock() - : std::unique_lock(*m_mutex_up); + PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get()); struct timeval now; gettimeofday(&now, NULL); uint64_t now_usec = @@ -123,16 +116,19 @@ public: OffsetTimeOfDay(&now); if (now.tv_sec > ts.tv_sec) return true; - if (now.tv_sec < ts.tv_sec) + else if (now.tv_sec < ts.tv_sec) return false; - if (now.tv_nsec > ts.tv_nsec) - return true; - return false; + else { + if (now.tv_nsec > ts.tv_nsec) + return true; + else + return false; + } } protected: // Classes that inherit from DNBTimer can see and modify these - std::unique_ptr m_mutex_up; + std::unique_ptr m_mutexAP; struct timeval m_timeval; };