ecere/gui/Window: Fixed deadlock on reload dialog boxes
authorJerome St-Louis <jerome@ecere.com>
Thu, 8 May 2014 15:25:22 +0000 (11:25 -0400)
committerJerome St-Louis <jerome@ecere.com>
Thu, 8 May 2014 15:48:21 +0000 (11:48 -0400)
- Unlocking GuiApplication prior to deleting a file monitor
- Also avoiding to instantiate FileMonitor for non-document windows, which will also
 avoid the problem that was caused by tooltips being deleted from the IDE's AdjustDebugMenus()
 from within GdbThreadMain() with the guiApp locked, while at the same time the main thread
 had the file monitors mutex locked, waiting for the GuiApp from within a Modal()

ecere/src/gui/Window.ec

index c552c6a..dee431f 100644 (file)
@@ -568,6 +568,16 @@ private:
       OldLink slave;
       ResPtr ptr;
 
+      if(fileMonitor)
+      {
+         int i, lockCount = guiApp.lockMutex.lockCount;
+         for(i = 0; i < lockCount; i++)
+            guiApp.lockMutex.Release();
+         delete fileMonitor;
+         for(i = 0; i < lockCount; i++)
+            guiApp.lockMutex.Wait();
+      }
+
       if(parent)
       {
          stopwatching(parent, font);
@@ -6071,6 +6081,28 @@ private:
       }
    }
 
+   void SetupFileMonitor()
+   {
+      if(!fileMonitor)
+      {
+         fileMonitor = FileMonitor
+         {
+            this, FileChange { modified = true };
+
+            bool OnFileNotify(FileChange action, char * param)
+            {
+               incref this;
+               fileMonitor.StopMonitoring();
+               if(OnFileModified(action, param))
+                  fileMonitor.StartMonitoring();
+               delete this;
+               return true;
+            }
+         };
+         incref fileMonitor;
+      }
+   }
+
 public:
    // normal Methods
    bool Create()
@@ -7330,6 +7362,7 @@ public:
 
    bool MenuFileSave(MenuItem selection, Modifiers mods)
    {
+      SetupFileMonitor();
       if(fileName)
       {
          fileMonitor.fileName = null;
@@ -7360,6 +7393,8 @@ public:
       DialogResult result = (DialogResult)bool::true;
       FileDialog fileDialog = saveDialog;
 
+      SetupFileMonitor();
+
       if(!fileDialog)
          fileDialog = FileDialog {};
       if(fileDialog)
@@ -9085,7 +9120,7 @@ public:
    property bool isDocument
    {
       property_category $"Document"
-      set { style.isDocument = value; }
+      set { style.isDocument = value; if(value) SetupFileMonitor(); }
       get { return style.isDocument; }
    };
 
@@ -9227,6 +9262,8 @@ public:
       property_category $"Document"
       set
       {
+         SetupFileMonitor();
+
          if(menu && ((!fileName && value) || (fileName && !value)))
          {
             MenuItem item = menu.FindItem(MenuFileSave, 0);
@@ -9540,20 +9577,8 @@ private:
    Mutex mutex;
    WindowState lastState;
 
-   FileMonitor fileMonitor
-   {
-      this, FileChange { modified = true };
+   FileMonitor fileMonitor;
 
-      bool OnFileNotify(FileChange action, char * param)
-      {
-         incref this;
-         fileMonitor.StopMonitoring();
-         if(OnFileModified(action, param))
-            fileMonitor.StartMonitoring();
-         delete this;
-         return true;
-      }
-   };
    FontResource setFont, systemFont;
    FontResource usedFont;
    FontResource captionFont;