Adding lock around access to NewDataRefreshRect to avoid concurrent access to this variable
authorlaurent
Mon, 07 Dec 2009 13:37:27 +0100
changeset 471 ea90da16a5e2
parent 470 cc64bbb1d654
child 472 fecd4f6c01ed
Adding lock around access to NewDataRefreshRect to avoid concurrent access to this variable
Viewer.py
--- a/Viewer.py	Mon Dec 07 09:57:25 2009 +0100
+++ b/Viewer.py	Mon Dec 07 13:37:27 2009 +0100
@@ -23,6 +23,8 @@
 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 import math
+from types import TupleType
+from threading import Lock
 
 import wx
 if wx.VERSION >= (2, 8, 0):
@@ -36,8 +38,6 @@
 from dialogs import *
 from graphics import *
 
-from types import TupleType
-
 SCROLLBAR_UNIT = 10
 WINDOW_BORDER = 10
 SCROLL_ZONE = 10
@@ -525,6 +525,7 @@
             self.SetDropTarget(ViewerDropTarget(self))
         
         self.NewDataRefreshRect = None
+        self.NewDataRefreshRect_lock = Lock()
         
         dc = wx.ClientDC(self)
         font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
@@ -815,14 +816,18 @@
 #-------------------------------------------------------------------------------
 
     def UpdateRefreshRect(self, refresh_rect):
+        self.NewDataRefreshRect_lock.acquire()
         if self.NewDataRefreshRect is None:
             self.NewDataRefreshRect = refresh_rect
         else:
             self.NewDataRefreshRect.Union(refresh_rect)
-
+        self.NewDataRefreshRect_lock.release()
+        
     def RefreshNewData(self):
         if self.NewDataRefreshRect is not None:
+            self.NewDataRefreshRect_lock.acquire()
             refresh_rect, self.NewDataRefreshRect = self.NewDataRefreshRect, None
+            self.NewDataRefreshRect_lock.release()
             self.RefreshRect(self.GetScrolledRect(refresh_rect), False)
         else:
             DebugViewer.RefreshNewData(self)