[compiler-rt] [ORC_RT][COFF] add more mutex to internal api (PR #112667)

Wu Yingcong via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 16 23:42:32 PDT 2024


https://github.com/yingcong-wu created https://github.com/llvm/llvm-project/pull/112667

Add more mutex to wherever `JDStates` is used to avoid data race problem.

>From 49f94627ae627a26ade1d566dcb8086d24733ec2 Mon Sep 17 00:00:00 2001
From: "Wu, Yingcong" <yingcong.wu at intel.com>
Date: Wed, 16 Oct 2024 23:00:07 -0700
Subject: [PATCH] add mutext

---
 compiler-rt/lib/orc/coff_platform.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/compiler-rt/lib/orc/coff_platform.cpp b/compiler-rt/lib/orc/coff_platform.cpp
index 49b805a0ec7d31..b3b03596a86536 100644
--- a/compiler-rt/lib/orc/coff_platform.cpp
+++ b/compiler-rt/lib/orc/coff_platform.cpp
@@ -168,6 +168,7 @@ COFFPlatformRuntimeState *COFFPlatformRuntimeState::CPS = nullptr;
 
 COFFPlatformRuntimeState::JITDylibState *
 COFFPlatformRuntimeState::getJITDylibStateByHeader(void *Header) {
+  std::lock_guard<std::recursive_mutex> Lock(JDStatesMutex);
   auto I = JDStates.find(Header);
   if (I == JDStates.end())
     return nullptr;
@@ -176,6 +177,7 @@ COFFPlatformRuntimeState::getJITDylibStateByHeader(void *Header) {
 
 COFFPlatformRuntimeState::JITDylibState *
 COFFPlatformRuntimeState::getJITDylibStateByName(std::string_view Name) {
+  std::lock_guard<std::recursive_mutex> Lock(JDStatesMutex);
   // FIXME: Avoid creating string copy here.
   auto I = JDNameToHeader.find(std::string(Name.data(), Name.size()));
   if (I == JDNameToHeader.end())



More information about the llvm-commits mailing list