Change to using a recursive_mutex for now

Based on discussions, preferring easier code readability,
maintenance, debugging until we do perf testing. Also consistency
with existing codebase for similar scenarios
This commit is contained in:
Pooja Trivedi 2025-12-09 16:33:55 -05:00
parent c614d36fc9
commit d7f3e27992
2 changed files with 6 additions and 12 deletions

View File

@ -71,9 +71,9 @@ HRESULT WSLAContainer::Start()
HRESULT WSLAContainer::Stop(int Signal, ULONG TimeoutMs)
try
{
std::lock_guard lock{m_lock};
std::lock_guard<std::recursive_mutex> lock(m_lock);
if (StateNoLock() == WslaContainerStateExited)
if (State() == WslaContainerStateExited)
{
return S_OK;
}
@ -109,12 +109,12 @@ CATCH_RETURN();
HRESULT WSLAContainer::Delete()
try
{
std::lock_guard lock{m_lock};
std::lock_guard<std::recursive_mutex> lock(m_lock);
// Validate that the container is in the exited state.
RETURN_HR_IF_MSG(
HRESULT_FROM_WIN32(ERROR_INVALID_STATE),
m_state != WslaContainerStateExited,
State() != WslaContainerStateExited,
"Cannot delete container '%hs', state: %i",
m_name.c_str(),
m_state);
@ -130,14 +130,8 @@ CATCH_RETURN();
WSLA_CONTAINER_STATE WSLAContainer::State() noexcept
{
std::lock_guard lock{m_lock};
std::lock_guard<std::recursive_mutex> lock(m_lock);
// If the container is running, refresh the init process state before returning.
return StateNoLock();
}
WSLA_CONTAINER_STATE WSLAContainer::StateNoLock() noexcept
{
// If the container is running, refresh the init process state before returning.
if (m_state == WslaContainerStateRunning && m_containerProcess.State() != WSLAProcessStateRunning)
{

View File

@ -48,7 +48,7 @@ private:
std::string m_image;
WSLA_CONTAINER_STATE m_state = WslaContainerStateInvalid;
WSLAVirtualMachine* m_parentVM = nullptr;
std::mutex m_lock;
std::recursive_mutex m_lock;
WSLA_CONTAINER_STATE StateNoLock() noexcept;
static std::vector<std::string> PrepareNerdctlRunCommand(const WSLA_CONTAINER_OPTIONS& options, std::vector<std::string>&& inputOptions);