Author: Jonas Devlieghere Date: 2025-04-28T08:44:30-07:00 New Revision: 41ab76bf0aafb35d6d023429560b44637dfb8de6
URL: https://github.com/llvm/llvm-project/commit/41ab76bf0aafb35d6d023429560b44637dfb8de6 DIFF: https://github.com/llvm/llvm-project/commit/41ab76bf0aafb35d6d023429560b44637dfb8de6.diff LOG: Revert "[debugserver] Migrate DNBTimer away from PThreadMutex (NFC) (#137540)" This reverts commit ae71055e6664caf7f74f2e21fb76513bef22a099. Added: Modified: lldb/tools/debugserver/source/DNBTimer.h Removed: ################################################################################ diff --git a/lldb/tools/debugserver/source/DNBTimer.h b/lldb/tools/debugserver/source/DNBTimer.h index 70d14e002cc81..958c24140916c 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 <cstdint> #include <memory> #include <mutex> @@ -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<std::recursive_mutex>(); + 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<std::recursive_mutex>(); + m_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE)); m_timeval = rhs.m_timeval; } @@ -40,43 +41,35 @@ class DNBTimer { // 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<std::recursive_mutex>(); + m_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE)); m_timeval = rhs.m_timeval; return *this; } ~DNBTimer() {} - bool IsThreadSafe() const { return static_cast<bool>(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::recursive_mutex>() - : std::unique_lock<std::recursive_mutex>(*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::recursive_mutex>() - : std::unique_lock<std::recursive_mutex>(*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::recursive_mutex>() - : std::unique_lock<std::recursive_mutex>(*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::recursive_mutex>() - : std::unique_lock<std::recursive_mutex>(*m_mutex_up); + PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get()); struct timeval now; gettimeofday(&now, NULL); uint64_t now_usec = @@ -123,16 +116,19 @@ class DNBTimer { 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<std::recursive_mutex> m_mutex_up; + std::unique_ptr<PThreadMutex> m_mutexAP; struct timeval m_timeval; }; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits