diff --git a/src/siadrive_dokan_api/siadokandrive.cpp b/src/siadrive_dokan_api/siadokandrive.cpp index 41ac57e..e807d1d 100644 --- a/src/siadrive_dokan_api/siadokandrive.cpp +++ b/src/siadrive_dokan_api/siadokandrive.cpp @@ -134,7 +134,6 @@ private: ULONG CreateOptions, PDOKAN_FILE_INFO DokanFileInfo) { - std::lock_guard l(_dokanMutex); SECURITY_ATTRIBUTES securityAttrib; securityAttrib.nLength = sizeof(securityAttrib); securityAttrib.lpSecurityDescriptor = SecurityContext->AccessState.SecurityDescriptor; @@ -354,6 +353,7 @@ private: // TODO Detect if file is read-only // TODO Quick hash to detect changes ofi.ReadOnly = false; + std::lock_guard l(_dokanMutex); _openFileMap.insert({ DokanFileInfo->Context, ofi }); /*if (creationDisposition == OPEN_ALWAYS || @@ -389,7 +389,6 @@ private: static NTSTATUS DOKAN_CALLBACK Sia_FindFiles(LPCWSTR FileName, PFillFindData FillFindData, PDOKAN_FILE_INFO DokanFileInfo) { - std::lock_guard l(_dokanMutex); auto siaFileTree = _siaFileTree; if (siaFileTree) { @@ -451,7 +450,6 @@ private: static void DOKAN_CALLBACK Sia_CloseFile(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { - std::lock_guard l(_dokanMutex); ULONG64 id = DokanFileInfo->Context; if (id) { @@ -473,6 +471,8 @@ private: { QueueUploadIfChanged(id, li.QuadPart); } + + std::lock_guard l(_dokanMutex); _openFileMap.erase(id); } @@ -875,7 +875,7 @@ public: ZeroMemory(&_dokanOptions, sizeof(DOKAN_OPTIONS)); _dokanOptions.Version = DOKAN_VERSION; - _dokanOptions.ThreadCount = 4; // use default + _dokanOptions.ThreadCount = 0; // use default _dokanOptions.Options = DOKAN_OPTION_DEBUG; } @@ -902,6 +902,7 @@ public: { while (!DokanRemoveMountPoint(&_mountPoint[0])) ::Sleep(1000); + _uploadManager.reset(nullptr); // HACK - DokanMain() never returns ::TerminateThread(_mountThread->native_handle(), -1); _mountThread->join(); @@ -914,7 +915,6 @@ public: { StopFileListThread(); Unmount(); - _uploadManager.reset(nullptr); _siaApi = nullptr; _siaDriveConfig = nullptr; ZeroMemory(&_dokanOps, sizeof(_dokanOps));