Skip to content

Commit

Permalink
Merge pull request ddnet#9146 from Robyt3/Http-Wait-Condition-Lock
Browse files Browse the repository at this point in the history
Ensure lock is held when modifying condition of condition variable
  • Loading branch information
Learath2 authored Oct 13, 2024
2 parents a397688 + 21e0cdd commit 2788f12
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/engine/shared/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ void CHttpRequest::OnCompletionInternal(void *pHandle, unsigned int Result)
// or other threads may try to access the result of a completed HTTP request,
// before the result has been initialized/updated in OnCompletion.
OnCompletion(State);
m_State = State;
{
std::unique_lock WaitLock(m_WaitMutex);
m_State = State;
}
m_WaitCondition.notify_all();
}

Expand Down Expand Up @@ -598,7 +601,10 @@ void CHttp::RunLoop()
goto error_configure;
}

pRequest->m_State = EHttpState::RUNNING;
{
std::unique_lock WaitLock(pRequest->m_WaitMutex);
pRequest->m_State = EHttpState::RUNNING;
}
m_RunningRequests.emplace(pEH, std::move(pRequest));
NewRequests.pop_front();
continue;
Expand Down

0 comments on commit 2788f12

Please sign in to comment.