[debugserver] Remove PThreadMutex (NFC) (#137555)
Now that all uses of PThreadMutex have been migrated to their C++ equivalent, this PR removes PThreadMutex itself.
This commit is contained in:
committed by
GitHub
parent
a61048bbcd
commit
9d77a3fa1a
@@ -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 */,
|
||||
|
||||
@@ -203,7 +203,6 @@ set(lldbDebugserverCommonSources
|
||||
libdebugserver.cpp
|
||||
PseudoTerminal.cpp
|
||||
PThreadEvent.cpp
|
||||
PThreadMutex.cpp
|
||||
RNBContext.cpp
|
||||
RNBRemote.cpp
|
||||
RNBServices.cpp
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <cstdlib>
|
||||
#include <libproc.h>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sysctl.h>
|
||||
@@ -69,8 +70,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;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "DNBError.h"
|
||||
#include "CFString.h"
|
||||
#include "DNBLog.h"
|
||||
#include "PThreadMutex.h"
|
||||
|
||||
#ifdef WITH_SPRINGBOARD
|
||||
#include <SpringBoardServices/SpringBoardServer.h>
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBTIMER_H
|
||||
|
||||
#include "DNBDefs.h"
|
||||
#include "PThreadMutex.h"
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <sys/time.h>
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "DNBError.h"
|
||||
#include "DNBLog.h"
|
||||
#include "MachProcess.h"
|
||||
#include "PThreadMutex.h"
|
||||
#include "SysSignal.h"
|
||||
#include <cerrno>
|
||||
#include <inttypes.h>
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <vector>
|
||||
|
||||
class MachProcess;
|
||||
class PThreadMutex;
|
||||
|
||||
typedef union MachMessageTag {
|
||||
mach_msg_header_t hdr;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user