Jelajahi Sumber

fixes #1196 - Filewatcher no longer gets stuck in read()

TheComet 10 tahun lalu
induk
melakukan
a48f0e57ad
1 mengubah file dengan 8 tambahan dan 2 penghapusan
  1. 8 2
      Source/Urho3D/IO/FileWatcher.cpp

+ 8 - 2
Source/Urho3D/IO/FileWatcher.cpp

@@ -195,14 +195,17 @@ void FileWatcher::StopWatching()
         shouldRun_ = false;
 
         // Create and delete a dummy file to make sure the watcher loop terminates
+        // This is not required with iNotify
+#if !defined(__linux__)
         String dummyFileName = path_ + "dummy.tmp";
         File file(context_, dummyFileName, FILE_WRITE);
         file.Close();
         if (fileSystem_)
             fileSystem_->Delete(dummyFileName);
+#endif
 
-        Stop();
-
+        // Remove watch - On linux this will cause read() to return with
+        // the IN_IGNORED flag set
 #ifdef _WIN32
         CloseHandle((HANDLE)dirHandle_);
 #elif defined(__linux__)
@@ -212,6 +215,9 @@ void FileWatcher::StopWatching()
 #elif defined(__APPLE__) && !defined(IOS)
         CloseFileWatcher(watcher_);
 #endif
+        // Join thread *after* removing watch as to avoid getting stuck in
+        // read()
+        Stop();
 
         URHO3D_LOGDEBUG("Stopped watching path " + path_);
         path_.Clear();