Skip to content

Commit

Permalink
Try lock guard instead of direct mutex lock
Browse files Browse the repository at this point in the history
  • Loading branch information
phunkyfish committed Jun 26, 2024
1 parent eb9a0eb commit 94c3bb0
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/stalker/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,19 @@ SError SessionManager::Authenticate()

kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3");

m_authMutex.lock();
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3a");
m_isAuthenticating = true;
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3b");
m_authenticated = false;
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3c");
m_lastUnknownError.clear();
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3d");
m_authMutex.unlock();
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3e");
{
std::lock_guard<std::mutex> guard(m_authMutex);
//m_authMutex.lock();
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3a");
m_isAuthenticating = true;
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3b");
m_authenticated = false;
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3c");
m_lastUnknownError.clear();
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3d");
//m_authMutex.unlock();
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 3e");
}

kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 4");

Expand Down Expand Up @@ -188,13 +191,16 @@ SError SessionManager::Authenticate()

kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 10");

m_authMutex.lock();
{
std::lock_guard<std::mutex> guard(m_authMutex);
//m_authMutex.lock();
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 10a");
m_authenticated = true;
m_authenticated = true;
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 10b");
m_isAuthenticating = false;
m_isAuthenticating = false;
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 10c");
m_authMutex.unlock();
//m_authMutex.unlock();
}

kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::Authenticate 11");

Expand Down Expand Up @@ -266,11 +272,12 @@ void SessionManager::StartWatchdog()
if (err == SERROR_AUTHORIZATION)
{
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::StartWatchdog 3");
m_authMutex.lock();
std::lock_guard<std::mutex> guard(m_authMutex);
//m_authMutex.lock();
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::StartWatchdog 4");
m_authenticated = false;
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::StartWatchdog 5");
m_authMutex.unlock();
// m_authMutex.unlock();
kodi::Log(ADDON_LOG_DEBUG, "ZZ SessionManager::StartWatchdog 6");
}
});
Expand Down

0 comments on commit 94c3bb0

Please sign in to comment.