-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[debugserver] Migrate DNBTimer away from PThreadMutex (NFC) #137540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The debugserver code predates modern C++, but with C++11 and later there's no need to have something like PThreadMutex. This migrates DNBTimer away from that class in preparation for removing PThreadMutex.
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesThe debugserver code predates modern C++, but with C++11 and later there's no need to have something like PThreadMutex. This migrates DNBTimer away from that class in preparation for removing PThreadMutex. Full diff: https://github.com/llvm/llvm-project/pull/137540.diff 1 Files Affected:
diff --git a/lldb/tools/debugserver/source/DNBTimer.h b/lldb/tools/debugserver/source/DNBTimer.h
index 2251c50fb8768..78b64c6583d3d 100644
--- a/lldb/tools/debugserver/source/DNBTimer.h
+++ b/lldb/tools/debugserver/source/DNBTimer.h
@@ -14,7 +14,6 @@
#define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBTIMER_H
#include "DNBDefs.h"
-#include "PThreadMutex.h"
#include <cstdint>
#include <memory>
#include <sys/time.h>
@@ -22,17 +21,17 @@
class DNBTimer {
public:
// Constructors and Destructors
- DNBTimer(bool threadSafe) : m_mutexAP() {
+ DNBTimer(bool threadSafe) {
if (threadSafe)
- m_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE));
+ m_mutex_up = std::make_unique<std::recursive_mutex>();
Reset();
}
- DNBTimer(const DNBTimer &rhs) : m_mutexAP() {
+ DNBTimer(const DNBTimer &rhs) {
// 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_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE));
+ m_mutex_up = std::make_unique<std::recursive_mutex>();
m_timeval = rhs.m_timeval;
}
@@ -40,35 +39,43 @@ 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_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE));
+ m_mutex_up = std::make_unique<std::recursive_mutex>();
m_timeval = rhs.m_timeval;
return *this;
}
~DNBTimer() {}
- bool IsThreadSafe() const { return m_mutexAP.get() != NULL; }
+ bool IsThreadSafe() const { return static_cast<bool>(m_mutex_up); }
// Reset the time value to now
void Reset() {
- PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get());
+ auto guard = m_mutex_up
+ ? std::unique_lock<std::recursive_mutex>()
+ : std::unique_lock<std::recursive_mutex>(*m_mutex_up);
gettimeofday(&m_timeval, NULL);
}
// Get the total microseconds since Jan 1, 1970
uint64_t TotalMicroSeconds() const {
- PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get());
+ auto guard = m_mutex_up
+ ? std::unique_lock<std::recursive_mutex>()
+ : std::unique_lock<std::recursive_mutex>(*m_mutex_up);
return (uint64_t)(m_timeval.tv_sec) * 1000000ull +
(uint64_t)m_timeval.tv_usec;
}
void GetTime(uint64_t &sec, uint32_t &usec) const {
- PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get());
+ auto guard = m_mutex_up
+ ? std::unique_lock<std::recursive_mutex>()
+ : std::unique_lock<std::recursive_mutex>(*m_mutex_up);
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) {
- PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get());
+ auto guard = m_mutex_up
+ ? std::unique_lock<std::recursive_mutex>()
+ : std::unique_lock<std::recursive_mutex>(*m_mutex_up);
struct timeval now;
gettimeofday(&now, NULL);
uint64_t now_usec =
@@ -115,19 +122,16 @@ class DNBTimer {
OffsetTimeOfDay(&now);
if (now.tv_sec > ts.tv_sec)
return true;
- else if (now.tv_sec < ts.tv_sec)
+ if (now.tv_sec < ts.tv_sec)
return false;
- else {
- if (now.tv_nsec > ts.tv_nsec)
- return true;
- else
- return false;
- }
+ if (now.tv_nsec > ts.tv_nsec)
+ return true;
+ return false;
}
protected:
// Classes that inherit from DNBTimer can see and modify these
- std::unique_ptr<PThreadMutex> m_mutexAP;
+ std::unique_ptr<std::recursive_mutex> m_mutex_up;
struct timeval m_timeval;
};
|
jasonmolenda
approved these changes
Apr 27, 2025
JDevlieghere
added a commit
that referenced
this pull request
Apr 28, 2025
The debugserver code predates modern C++, but with C++11 and later there's no need to have something like PThreadMutex. This migrates DNBTimer away from that class in preparation for removing PThreadMutex.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…lvm#137540)" This reverts commit ae71055.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…lvm#137540)" This reverts commit ae71055.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…lvm#137540)" This reverts commit ae71055.
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
…lvm#137540)" This reverts commit ae71055.
Ankur-0429
pushed a commit
to Ankur-0429/llvm-project
that referenced
this pull request
May 9, 2025
…lvm#137540)" This reverts commit ae71055.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The debugserver code predates modern C++, but with C++11 and later there's no need to have something like PThreadMutex. This migrates DNBTimer away from that class in preparation for removing PThreadMutex.