Commit 7859058e by Zhixun Tan Committed by Tianqi Chen

Name all the lock guards. (#938)

parent ca8e31ff
...@@ -24,7 +24,7 @@ struct LLVMEnv { ...@@ -24,7 +24,7 @@ struct LLVMEnv {
void InitializeLLVM() { void InitializeLLVM() {
LLVMEnv* e = LLVMEnv::Global(); LLVMEnv* e = LLVMEnv::Global();
if (!e->all_initialized) { if (!e->all_initialized) {
std::lock_guard<std::mutex>(e->mu); std::lock_guard<std::mutex> lock(e->mu);
if (!e->all_initialized) { if (!e->all_initialized) {
e->all_initialized = true; e->all_initialized = true;
llvm::InitializeAllTargetInfos(); llvm::InitializeAllTargetInfos();
......
...@@ -96,7 +96,7 @@ MetalWorkspace::~MetalWorkspace() { ...@@ -96,7 +96,7 @@ MetalWorkspace::~MetalWorkspace() {
void MetalWorkspace::Init() { void MetalWorkspace::Init() {
if (initialized_) return; if (initialized_) return;
std::lock_guard<std::mutex>(this->mutex); std::lock_guard<std::mutex> lock(this->mutex);
if (initialized_) return; if (initialized_) return;
initialized_ = true; initialized_ = true;
if (devices.size() != 0) return; if (devices.size() != 0) return;
......
...@@ -180,7 +180,7 @@ bool MatchPlatformInfo( ...@@ -180,7 +180,7 @@ bool MatchPlatformInfo(
void OpenCLWorkspace::Init() { void OpenCLWorkspace::Init() {
if (initialized_) return; if (initialized_) return;
std::lock_guard<std::mutex>(this->mu); std::lock_guard<std::mutex> lock(this->mu);
if (initialized_) return; if (initialized_) return;
initialized_ = true; initialized_ = true;
if (context != nullptr) return; if (context != nullptr) return;
......
...@@ -46,7 +46,7 @@ Registry& Registry::set_body(PackedFunc f) { // NOLINT(*) ...@@ -46,7 +46,7 @@ Registry& Registry::set_body(PackedFunc f) { // NOLINT(*)
Registry& Registry::Register(const std::string& name, bool override) { // NOLINT(*) Registry& Registry::Register(const std::string& name, bool override) { // NOLINT(*)
Manager* m = Manager::Global(); Manager* m = Manager::Global();
std::lock_guard<std::mutex>(m->mutex); std::lock_guard<std::mutex> lock(m->mutex);
auto it = m->fmap.find(name); auto it = m->fmap.find(name);
if (it == m->fmap.end()) { if (it == m->fmap.end()) {
Registry* r = new Registry(); Registry* r = new Registry();
...@@ -62,7 +62,7 @@ Registry& Registry::Register(const std::string& name, bool override) { // NOLIN ...@@ -62,7 +62,7 @@ Registry& Registry::Register(const std::string& name, bool override) { // NOLIN
bool Registry::Remove(const std::string& name) { bool Registry::Remove(const std::string& name) {
Manager* m = Manager::Global(); Manager* m = Manager::Global();
std::lock_guard<std::mutex>(m->mutex); std::lock_guard<std::mutex> lock(m->mutex);
auto it = m->fmap.find(name); auto it = m->fmap.find(name);
if (it == m->fmap.end()) return false; if (it == m->fmap.end()) return false;
m->fmap.erase(it); m->fmap.erase(it);
...@@ -71,7 +71,7 @@ bool Registry::Remove(const std::string& name) { ...@@ -71,7 +71,7 @@ bool Registry::Remove(const std::string& name) {
const PackedFunc* Registry::Get(const std::string& name) { const PackedFunc* Registry::Get(const std::string& name) {
Manager* m = Manager::Global(); Manager* m = Manager::Global();
std::lock_guard<std::mutex>(m->mutex); std::lock_guard<std::mutex> lock(m->mutex);
auto it = m->fmap.find(name); auto it = m->fmap.find(name);
if (it == m->fmap.end()) return nullptr; if (it == m->fmap.end()) return nullptr;
return &(it->second->func_); return &(it->second->func_);
...@@ -79,7 +79,7 @@ const PackedFunc* Registry::Get(const std::string& name) { ...@@ -79,7 +79,7 @@ const PackedFunc* Registry::Get(const std::string& name) {
std::vector<std::string> Registry::ListNames() { std::vector<std::string> Registry::ListNames() {
Manager* m = Manager::Global(); Manager* m = Manager::Global();
std::lock_guard<std::mutex>(m->mutex); std::lock_guard<std::mutex> lock(m->mutex);
std::vector<std::string> keys; std::vector<std::string> keys;
keys.reserve(m->fmap.size()); keys.reserve(m->fmap.size());
for (const auto &kv : m->fmap) { for (const auto &kv : m->fmap) {
...@@ -101,7 +101,7 @@ ExtTypeVTable* ExtTypeVTable::RegisterInternal( ...@@ -101,7 +101,7 @@ ExtTypeVTable* ExtTypeVTable::RegisterInternal(
int type_code, const ExtTypeVTable& vt) { int type_code, const ExtTypeVTable& vt) {
CHECK(type_code > kExtBegin && type_code < kExtEnd); CHECK(type_code > kExtBegin && type_code < kExtEnd);
Registry::Manager* m = Registry::Manager::Global(); Registry::Manager* m = Registry::Manager::Global();
std::lock_guard<std::mutex>(m->mutex); std::lock_guard<std::mutex> lock(m->mutex);
ExtTypeVTable* pvt = &(m->ext_vtable[type_code]); ExtTypeVTable* pvt = &(m->ext_vtable[type_code]);
pvt[0] = vt; pvt[0] = vt;
return pvt; return pvt;
......
...@@ -650,7 +650,7 @@ std::vector<VulkanContext> GetContext(VkInstance instance) { ...@@ -650,7 +650,7 @@ std::vector<VulkanContext> GetContext(VkInstance instance) {
void VulkanWorkspace::Init() { void VulkanWorkspace::Init() {
if (initialized_) return; if (initialized_) return;
std::lock_guard<std::mutex>(this->mu); std::lock_guard<std::mutex> lock(this->mu);
if (initialized_) return; if (initialized_) return;
initialized_ = true; initialized_ = true;
instance_ = CreateInstance(); instance_ = CreateInstance();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment