1
0

Remove unnecessary thread

This commit is contained in:
Scott E. Graves
2017-04-18 16:25:55 -05:00
parent 0a04147eb2
commit aef21f4db2

View File

@@ -1209,9 +1209,7 @@ private:
static DOKAN_OPERATIONS _dokanOps; static DOKAN_OPERATIONS _dokanOps;
static DOKAN_OPTIONS _dokanOptions; static DOKAN_OPTIONS _dokanOptions;
static FilePath _cacheLocation; static FilePath _cacheLocation;
static std::unique_ptr<std::thread> _fileListThread;
static HANDLE _fileListStopEvent; static HANDLE _fileListStopEvent;
static CSiaFileTreePtr _siaFileTree;
static std::mutex _openFileMutex; static std::mutex _openFileMutex;
static std::unique_ptr<std::thread> _mountThread; static std::unique_ptr<std::thread> _mountThread;
static NTSTATUS _mountStatus; static NTSTATUS _mountStatus;
@@ -1228,7 +1226,9 @@ private:
inline static CSiaFileTreePtr GetFileTree() inline static CSiaFileTreePtr GetFileTree()
{ {
return _siaFileTree; CSiaFileTreePtr siaFileTree;
_siaApi->GetRenter()->GetFileTree(siaFileTree);
return siaFileTree;
} }
template<typename T> template<typename T>
@@ -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) static void RefreshActiveFileTree(const bool& force = false)
{ {
if (force) if (force)
{ {
_siaApi->GetRenter()->RefreshFileTree(); _siaApi->GetRenter()->RefreshFileTree();
} }
CSiaFileTreePtr siaFileTree;
_siaApi->GetRenter()->GetFileTree(siaFileTree);
_siaFileTree = siaFileTree;
} }
// Dokan callbacks // Dokan callbacks
@@ -1978,15 +1948,12 @@ private:
static NTSTATUS DOKAN_CALLBACK Sia_Mounted(PDOKAN_FILE_INFO dokanFileInfo) static NTSTATUS DOKAN_CALLBACK Sia_Mounted(PDOKAN_FILE_INFO dokanFileInfo)
{ {
StartFileListThread();
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveMounted(_mountPoint))); CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveMounted(_mountPoint)));
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static NTSTATUS DOKAN_CALLBACK Sia_Unmounted(PDOKAN_FILE_INFO dokanFileInfo) static NTSTATUS DOKAN_CALLBACK Sia_Unmounted(PDOKAN_FILE_INFO dokanFileInfo)
{ {
StopFileListThread();
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveUnMounted(_mountPoint))); CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveUnMounted(_mountPoint)));
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@@ -2323,7 +2290,7 @@ private:
} }
else else
{ {
filePath.DeleteFile(); while (!filePath.DeleteFile());
int count = 0; int count = 0;
{ {
@@ -2336,7 +2303,7 @@ private:
if (count <= 1) if (count <= 1)
{ {
RefreshActiveFileTree(true); _siaApi->GetRenter()->RefreshFileTree();
} }
} }
} }
@@ -2704,7 +2671,6 @@ public:
static void Shutdown() static void Shutdown()
{ {
_uploadManager.reset(); _uploadManager.reset();
StopFileListThread();
Unmount(); Unmount();
_siaApi = nullptr; _siaApi = nullptr;
_siaDriveConfig = nullptr; _siaDriveConfig = nullptr;
@@ -2742,9 +2708,7 @@ DOKAN_OPERATIONS DokanImpl::_dokanOps;
DOKAN_OPTIONS DokanImpl::_dokanOptions; DOKAN_OPTIONS DokanImpl::_dokanOptions;
FilePath DokanImpl::_cacheLocation; FilePath DokanImpl::_cacheLocation;
HANDLE DokanImpl::_fileListStopEvent; HANDLE DokanImpl::_fileListStopEvent;
CSiaFileTreePtr DokanImpl::_siaFileTree;
std::mutex DokanImpl::_openFileMutex; std::mutex DokanImpl::_openFileMutex;
std::unique_ptr<std::thread> DokanImpl::_fileListThread;
std::unique_ptr<std::thread> DokanImpl::_mountThread; std::unique_ptr<std::thread> DokanImpl::_mountThread;
NTSTATUS DokanImpl::_mountStatus = STATUS_SUCCESS; NTSTATUS DokanImpl::_mountStatus = STATUS_SUCCESS;
SString DokanImpl::_mountPoint; SString DokanImpl::_mountPoint;