From cca6ceec8873a0a9740ecc8f0161c603b561c839 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Tue, 5 Feb 2019 19:30:25 +0100 Subject: [PATCH] Fix the potential uncloseable dialogs if starting a thread failed Signed-off-by: Sven Strickroth --- src/TortoiseProc/AddDlg.cpp | 20 ++++++++++++++------ src/TortoiseProc/ResolveDlg.cpp | 18 +++++++++++++----- src/TortoiseProc/RevertDlg.cpp | 19 ++++++++++++++----- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/TortoiseProc/AddDlg.cpp b/src/TortoiseProc/AddDlg.cpp index d44c916cf..fa5ac89de 100644 --- a/src/TortoiseProc/AddDlg.cpp +++ b/src/TortoiseProc/AddDlg.cpp @@ -1,6 +1,6 @@ -// TortoiseGit - a Windows shell extension for easy version control +// TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2018 - TortoiseGit +// Copyright (C) 2008-2019 - TortoiseGit // Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -92,10 +92,12 @@ BOOL CAddDlg::OnInitDialog() //first start a thread to obtain the file list with the status without //blocking the dialog + InterlockedExchange(&m_bThreadRunning, TRUE); if (!AfxBeginThread(AddThreadEntry, this)) + { + InterlockedExchange(&m_bThreadRunning, FALSE); CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR); - InterlockedExchange(&m_bThreadRunning, TRUE); - + } return TRUE; } @@ -187,8 +189,12 @@ BOOL CAddDlg::PreTranslateMessage(MSG* pMsg) LRESULT CAddDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM) { + InterlockedExchange(&m_bThreadRunning, TRUE); if (!AfxBeginThread(AddThreadEntry, this)) + { + InterlockedExchange(&m_bThreadRunning, FALSE); CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR); + } return 0; } @@ -255,10 +261,12 @@ void CAddDlg::Refresh() { if (!m_bThreadRunning) { + InterlockedExchange(&m_bThreadRunning, TRUE); if (!AfxBeginThread(AddThreadEntry, this)) + { + InterlockedExchange(&m_bThreadRunning, FALSE); CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR); - else - InterlockedExchange(&m_bThreadRunning, TRUE); + } } } diff --git a/src/TortoiseProc/ResolveDlg.cpp b/src/TortoiseProc/ResolveDlg.cpp index aa671863e..7b9209425 100644 --- a/src/TortoiseProc/ResolveDlg.cpp +++ b/src/TortoiseProc/ResolveDlg.cpp @@ -1,6 +1,6 @@ -// TortoiseGit - a Windows shell extension for easy version control +// TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2009-2013, 2015-2018 - TortoiseGit +// Copyright (C) 2009-2013, 2015-2019 - TortoiseGit // Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -84,11 +84,12 @@ BOOL CResolveDlg::OnInitDialog() // first start a thread to obtain the file list with the status without // blocking the dialog + InterlockedExchange(&m_bThreadRunning, TRUE); if (!AfxBeginThread(ResolveThreadEntry, this)) { + InterlockedExchange(&m_bThreadRunning, FALSE); CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR); } - InterlockedExchange(&m_bThreadRunning, TRUE); return TRUE; } @@ -170,10 +171,13 @@ BOOL CResolveDlg::PreTranslateMessage(MSG* pMsg) { if (!m_bThreadRunning) { + InterlockedExchange(&m_bThreadRunning, TRUE); + if (!AfxBeginThread(ResolveThreadEntry, this)) + { + InterlockedExchange(&m_bThreadRunning, FALSE); CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR); - else - InterlockedExchange(&m_bThreadRunning, TRUE); + } } } break; @@ -185,8 +189,12 @@ BOOL CResolveDlg::PreTranslateMessage(MSG* pMsg) LRESULT CResolveDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM) { + InterlockedExchange(&m_bThreadRunning, TRUE); if (!AfxBeginThread(ResolveThreadEntry, this)) + { + InterlockedExchange(&m_bThreadRunning, FALSE); CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR); + } return 0; } diff --git a/src/TortoiseProc/RevertDlg.cpp b/src/TortoiseProc/RevertDlg.cpp index a871b2ec1..054ee1085 100644 --- a/src/TortoiseProc/RevertDlg.cpp +++ b/src/TortoiseProc/RevertDlg.cpp @@ -1,6 +1,6 @@ -// TortoiseGit - a Windows shell extension for easy version control +// TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2009-2013, 2016-2018 - TortoiseGit +// Copyright (C) 2009-2013, 2016-2019 - TortoiseGit // Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -90,9 +90,12 @@ BOOL CRevertDlg::OnInitDialog() // first start a thread to obtain the file list with the status without // blocking the dialog + InterlockedExchange(&m_bThreadRunning, TRUE); if (AfxBeginThread(RevertThreadEntry, this) == nullptr) + { + InterlockedExchange(&m_bThreadRunning, TFALSE); CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR); - InterlockedExchange(&m_bThreadRunning, TRUE); + } return TRUE; } @@ -223,10 +226,12 @@ BOOL CRevertDlg::PreTranslateMessage(MSG* pMsg) { if (!m_bThreadRunning) { + InterlockedExchange(&m_bThreadRunning, TRUE); if (AfxBeginThread(RevertThreadEntry, this) == nullptr) + { + InterlockedExchange(&m_bThreadRunning, FALSE); CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR); - else - InterlockedExchange(&m_bThreadRunning, TRUE); + } } } break; @@ -238,8 +243,12 @@ BOOL CRevertDlg::PreTranslateMessage(MSG* pMsg) LRESULT CRevertDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM) { + InterlockedExchange(&m_bThreadRunning, TRUE); if (AfxBeginThread(RevertThreadEntry, this) == nullptr) + { + InterlockedExchange(&m_bThreadRunning, FALSE); CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR); + } return 0; } -- 2.11.4.GIT