Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock access to rejitters #5757

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tracer/src/Datadog.Tracer.Native/rejit_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ void RejitHandler::Shutdown()
WriteLock w_lock(m_shutdown_lock);
m_shutdown.store(true);

ReadLock r_lock(m_rejitters_lock);

for (auto rejitter : m_rejitters)
{
rejitter->Shutdown();
Expand All @@ -373,6 +375,8 @@ bool RejitHandler::IsShutdownRequested()

void RejitHandler::RegisterRejitter(Rejitter* rejitter)
{
WriteLock w_lock(m_rejitters_lock);

if (m_rejitters.size() == 0)
{
m_rejitters.push_back(rejitter);
Expand Down Expand Up @@ -405,6 +409,8 @@ HRESULT RejitHandler::NotifyReJITParameters(ModuleID moduleId, mdMethodDef metho
// Create the FunctionControlWrapper
FunctionControlWrapper functionControl((ICorProfilerInfo*)m_profilerInfo, moduleId, methodId);

ReadLock r_lock(m_rejitters_lock);

// Call all rejitters sequentially
for (auto rejitter : m_rejitters)
{
Expand Down Expand Up @@ -461,6 +467,8 @@ bool RejitHandler::HasModuleAndMethod(ModuleID moduleId, mdMethodDef methodDef)
return false;
}

ReadLock r_lock(m_rejitters_lock);

for (auto rejitter : m_rejitters)
{
if (rejitter->HasModuleAndMethod(moduleId, methodDef))
Expand All @@ -479,6 +487,8 @@ void RejitHandler::RemoveModule(ModuleID moduleId)
return;
}

ReadLock r_lock(m_rejitters_lock);

for (auto rejitter : m_rejitters)
{
rejitter->RemoveModule(moduleId);
Expand All @@ -492,6 +502,8 @@ void RejitHandler::AddNGenInlinerModule(ModuleID moduleId)
return;
}

ReadLock r_lock(m_rejitters_lock);

for (auto rejitter : m_rejitters)
{
rejitter->AddNGenInlinerModule(moduleId);
Expand Down
1 change: 1 addition & 0 deletions tracer/src/Datadog.Tracer.Native/rejit_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class RejitHandler
private:
std::atomic_bool m_shutdown = {false};
Lock m_shutdown_lock;
Lock m_rejitters_lock;

AssemblyProperty* m_pCorAssemblyProperty = nullptr;

Expand Down
Loading