[progress] make CGUIDialogProgressBar::ShowProgressBar/SetCanCancel thread-safe witho...
authorJonathan Marshall <jmarshall@xbmc.org>
Sat, 12 Jul 2014 23:22:10 +0000 (11:22 +1200)
committerJonathan Marshall <jmarshall@xbmc.org>
Mon, 14 Jul 2014 02:21:22 +0000 (14:21 +1200)
xbmc/dialogs/GUIDialogProgress.cpp
xbmc/dialogs/GUIDialogProgress.h

index 9d20a66..36ed16d 100644 (file)
@@ -39,6 +39,7 @@ CGUIDialogProgress::CGUIDialogProgress(void)
   m_iCurrent=0;
   m_iMax=0;
   m_percentage = 0;
+  m_showProgress = false;
   m_bCanCancel = true;
 }
 
@@ -49,13 +50,9 @@ CGUIDialogProgress::~CGUIDialogProgress(void)
 
 void CGUIDialogProgress::SetCanCancel(bool bCanCancel)
 {
+  CSingleLock lock(m_section);
   m_bCanCancel = bCanCancel;
-  CGUIMessage msg(bCanCancel ? GUI_MSG_VISIBLE : GUI_MSG_HIDDEN, GetID(), CONTROL_CANCEL_BUTTON);
-  CSingleTryLock tryLock(g_graphicsContext);
-  if(tryLock.IsOwner())
-    OnMessage(msg);
-  else
-    g_windowManager.SendThreadMessage(msg, GetID());
+  SetInvalid();
 }
 
 void CGUIDialogProgress::StartModal()
@@ -75,9 +72,9 @@ void CGUIDialogProgress::StartModal()
   g_windowManager.RouteToWindow(this);
 
   // active this window...
+  ShowProgressBar(false);
   CGUIMessage msg(GUI_MSG_WINDOW_INIT, 0, 0);
   OnMessage(msg);
-  ShowProgressBar(false);
 
   lock.Leave();
 
@@ -190,12 +187,31 @@ bool CGUIDialogProgress::Abort()
 
 void CGUIDialogProgress::ShowProgressBar(bool bOnOff)
 {
-  CGUIMessage msg(bOnOff ? GUI_MSG_VISIBLE : GUI_MSG_HIDDEN, GetID(), CONTROL_PROGRESS_BAR);
-  CSingleTryLock tryLock(g_graphicsContext);
-  if(tryLock.IsOwner())
-    OnMessage(msg);
-  else
-    g_windowManager.SendThreadMessage(msg, GetID());
+  CSingleLock lock(m_section);
+  m_showProgress = bOnOff;
+  SetInvalid();
+}
+
+void CGUIDialogProgress::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
+{
+  if (m_bInvalidated)
+  { // take a copy to save holding the lock for too long
+    bool showProgress, showCancel;
+    {
+      CSingleLock lock(m_section);
+      showProgress = m_showProgress;
+      showCancel   = m_bCanCancel;
+    }
+    if (showProgress)
+      SET_CONTROL_VISIBLE(CONTROL_PROGRESS_BAR);
+    else
+      SET_CONTROL_HIDDEN(CONTROL_PROGRESS_BAR);
+    if (showCancel)
+      SET_CONTROL_VISIBLE(CONTROL_CANCEL_BUTTON);
+    else
+      SET_CONTROL_HIDDEN(CONTROL_CANCEL_BUTTON);
+  }
+  CGUIDialogBoxBase::Process(currentTime, dirtyregions);
 }
 
 int CGUIDialogProgress::GetDefaultLabelID(int controlId) const
index 984d094..e3d97e6 100644 (file)
@@ -50,6 +50,7 @@ public:
 
 protected:
   virtual int GetDefaultLabelID(int controlId) const;
+  virtual void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions);
 
   bool m_bCanCancel;
   bool m_bCanceled;
@@ -57,4 +58,5 @@ protected:
   int  m_iCurrent;
   int  m_iMax;
   int m_percentage;
+  bool m_showProgress;
 };