Skip to content

Commit 41ab76b

Browse files
committed
Revert "[debugserver] Migrate DNBTimer away from PThreadMutex (NFC) (#137540)"
This reverts commit ae71055.
1 parent c52fdbe commit 41ab76b

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

lldb/tools/debugserver/source/DNBTimer.h

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBTIMER_H
1515

1616
#include "DNBDefs.h"
17+
#include "PThreadMutex.h"
1718
#include <cstdint>
1819
#include <memory>
1920
#include <mutex>
@@ -22,61 +23,53 @@
2223
class DNBTimer {
2324
public:
2425
// Constructors and Destructors
25-
DNBTimer(bool threadSafe) {
26+
DNBTimer(bool threadSafe) : m_mutexAP() {
2627
if (threadSafe)
27-
m_mutex_up = std::make_unique<std::recursive_mutex>();
28+
m_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE));
2829
Reset();
2930
}
3031

31-
DNBTimer(const DNBTimer &rhs) {
32+
DNBTimer(const DNBTimer &rhs) : m_mutexAP() {
3233
// Create a new mutex to make this timer thread safe as well if
3334
// the timer we are copying is thread safe
3435
if (rhs.IsThreadSafe())
35-
m_mutex_up = std::make_unique<std::recursive_mutex>();
36+
m_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE));
3637
m_timeval = rhs.m_timeval;
3738
}
3839

3940
DNBTimer &operator=(const DNBTimer &rhs) {
4041
// Create a new mutex to make this timer thread safe as well if
4142
// the timer we are copying is thread safe
4243
if (rhs.IsThreadSafe())
43-
m_mutex_up = std::make_unique<std::recursive_mutex>();
44+
m_mutexAP.reset(new PThreadMutex(PTHREAD_MUTEX_RECURSIVE));
4445
m_timeval = rhs.m_timeval;
4546
return *this;
4647
}
4748

4849
~DNBTimer() {}
4950

50-
bool IsThreadSafe() const { return static_cast<bool>(m_mutex_up); }
51+
bool IsThreadSafe() const { return m_mutexAP.get() != NULL; }
5152
// Reset the time value to now
5253
void Reset() {
53-
auto guard = m_mutex_up
54-
? std::unique_lock<std::recursive_mutex>()
55-
: std::unique_lock<std::recursive_mutex>(*m_mutex_up);
54+
PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get());
5655
gettimeofday(&m_timeval, NULL);
5756
}
5857
// Get the total microseconds since Jan 1, 1970
5958
uint64_t TotalMicroSeconds() const {
60-
auto guard = m_mutex_up
61-
? std::unique_lock<std::recursive_mutex>()
62-
: std::unique_lock<std::recursive_mutex>(*m_mutex_up);
59+
PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get());
6360
return (uint64_t)(m_timeval.tv_sec) * 1000000ull +
6461
(uint64_t)m_timeval.tv_usec;
6562
}
6663

6764
void GetTime(uint64_t &sec, uint32_t &usec) const {
68-
auto guard = m_mutex_up
69-
? std::unique_lock<std::recursive_mutex>()
70-
: std::unique_lock<std::recursive_mutex>(*m_mutex_up);
65+
PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get());
7166
sec = m_timeval.tv_sec;
7267
usec = m_timeval.tv_usec;
7368
}
7469
// Return the number of microseconds elapsed between now and the
7570
// m_timeval
7671
uint64_t ElapsedMicroSeconds(bool update) {
77-
auto guard = m_mutex_up
78-
? std::unique_lock<std::recursive_mutex>()
79-
: std::unique_lock<std::recursive_mutex>(*m_mutex_up);
72+
PTHREAD_MUTEX_LOCKER(locker, m_mutexAP.get());
8073
struct timeval now;
8174
gettimeofday(&now, NULL);
8275
uint64_t now_usec =
@@ -123,16 +116,19 @@ class DNBTimer {
123116
OffsetTimeOfDay(&now);
124117
if (now.tv_sec > ts.tv_sec)
125118
return true;
126-
if (now.tv_sec < ts.tv_sec)
119+
else if (now.tv_sec < ts.tv_sec)
127120
return false;
128-
if (now.tv_nsec > ts.tv_nsec)
129-
return true;
130-
return false;
121+
else {
122+
if (now.tv_nsec > ts.tv_nsec)
123+
return true;
124+
else
125+
return false;
126+
}
131127
}
132128

133129
protected:
134130
// Classes that inherit from DNBTimer can see and modify these
135-
std::unique_ptr<std::recursive_mutex> m_mutex_up;
131+
std::unique_ptr<PThreadMutex> m_mutexAP;
136132
struct timeval m_timeval;
137133
};
138134

0 commit comments

Comments
 (0)