Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
#168: unique smart pointers in download-info
Browse files Browse the repository at this point in the history
… only a little bit yet.
  • Loading branch information
hugbug committed Mar 6, 2016
1 parent 9461678 commit 6bae674
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
22 changes: 8 additions & 14 deletions daemon/queue/DownloadInfo.cpp
Expand Up @@ -205,7 +205,6 @@ NzbInfo::NzbInfo() : m_fileList(true)
m_priority = 0;
m_activeDownloads = 0;
m_messages.clear();
m_postInfo = nullptr;
m_idMessageGen = 0;
m_id = ++m_idGen;
m_downloadedSize = 0;
Expand All @@ -227,7 +226,6 @@ NzbInfo::~NzbInfo()
{
debug("Destroying NZBInfo");

delete m_postInfo;
m_fileList.Clear();
}

Expand Down Expand Up @@ -556,14 +554,13 @@ void NzbInfo::CopyFileList(NzbInfo* srcNzbInfo)

void NzbInfo::EnterPostProcess()
{
m_postInfo = new PostInfo();
m_postInfo = std::make_unique<PostInfo>();
m_postInfo->SetNzbInfo(this);
}

void NzbInfo::LeavePostProcess()
{
delete m_postInfo;
m_postInfo = nullptr;
m_postInfo.reset();
ClearMessages();
}

Expand Down Expand Up @@ -809,8 +806,6 @@ FileInfo::~ FileInfo()
{
debug("Destroying FileInfo");

delete m_mutexOutputFile;

ClearArticles();
}

Expand Down Expand Up @@ -862,26 +857,25 @@ void FileInfo::MakeValidFilename()

void FileInfo::LockOutputFile()
{
m_mutexOutputFile->Lock();
m_outputFileMutex->Lock();
}

void FileInfo::UnlockOutputFile()
{
m_mutexOutputFile->Unlock();
m_outputFileMutex->Unlock();
}

void FileInfo::SetActiveDownloads(int activeDownloads)
{
m_activeDownloads = activeDownloads;

if (m_activeDownloads > 0 && !m_mutexOutputFile)
if (m_activeDownloads > 0 && !m_outputFileMutex)
{
m_mutexOutputFile = new Mutex();
m_outputFileMutex = std::make_unique<Mutex>();
}
else if (m_activeDownloads == 0 && m_mutexOutputFile)
else if (m_activeDownloads == 0)
{
delete m_mutexOutputFile;
m_mutexOutputFile = nullptr;
m_outputFileMutex.reset();
}
}

Expand Down
8 changes: 3 additions & 5 deletions daemon/queue/DownloadInfo.h
Expand Up @@ -207,7 +207,7 @@ class FileInfo
int m_completedArticles = 0;
bool m_outputInitialized = false;
CString m_outputFilename;
Mutex* m_mutexOutputFile = nullptr;
std::unique_ptr<Mutex> m_outputFileMutex;
bool m_extraPriority = false;
int m_activeDownloads = 0;
bool m_autoDeleted = false;
Expand Down Expand Up @@ -560,15 +560,13 @@ class NzbInfo
bool GetParFull() { return m_parFull; }
int GetFeedId() { return m_feedId; }
void SetFeedId(int feedId) { m_feedId = feedId; }

void CopyFileList(NzbInfo* srcNzbInfo);
void UpdateMinMaxTime();
PostInfo* GetPostInfo() { return m_postInfo; }
PostInfo* GetPostInfo() { return m_postInfo.get(); }
void EnterPostProcess();
void LeavePostProcess();
bool IsDupeSuccess();
const char* MakeTextStatus(bool ignoreScriptStatus);

void AddMessage(Message::EKind kind, const char* text);
void PrintMessage(Message::EKind kind, const char* format, ...) PRINTF_SYNTAX(3);
int GetMessageCount() { return m_messageCount; }
Expand Down Expand Up @@ -647,7 +645,7 @@ class NzbInfo
Mutex m_logMutex;
MessageList m_messages;
int m_idMessageGen;
PostInfo* m_postInfo;
std::unique_ptr<PostInfo> m_postInfo;
int64 m_downloadedSize;
time_t m_downloadStartTime;
int m_downloadSec;
Expand Down

0 comments on commit 6bae674

Please sign in to comment.