diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2025-04-28 08:41:52 -0700 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2025-04-28 08:44:30 -0700 |
commit | 41ab76bf0aafb35d6d023429560b44637dfb8de6 (patch) | |
tree | b27192edad80e57f11455a988240af0c03cc2780 | |
parent | c52fdbe697eb0eee2484c5bf1aeb17d678430830 (diff) | |
download | llvm-41ab76bf0aafb35d6d023429560b44637dfb8de6.zip llvm-41ab76bf0aafb35d6d023429560b44637dfb8de6.tar.gz llvm-41ab76bf0aafb35d6d023429560b44637dfb8de6.tar.bz2 |
Revert "[debugserver] Migrate DNBTimer away from PThreadMutex (NFC) (#137540)"
This reverts commit ae71055e6664caf7f74f2e21fb76513bef22a099.
-rw-r--r-- | lldb/tools/debugserver/source/DNBTimer.h | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/lldb/tools/debugserver/source/DNBTimer.h b/lldb/tools/debugserver/source/DNBTimer.h index 70d14e0..958c241 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 @@ 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<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 @@ 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<std::recursive_mutex> m_mutex_up; + std::unique_ptr<PThreadMutex> m_mutexAP; struct timeval m_timeval; }; |