Changeset View
Changeset View
Standalone View
Standalone View
lib/Support/Threading.cpp
Show All 15 Lines | |||||
#include "llvm/Support/Atomic.h" | #include "llvm/Support/Atomic.h" | ||||
#include "llvm/Support/Mutex.h" | #include "llvm/Support/Mutex.h" | ||||
#include <cassert> | #include <cassert> | ||||
using namespace llvm; | using namespace llvm; | ||||
static bool multithreaded_mode = false; | static bool multithreaded_mode = false; | ||||
static sys::Mutex* global_lock = nullptr; | static sys::RecursiveMutex* global_lock = nullptr; | ||||
bool llvm::llvm_start_multithreaded() { | bool llvm::llvm_start_multithreaded() { | ||||
#if LLVM_ENABLE_THREADS != 0 | #if LLVM_ENABLE_THREADS != 0 | ||||
assert(!multithreaded_mode && "Already multithreaded!"); | assert(!multithreaded_mode && "Already multithreaded!"); | ||||
multithreaded_mode = true; | multithreaded_mode = true; | ||||
global_lock = new sys::Mutex(true); | global_lock = new sys::RecursiveMutex; | ||||
// We fence here to ensure that all initialization is complete BEFORE we | // We fence here to ensure that all initialization is complete BEFORE we | ||||
// return from llvm_start_multithreaded(). | // return from llvm_start_multithreaded(). | ||||
sys::MemoryFence(); | sys::MemoryFence(); | ||||
return true; | return true; | ||||
#else | #else | ||||
return false; | return false; | ||||
#endif | #endif | ||||
} | } | ||||
void llvm::llvm_stop_multithreaded() { | void llvm::llvm_stop_multithreaded() { | ||||
#if LLVM_ENABLE_THREADS != 0 | #if LLVM_ENABLE_THREADS != 0 | ||||
assert(multithreaded_mode && "Not currently multithreaded!"); | assert(multithreaded_mode && "Not currently multithreaded!"); | ||||
// We fence here to insure that all threaded operations are complete BEFORE we | // We fence here to insure that all threaded operations are complete BEFORE we | ||||
// return from llvm_stop_multithreaded(). | // return from llvm_stop_multithreaded(). | ||||
sys::MemoryFence(); | sys::MemoryFence(); | ||||
multithreaded_mode = false; | multithreaded_mode = false; | ||||
delete global_lock; | delete global_lock; | ||||
global_lock = nullptr; | |||||
#endif | #endif | ||||
} | } | ||||
bool llvm::llvm_is_multithreaded() { | bool llvm::llvm_is_multithreaded() { | ||||
return multithreaded_mode; | return multithreaded_mode; | ||||
} | } | ||||
void llvm::llvm_acquire_global_lock() { | void llvm::llvm_acquire_global_lock() { | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |