mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-11 10:26:44 +00:00
[Support] Replace sys::Mutex with their standard equivalents.
Only use a recursive mutex if it can be locked recursively. llvm-svn: 369295
This commit is contained in:
parent
056f1b5cc7
commit
928071ae4e
@ -10,8 +10,8 @@
|
||||
#include "llvm/Config/llvm-config.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Support/Mutex.h"
|
||||
#include "llvm/Support/ThreadLocal.h"
|
||||
#include <mutex>
|
||||
#include <setjmp.h>
|
||||
using namespace llvm;
|
||||
|
||||
@ -71,7 +71,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
static ManagedStatic<sys::Mutex> gCrashRecoveryContextMutex;
|
||||
static ManagedStatic<std::mutex> gCrashRecoveryContextMutex;
|
||||
static bool gCrashRecoveryEnabled = false;
|
||||
|
||||
static ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>>
|
||||
@ -116,7 +116,7 @@ CrashRecoveryContext *CrashRecoveryContext::GetCurrent() {
|
||||
}
|
||||
|
||||
void CrashRecoveryContext::Enable() {
|
||||
sys::ScopedLock L(*gCrashRecoveryContextMutex);
|
||||
std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex);
|
||||
// FIXME: Shouldn't this be a refcount or something?
|
||||
if (gCrashRecoveryEnabled)
|
||||
return;
|
||||
@ -125,7 +125,7 @@ void CrashRecoveryContext::Enable() {
|
||||
}
|
||||
|
||||
void CrashRecoveryContext::Disable() {
|
||||
sys::ScopedLock L(*gCrashRecoveryContextMutex);
|
||||
std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex);
|
||||
if (!gCrashRecoveryEnabled)
|
||||
return;
|
||||
gCrashRecoveryEnabled = false;
|
||||
|
@ -12,21 +12,20 @@
|
||||
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Config/config.h"
|
||||
#include "llvm/Support/Mutex.h"
|
||||
#include "llvm/Support/Threading.h"
|
||||
#include <cassert>
|
||||
#include <mutex>
|
||||
using namespace llvm;
|
||||
|
||||
static const ManagedStaticBase *StaticList = nullptr;
|
||||
static sys::Mutex *ManagedStaticMutex = nullptr;
|
||||
static std::recursive_mutex *ManagedStaticMutex = nullptr;
|
||||
static llvm::once_flag mutex_init_flag;
|
||||
|
||||
static void initializeMutex() {
|
||||
ManagedStaticMutex = new sys::Mutex();
|
||||
ManagedStaticMutex = new std::recursive_mutex();
|
||||
}
|
||||
|
||||
static sys::Mutex* getManagedStaticMutex() {
|
||||
static std::recursive_mutex *getManagedStaticMutex() {
|
||||
llvm::call_once(mutex_init_flag, initializeMutex);
|
||||
return ManagedStaticMutex;
|
||||
}
|
||||
@ -35,7 +34,7 @@ void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(),
|
||||
void (*Deleter)(void*)) const {
|
||||
assert(Creator);
|
||||
if (llvm_is_multithreaded()) {
|
||||
std::lock_guard<sys::Mutex> Lock(*getManagedStaticMutex());
|
||||
std::lock_guard<std::recursive_mutex> Lock(*getManagedStaticMutex());
|
||||
|
||||
if (!Ptr.load(std::memory_order_relaxed)) {
|
||||
void *Tmp = Creator();
|
||||
@ -77,7 +76,7 @@ void ManagedStaticBase::destroy() const {
|
||||
|
||||
/// llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
|
||||
void llvm::llvm_shutdown() {
|
||||
std::lock_guard<sys::Mutex> Lock(*getManagedStaticMutex());
|
||||
std::lock_guard<std::recursive_mutex> Lock(*getManagedStaticMutex());
|
||||
|
||||
while (StaticList)
|
||||
StaticList->destroy();
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Config/config.h"
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Support/Mutex.h"
|
||||
#include <mutex>
|
||||
#if HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
@ -327,13 +326,13 @@ extern "C" int tigetnum(char *capname);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TERMINFO
|
||||
static ManagedStatic<sys::Mutex> TermColorMutex;
|
||||
static ManagedStatic<std::mutex> TermColorMutex;
|
||||
#endif
|
||||
|
||||
static bool terminalHasColors(int fd) {
|
||||
#ifdef HAVE_TERMINFO
|
||||
// First, acquire a global lock because these C routines are thread hostile.
|
||||
std::lock_guard<sys::Mutex> G(*TermColorMutex);
|
||||
std::lock_guard<std::mutex> G(*TermColorMutex);
|
||||
|
||||
int errret = 0;
|
||||
if (setupterm(nullptr, fd, &errret) != 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user