#185: use guards with private mutexes

Use guard objects to automatically unlock private mutexes when leaving
current scope.
This commit is contained in:
Andrey Prygunkov
2016-03-16 22:37:19 +01:00
parent 65e0238aa2
commit f973388879
17 changed files with 180 additions and 235 deletions

View File

@@ -83,7 +83,7 @@ void Scanner::ServiceWork()
return;
}
m_scanMutex.Lock();
Guard guard(m_scanMutex);
if (m_requestedNzbDirScan ||
(!g_Options->GetPauseScan() && g_Options->GetNzbDirInterval() > 0 &&
@@ -126,8 +126,6 @@ void Scanner::ServiceWork()
m_queueList.clear();
}
m_nzbDirInterval += 200;
m_scanMutex.Unlock();
}
/**
@@ -463,10 +461,11 @@ bool Scanner::AddFileToQueue(const char* filename, const char* nzbName, const ch
void Scanner::ScanNzbDir(bool syncMode)
{
m_scanMutex.Lock();
m_scanning = true;
m_requestedNzbDirScan = true;
m_scanMutex.Unlock();
{
Guard guard(m_scanMutex);
m_scanning = true;
m_requestedNzbDirScan = true;
}
while (syncMode && (m_scanning || m_requestedNzbDirScan))
{
@@ -542,14 +541,13 @@ Scanner::EAddStatus Scanner::AddExternalFile(const char* nzbName, const char* ca
num++;
}
m_scanMutex.Lock();
Guard guard(m_scanMutex);
if (!FileSystem::MoveFile(tempFileName, scanFileName))
{
error("Could not move file %s to %s: %s", *tempFileName, *scanFileName,
*FileSystem::GetLastErrorMessage());
FileSystem::DeleteFile(tempFileName);
m_scanMutex.Unlock(); // UNLOCK
return asFailed;
}
@@ -566,7 +564,7 @@ Scanner::EAddStatus Scanner::AddExternalFile(const char* nzbName, const char* ca
dupeKey, dupeScore, dupeMode, parameters, addTop, addPaused, urlInfo,
&addStatus, nzbId);
m_scanMutex.Unlock();
guard.Release();
ScanNzbDir(true);