diff --git a/Common/Network/FileTransporter/src/FileTransporter_private.h b/Common/Network/FileTransporter/src/FileTransporter_private.h index 300275e8cb..d02b1dde0f 100644 --- a/Common/Network/FileTransporter/src/FileTransporter_private.h +++ b/Common/Network/FileTransporter/src/FileTransporter_private.h @@ -56,8 +56,7 @@ namespace NSNetwork m_cData = NULL; m_nSize = 0; - - m_bIsExit = nullptr; +// m_bIsExit = nullptr; } CFileTransporterBase(const std::wstring &sUploadUrl, const unsigned char* cData, const int nSize) @@ -74,8 +73,7 @@ namespace NSNetwork m_cData = cData; m_nSize = nSize; - - m_bIsExit = nullptr; +// m_bIsExit = nullptr; } CFileTransporterBase(const std::wstring &sUploadUrl, const std::wstring &sUploadFilePath) @@ -92,8 +90,7 @@ namespace NSNetwork m_cData = NULL; m_nSize = 0; - - m_bIsExit = nullptr; +// m_bIsExit = nullptr; } virtual ~CFileTransporterBase () @@ -103,7 +100,7 @@ namespace NSNetwork NSFile::CFileBinary::Remove(m_sDownloadFilePath); m_sDownloadFilePath = L""; } - m_bIsExit = nullptr; +// m_bIsExit = nullptr; } virtual int DownloadFile() = 0; @@ -135,8 +132,9 @@ namespace NSNetwork std::function m_func_onComplete = nullptr; std::function m_func_onProgress = nullptr; + std::function m_check_aborted = nullptr; - std::atomic* m_bIsExit; // Для остановки и выхода потока +// std::atomic* m_bIsExit; // Для остановки и выхода потока }; class CFileTransporter_private : public NSThreads::CBaseThread @@ -228,7 +226,6 @@ namespace NSNetwork virtual DWORD ThreadProc () { m_pInternal->m_bComplete = false; - m_pInternal->m_bIsExit = NSThreads::CBaseThread::m_bIsExit; int hrResultAll = 0; if(m_pInternal->m_eLoadType == m_pInternal->DOWNLOADFILE) diff --git a/Common/Network/FileTransporter/src/FileTransporter_win.cpp b/Common/Network/FileTransporter/src/FileTransporter_win.cpp index 13a75afccf..73ea4321d2 100644 --- a/Common/Network/FileTransporter/src/FileTransporter_win.cpp +++ b/Common/Network/FileTransporter/src/FileTransporter_win.cpp @@ -89,7 +89,7 @@ namespace NSNetwork DeleteUrlCacheEntry(m_sDownloadFileUrl.c_str()); HRESULT hrResultAll = DownloadFileAll(m_sDownloadFileUrl, m_sDownloadFilePath); - if(E_ABORT == hrResultAll && m_bIsExit->load()) + if(E_ABORT == hrResultAll /*&& m_bIsExit->load()*/) { //DeleteUrlCacheEntry(m_sDownloadFileUrl.c_str()); CoUninitialize (); @@ -373,7 +373,7 @@ namespace NSNetwork } DownloadProgress progress; - progress.func_getAborted = std::bind(&CFileTransporterBaseWin::getAborted, this); + progress.func_checkAborted = m_check_aborted; progress.func_onProgress = m_func_onProgress; // Скачиваем файл с возвратом процентов состояния return URLDownloadToFileW (NULL, sFileURL.c_str(), strFileOutput.c_str(), NULL, static_cast(&progress)); @@ -414,7 +414,7 @@ namespace NSNetwork virtual HRESULT __stdcall OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText) { - if(func_getAborted && func_getAborted()) + if(func_checkAborted && func_checkAborted()) { return E_ABORT; } @@ -427,13 +427,10 @@ namespace NSNetwork return S_OK; } - std::function func_getAborted = nullptr; + std::function func_checkAborted = nullptr; std::function func_onProgress = nullptr; }; - bool getAborted() const { - return m_bIsExit && m_bIsExit->load(); - } bool DownloadFilePS(const std::wstring& sFileURL, const std::wstring& strFileOutput) { @@ -489,16 +486,19 @@ namespace NSNetwork CFileTransporter_private::CFileTransporter_private(const std::wstring &sDownloadFileUrl, bool bDelete) : m_pInternal(new CFileTransporterBaseWin(sDownloadFileUrl, bDelete)) { + m_pInternal->m_check_aborted = std::bind(&CBaseThread::isAborted, this);; } CFileTransporter_private::CFileTransporter_private(const std::wstring &sUploadUrl, const unsigned char* cData, const int nSize) : m_pInternal(new CFileTransporterBaseWin(sUploadUrl, cData, nSize)) { + m_pInternal->m_check_aborted = std::bind(&CBaseThread::isAborted, this);; } CFileTransporter_private::CFileTransporter_private(const std::wstring &sUploadUrl, const std::wstring &sUploadFilePath) : m_pInternal(new CFileTransporterBaseWin(sUploadUrl, sUploadFilePath)) { + m_pInternal->m_check_aborted = std::bind(&CBaseThread::isAborted, this);; } } } diff --git a/DesktopEditor/graphics/BaseThread.cpp b/DesktopEditor/graphics/BaseThread.cpp index 55e0043028..3e97765b18 100644 --- a/DesktopEditor/graphics/BaseThread.cpp +++ b/DesktopEditor/graphics/BaseThread.cpp @@ -154,7 +154,6 @@ namespace NSThreads m_lThreadPriority = 0; m_bIsNeedDestroy = false; - m_bIsExit = nullptr; } CBaseThread::~CBaseThread() { @@ -171,7 +170,7 @@ namespace NSThreads m_bRunThread = TRUE; - m_bIsExit = new std::atomic(false); + m_bIsExit.store(false); #if defined(_WIN32) || defined(_WIN64) || defined(_WIN32_WCE) DWORD dwTemp; ((__native_thread*)m_hThread)->m_thread = CreateThread(NULL, 0, &__ThreadProc, (void*)this, 0, &dwTemp); @@ -193,10 +192,11 @@ namespace NSThreads { if (!m_bRunThread) return; + + m_bIsExit.store(true); m_bRunThread = FALSE; Join(); - RELEASEOBJECT(m_bIsExit); RELEASEOBJECT(m_hThread); } void CBaseThread::StopNoJoin() @@ -213,6 +213,7 @@ namespace NSThreads INT CBaseThread::IsSuspended() { return m_bSuspend; } INT CBaseThread::IsRunned() { return m_bRunThread; } int CBaseThread::GetError() { return m_lError; } + bool CBaseThread::isAborted() {return m_bIsExit && m_bIsExit.load();} CThreadDescriptor* CBaseThread::GetDescriptor() { return m_hThread; } int CBaseThread::GetPriority() { return m_lThreadPriority; } @@ -240,12 +241,11 @@ namespace NSThreads if (NULL == m_hThread) return; - m_bIsExit->exchange(true); + m_bIsExit.store(true); m_bRunThread = FALSE; Join(); - RELEASEOBJECT(m_bIsExit); RELEASEOBJECT(m_hThread); } } diff --git a/DesktopEditor/graphics/BaseThread.h b/DesktopEditor/graphics/BaseThread.h index 16ae50c563..ca78ac3a7d 100644 --- a/DesktopEditor/graphics/BaseThread.h +++ b/DesktopEditor/graphics/BaseThread.h @@ -67,7 +67,7 @@ namespace NSThreads int m_lThreadPriority; bool m_bIsNeedDestroy; - std::atomic* m_bIsExit; + std::atomic m_bIsExit{false}; public: CBaseThread(); @@ -83,6 +83,7 @@ namespace NSThreads INT IsSuspended(); INT IsRunned(); + bool isAborted(); int GetError(); CThreadDescriptor* GetDescriptor();