-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[debugserver] Remove PThreadMutex (NFC) #137555
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
Conversation
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesNow that all uses of PThreadMutex have been migrated to their C++ equivalent, this PR removes PThreadMutex itself. Full diff: https://github.com/llvm/llvm-project/pull/137555.diff 9 Files Affected:
diff --git a/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj b/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj
index c25eabcbadab3..f0103008bb27f 100644
--- a/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj
+++ b/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj
@@ -36,7 +36,6 @@
26CE05BA115C363E0022F371 /* DNBLog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C637E00C71334A0024798E /* DNBLog.cpp */; };
26CE05BB115C363F0022F371 /* DNBRegisterInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C637E20C71334A0024798E /* DNBRegisterInfo.cpp */; };
26CE05BC115C36420022F371 /* PThreadEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C637FE0C71334A0024798E /* PThreadEvent.cpp */; };
- 26CE05BD115C36430022F371 /* PThreadMutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2672DBEE0EEF446700E92059 /* PThreadMutex.cpp */; };
26CE05BE115C36440022F371 /* SysSignal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C638010C71334A0024798E /* SysSignal.cpp */; };
26CE05BF115C364D0022F371 /* DNBArchImplX86_64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26CF99A21142EB7400011AAB /* DNBArchImplX86_64.cpp */; };
26CE05C3115C36580022F371 /* CFString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2695DD9B0D3EC160007E4CA2 /* CFString.cpp */; };
@@ -65,7 +64,6 @@
456F67591AD46CE9002850C2 /* DNBLog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C637E00C71334A0024798E /* DNBLog.cpp */; };
456F675A1AD46CE9002850C2 /* DNBRegisterInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C637E20C71334A0024798E /* DNBRegisterInfo.cpp */; };
456F675B1AD46CE9002850C2 /* PThreadEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C637FE0C71334A0024798E /* PThreadEvent.cpp */; };
- 456F675C1AD46CE9002850C2 /* PThreadMutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2672DBEE0EEF446700E92059 /* PThreadMutex.cpp */; };
456F675D1AD46CE9002850C2 /* SysSignal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C638010C71334A0024798E /* SysSignal.cpp */; };
456F675E1AD46CE9002850C2 /* DNBArchImplX86_64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26CF99A21142EB7400011AAB /* DNBArchImplX86_64.cpp */; };
456F67621AD46CE9002850C2 /* CFString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2695DD9B0D3EC160007E4CA2 /* CFString.cpp */; };
@@ -102,7 +100,6 @@
26593A060D4931CC001C9FE3 /* ChangeLog */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ChangeLog; sourceTree = "<group>"; };
266B5ECF1460A68200E43F0A /* DNBArchImplARM64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DNBArchImplARM64.cpp; sourceTree = "<group>"; };
266B5ED01460A68200E43F0A /* DNBArchImplARM64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNBArchImplARM64.h; sourceTree = "<group>"; };
- 2672DBEE0EEF446700E92059 /* PThreadMutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PThreadMutex.cpp; sourceTree = "<group>"; };
2695DD910D3EBFF6007E4CA2 /* CFBundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CFBundle.cpp; sourceTree = "<group>"; };
2695DD920D3EBFF6007E4CA2 /* CFBundle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFBundle.h; sourceTree = "<group>"; };
2695DD9A0D3EC160007E4CA2 /* CFString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFString.h; sourceTree = "<group>"; };
@@ -151,7 +148,6 @@
26C637FD0C71334A0024798E /* PThreadCondition.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PThreadCondition.h; sourceTree = "<group>"; };
26C637FE0C71334A0024798E /* PThreadEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PThreadEvent.cpp; sourceTree = "<group>"; };
26C637FF0C71334A0024798E /* PThreadEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PThreadEvent.h; sourceTree = "<group>"; };
- 26C638000C71334A0024798E /* PThreadMutex.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PThreadMutex.h; sourceTree = "<group>"; };
26C638010C71334A0024798E /* SysSignal.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SysSignal.cpp; sourceTree = "<group>"; };
26C638020C71334A0024798E /* SysSignal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SysSignal.h; sourceTree = "<group>"; };
26C638050C71334A0024798E /* TTYState.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = TTYState.cpp; sourceTree = "<group>"; };
@@ -284,8 +280,6 @@
26C637FD0C71334A0024798E /* PThreadCondition.h */,
26C637FF0C71334A0024798E /* PThreadEvent.h */,
26C637FE0C71334A0024798E /* PThreadEvent.cpp */,
- 26C638000C71334A0024798E /* PThreadMutex.h */,
- 2672DBEE0EEF446700E92059 /* PThreadMutex.cpp */,
233B4EA81D2DB96A00E98261 /* StringConvert.cpp */,
26C638020C71334A0024798E /* SysSignal.h */,
26C638010C71334A0024798E /* SysSignal.cpp */,
@@ -486,7 +480,6 @@
26CE05BA115C363E0022F371 /* DNBLog.cpp in Sources */,
26CE05BB115C363F0022F371 /* DNBRegisterInfo.cpp in Sources */,
26CE05BC115C36420022F371 /* PThreadEvent.cpp in Sources */,
- 26CE05BD115C36430022F371 /* PThreadMutex.cpp in Sources */,
26CE05BE115C36440022F371 /* SysSignal.cpp in Sources */,
26CE05BF115C364D0022F371 /* DNBArchImplX86_64.cpp in Sources */,
26CE05C5115C36590022F371 /* CFBundle.cpp in Sources */,
@@ -525,7 +518,6 @@
456F67591AD46CE9002850C2 /* DNBLog.cpp in Sources */,
456F675A1AD46CE9002850C2 /* DNBRegisterInfo.cpp in Sources */,
456F675B1AD46CE9002850C2 /* PThreadEvent.cpp in Sources */,
- 456F675C1AD46CE9002850C2 /* PThreadMutex.cpp in Sources */,
456F675D1AD46CE9002850C2 /* SysSignal.cpp in Sources */,
456F675E1AD46CE9002850C2 /* DNBArchImplX86_64.cpp in Sources */,
23043C9E1D35DBFA00FC25CA /* StringConvert.cpp in Sources */,
diff --git a/lldb/tools/debugserver/source/CMakeLists.txt b/lldb/tools/debugserver/source/CMakeLists.txt
index 1a433898f6aa4..f7ff76c3e8e84 100644
--- a/lldb/tools/debugserver/source/CMakeLists.txt
+++ b/lldb/tools/debugserver/source/CMakeLists.txt
@@ -203,7 +203,6 @@ set(lldbDebugserverCommonSources
libdebugserver.cpp
PseudoTerminal.cpp
PThreadEvent.cpp
- PThreadMutex.cpp
RNBContext.cpp
RNBRemote.cpp
RNBServices.cpp
diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp
index 10c55dc3f769f..b1389ab8f8066 100644
--- a/lldb/tools/debugserver/source/DNB.cpp
+++ b/lldb/tools/debugserver/source/DNB.cpp
@@ -69,8 +69,8 @@ static ProcessMap *GetProcessMap(bool can_create) {
static ProcessMap *g_process_map_ptr = NULL;
if (can_create && g_process_map_ptr == NULL) {
- static pthread_mutex_t g_process_map_mutex = PTHREAD_MUTEX_INITIALIZER;
- PTHREAD_MUTEX_LOCKER(locker, &g_process_map_mutex);
+ static std::mutex g_process_map_mutex;
+ std::lock_guard<std::mutex> guard(g_process_map_mutex);
if (g_process_map_ptr == NULL)
g_process_map_ptr = new ProcessMap;
}
diff --git a/lldb/tools/debugserver/source/DNBError.cpp b/lldb/tools/debugserver/source/DNBError.cpp
index 00933bce1a770..17690428341bf 100644
--- a/lldb/tools/debugserver/source/DNBError.cpp
+++ b/lldb/tools/debugserver/source/DNBError.cpp
@@ -13,7 +13,6 @@
#include "DNBError.h"
#include "CFString.h"
#include "DNBLog.h"
-#include "PThreadMutex.h"
#ifdef WITH_SPRINGBOARD
#include <SpringBoardServices/SpringBoardServer.h>
diff --git a/lldb/tools/debugserver/source/MacOSX/MachException.cpp b/lldb/tools/debugserver/source/MacOSX/MachException.cpp
index 40450c2c9d1ff..618fce370d9eb 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachException.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/MachException.cpp
@@ -15,7 +15,6 @@
#include "DNBError.h"
#include "DNBLog.h"
#include "MachProcess.h"
-#include "PThreadMutex.h"
#include "SysSignal.h"
#include <cerrno>
#include <inttypes.h>
diff --git a/lldb/tools/debugserver/source/MacOSX/MachException.h b/lldb/tools/debugserver/source/MacOSX/MachException.h
index 573e84e991608..2da389c50be61 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachException.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachException.h
@@ -17,7 +17,6 @@
#include <vector>
class MachProcess;
-class PThreadMutex;
typedef union MachMessageTag {
mach_msg_header_t hdr;
diff --git a/lldb/tools/debugserver/source/MacOSX/MachTask.h b/lldb/tools/debugserver/source/MacOSX/MachTask.h
index 286a57b9e0dd1..2284f6b99de91 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachTask.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachTask.h
@@ -16,15 +16,14 @@
#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_MACHTASK_H
#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_MACHTASK_H
-#include <mach/mach.h>
-#include <sys/socket.h>
-#include <map>
-#include <string>
#include "DNBDefs.h"
-#include "RNBContext.h"
#include "MachException.h"
#include "MachVMMemory.h"
-#include "PThreadMutex.h"
+#include "RNBContext.h"
+#include <mach/mach.h>
+#include <map>
+#include <string>
+#include <sys/socket.h>
class MachProcess;
diff --git a/lldb/tools/debugserver/source/PThreadMutex.cpp b/lldb/tools/debugserver/source/PThreadMutex.cpp
deleted file mode 100644
index 118921aee5a81..0000000000000
--- a/lldb/tools/debugserver/source/PThreadMutex.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-//===-- PThreadMutex.cpp ----------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Created by Greg Clayton on 12/9/08.
-//
-//===----------------------------------------------------------------------===//
-
-#include "PThreadMutex.h"
-
-#include "DNBTimer.h"
-
-#if defined(DEBUG_PTHREAD_MUTEX_DEADLOCKS)
-
-PThreadMutex::Locker::Locker(PThreadMutex &m, const char *function,
- const char *file, const int line)
- : m_pMutex(m.Mutex()), m_function(function), m_file(file), m_line(line),
- m_lock_time(0) {
- Lock();
-}
-
-PThreadMutex::Locker::Locker(PThreadMutex *m, const char *function,
- const char *file, const int line)
- : m_pMutex(m ? m->Mutex() : NULL), m_function(function), m_file(file),
- m_line(line), m_lock_time(0) {
- Lock();
-}
-
-PThreadMutex::Locker::Locker(pthread_mutex_t *mutex, const char *function,
- const char *file, const int line)
- : m_pMutex(mutex), m_function(function), m_file(file), m_line(line),
- m_lock_time(0) {
- Lock();
-}
-
-PThreadMutex::Locker::~Locker() { Unlock(); }
-
-void PThreadMutex::Locker::Lock() {
- if (m_pMutex) {
- m_lock_time = DNBTimer::GetTimeOfDay();
- if (::pthread_mutex_trylock(m_pMutex) != 0) {
- fprintf(stdout, "::pthread_mutex_trylock (%8.8p) mutex is locked "
- "(function %s in %s:%i), waiting...\n",
- m_pMutex, m_function, m_file, m_line);
- ::pthread_mutex_lock(m_pMutex);
- fprintf(stdout, "::pthread_mutex_lock (%8.8p) succeeded after %6llu "
- "usecs (function %s in %s:%i)\n",
- m_pMutex, DNBTimer::GetTimeOfDay() - m_lock_time, m_function,
- m_file, m_line);
- }
- }
-}
-
-void PThreadMutex::Locker::Unlock() {
- fprintf(stdout, "::pthread_mutex_unlock (%8.8p) had lock for %6llu usecs in "
- "%s in %s:%i\n",
- m_pMutex, DNBTimer::GetTimeOfDay() - m_lock_time, m_function, m_file,
- m_line);
- ::pthread_mutex_unlock(m_pMutex);
-}
-
-#endif
diff --git a/lldb/tools/debugserver/source/PThreadMutex.h b/lldb/tools/debugserver/source/PThreadMutex.h
deleted file mode 100644
index 17f9fdff5f2d3..0000000000000
--- a/lldb/tools/debugserver/source/PThreadMutex.h
+++ /dev/null
@@ -1,119 +0,0 @@
-//===-- PThreadMutex.h ------------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Created by Greg Clayton on 6/16/07.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_PTHREADMUTEX_H
-#define LLDB_TOOLS_DEBUGSERVER_SOURCE_PTHREADMUTEX_H
-
-#include <cassert>
-#include <cstdint>
-#include <pthread.h>
-
-//#define DEBUG_PTHREAD_MUTEX_DEADLOCKS 1
-
-#if defined(DEBUG_PTHREAD_MUTEX_DEADLOCKS)
-#define PTHREAD_MUTEX_LOCKER(var, mutex) \
- PThreadMutex::Locker var(mutex, __FUNCTION__, __FILE__, __LINE__)
-
-#else
-#define PTHREAD_MUTEX_LOCKER(var, mutex) PThreadMutex::Locker var(mutex)
-#endif
-
-class PThreadMutex {
-public:
- class Locker {
- public:
-#if defined(DEBUG_PTHREAD_MUTEX_DEADLOCKS)
-
- Locker(PThreadMutex &m, const char *function, const char *file, int line);
- Locker(PThreadMutex *m, const char *function, const char *file, int line);
- Locker(pthread_mutex_t *mutex, const char *function, const char *file,
- int line);
- ~Locker();
- void Lock();
- void Unlock();
-
-#else
- Locker(PThreadMutex &m) : m_pMutex(m.Mutex()) { Lock(); }
-
- Locker(PThreadMutex *m) : m_pMutex(m ? m->Mutex() : NULL) { Lock(); }
-
- Locker(pthread_mutex_t *mutex) : m_pMutex(mutex) { Lock(); }
-
- void Lock() {
- if (m_pMutex)
- ::pthread_mutex_lock(m_pMutex);
- }
-
- void Unlock() {
- if (m_pMutex)
- ::pthread_mutex_unlock(m_pMutex);
- }
-
- ~Locker() { Unlock(); }
-
-#endif
-
- // unlock any the current mutex and lock the new one if it is valid
- void Reset(pthread_mutex_t *pMutex = NULL) {
- Unlock();
- m_pMutex = pMutex;
- Lock();
- }
- pthread_mutex_t *m_pMutex;
-#if defined(DEBUG_PTHREAD_MUTEX_DEADLOCKS)
- const char *m_function;
- const char *m_file;
- int m_line;
- uint64_t m_lock_time;
-#endif
- };
-
- PThreadMutex() {
- [[maybe_unused]] int err;
- err = ::pthread_mutex_init(&m_mutex, NULL);
- assert(err == 0);
- }
-
- PThreadMutex(int type) {
- [[maybe_unused]] int err;
- ::pthread_mutexattr_t attr;
- err = ::pthread_mutexattr_init(&attr);
- assert(err == 0);
- err = ::pthread_mutexattr_settype(&attr, type);
- assert(err == 0);
- err = ::pthread_mutex_init(&m_mutex, &attr);
- assert(err == 0);
- err = ::pthread_mutexattr_destroy(&attr);
- assert(err == 0);
- }
-
- ~PThreadMutex() {
- [[maybe_unused]] int err;
- err = ::pthread_mutex_destroy(&m_mutex);
- if (err != 0) {
- err = Unlock();
- if (err == 0)
- ::pthread_mutex_destroy(&m_mutex);
- }
- }
-
- pthread_mutex_t *Mutex() { return &m_mutex; }
-
- int Lock() { return ::pthread_mutex_lock(&m_mutex); }
-
- int Unlock() { return ::pthread_mutex_unlock(&m_mutex); }
-
-protected:
- pthread_mutex_t m_mutex;
-};
-
-#endif
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol thanks for updating the xcode project file, it's sometimes handy to build debugserver alone without the rest of lldb.
Now that all uses of PThreadMutex have been migrated to their C++ equivalent, this PR removes PThreadMutex itself.
1095cfe
to
1ebef7a
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/15188 Here is the relevant piece of the build log for the reference
|
Now that all uses of PThreadMutex have been migrated to their C++ equivalent, this PR removes PThreadMutex itself.
Now that all uses of PThreadMutex have been migrated to their C++ equivalent, this PR removes PThreadMutex itself.
Now that all uses of PThreadMutex have been migrated to their C++ equivalent, this PR removes PThreadMutex itself.
Now that all uses of PThreadMutex have been migrated to their C++ equivalent, this PR removes PThreadMutex itself.
Now that all uses of PThreadMutex have been migrated to their C++ equivalent, this PR removes PThreadMutex itself.
Now that all uses of PThreadMutex have been migrated to their C++ equivalent, this PR removes PThreadMutex itself.