winemac: Move CVDisplayLink operations out of @synchronized blocks to avoid potential deadlock.

Ken Thomases ken at codeweavers.com
Mon May 8 12:52:02 CDT 2017


The -fire method called by the display link callback also synchronizes on self
(while accessing the windows array).  Display link operations use a lock to
synchronize, too, and it's held while the callback is running.

Signed-off-by: Ken Thomases <ken at codeweavers.com>
---
 dlls/winemac.drv/cocoa_window.m | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m
index 1150322..7cb3459 100644
--- a/dlls/winemac.drv/cocoa_window.m
+++ b/dlls/winemac.drv/cocoa_window.m
@@ -218,22 +218,26 @@ - (void) dealloc
 
     - (void) addWindow:(WineWindow*)window
     {
+        BOOL needsStart;
         @synchronized(self) {
-            BOOL needsStart = !_windows.count;
+            needsStart = !_windows.count;
             [_windows addObject:window];
-            if (needsStart)
-                CVDisplayLinkStart(_link);
         }
+        if (needsStart)
+            CVDisplayLinkStart(_link);
     }
 
     - (void) removeWindow:(WineWindow*)window
     {
+        BOOL shouldStop = FALSE;
         @synchronized(self) {
             BOOL wasRunning = _windows.count > 0;
             [_windows removeObject:window];
             if (wasRunning && !_windows.count)
-                CVDisplayLinkStop(_link);
+                shouldStop = TRUE;
         }
+        if (shouldStop)
+            CVDisplayLinkStop(_link);
     }
 
     - (void) fire
-- 
2.10.2




More information about the wine-patches mailing list