From aef21f4db236d9662b16e4d6ad146ee610f55eb1 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 18 Apr 2017 16:25:55 -0500 Subject: [PATCH] Remove unnecessary thread --- src/siadrive_dokan_api/siadokandrive.cpp | 46 +++--------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/src/siadrive_dokan_api/siadokandrive.cpp b/src/siadrive_dokan_api/siadokandrive.cpp index 8501cb4..f720b83 100644 --- a/src/siadrive_dokan_api/siadokandrive.cpp +++ b/src/siadrive_dokan_api/siadokandrive.cpp @@ -1209,9 +1209,7 @@ private: static DOKAN_OPERATIONS _dokanOps; static DOKAN_OPTIONS _dokanOptions; static FilePath _cacheLocation; - static std::unique_ptr _fileListThread; static HANDLE _fileListStopEvent; - static CSiaFileTreePtr _siaFileTree; static std::mutex _openFileMutex; static std::unique_ptr _mountThread; static NTSTATUS _mountStatus; @@ -1228,7 +1226,9 @@ private: inline static CSiaFileTreePtr GetFileTree() { - return _siaFileTree; + CSiaFileTreePtr siaFileTree; + _siaApi->GetRenter()->GetFileTree(siaFileTree); + return siaFileTree; } template @@ -1408,42 +1408,12 @@ private: } } - static void StartFileListThread() - { - if (!_fileListThread) - { - _fileListStopEvent = ::CreateEvent(nullptr, FALSE, FALSE, nullptr); - _fileListThread.reset(new std::thread([]() - { - do - { - RefreshActiveFileTree(); - } while (::WaitForSingleObject(_fileListStopEvent, 1000) == WAIT_TIMEOUT); - })); - } - } - - static void StopFileListThread() - { - if (_fileListThread) - { - ::SetEvent(_fileListStopEvent); - _fileListThread->join(); - _fileListThread.reset(nullptr); - ::CloseHandle(_fileListStopEvent); - } - } - static void RefreshActiveFileTree(const bool& force = false) { if (force) { _siaApi->GetRenter()->RefreshFileTree(); } - - CSiaFileTreePtr siaFileTree; - _siaApi->GetRenter()->GetFileTree(siaFileTree); - _siaFileTree = siaFileTree; } // Dokan callbacks @@ -1978,15 +1948,12 @@ private: static NTSTATUS DOKAN_CALLBACK Sia_Mounted(PDOKAN_FILE_INFO dokanFileInfo) { - StartFileListThread(); - CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveMounted(_mountPoint))); return STATUS_SUCCESS; } static NTSTATUS DOKAN_CALLBACK Sia_Unmounted(PDOKAN_FILE_INFO dokanFileInfo) { - StopFileListThread(); CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveUnMounted(_mountPoint))); return STATUS_SUCCESS; } @@ -2323,7 +2290,7 @@ private: } else { - filePath.DeleteFile(); + while (!filePath.DeleteFile()); int count = 0; { @@ -2336,7 +2303,7 @@ private: if (count <= 1) { - RefreshActiveFileTree(true); + _siaApi->GetRenter()->RefreshFileTree(); } } } @@ -2704,7 +2671,6 @@ public: static void Shutdown() { _uploadManager.reset(); - StopFileListThread(); Unmount(); _siaApi = nullptr; _siaDriveConfig = nullptr; @@ -2742,9 +2708,7 @@ DOKAN_OPERATIONS DokanImpl::_dokanOps; DOKAN_OPTIONS DokanImpl::_dokanOptions; FilePath DokanImpl::_cacheLocation; HANDLE DokanImpl::_fileListStopEvent; -CSiaFileTreePtr DokanImpl::_siaFileTree; std::mutex DokanImpl::_openFileMutex; -std::unique_ptr DokanImpl::_fileListThread; std::unique_ptr DokanImpl::_mountThread; NTSTATUS DokanImpl::_mountStatus = STATUS_SUCCESS; SString DokanImpl::_mountPoint;