-
-
Notifications
You must be signed in to change notification settings - Fork 62
Fix MacOSX deadlock by locking mutex in drawRect instead of holding across threads #576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
abf42d7
c3cd139
41f0383
cc54fc4
cd9381c
1ce49e5
fb9b78a
132c6d4
896ff25
8f1f2cf
bf2eaab
f4480f5
ca0748f
007967b
051bbf8
66f2ddd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| #include <cairo/cairo-quartz.h> | ||
| #include <iostream> | ||
| #include <exception> | ||
| #include <mutex> | ||
| #include "minsky_epilogue.h" | ||
|
|
||
| using namespace std; | ||
|
|
@@ -100,13 +101,20 @@ namespace minsky | |
| void NSContext::requestRedraw() | ||
| { | ||
| [impl->cairoView setNeedsDisplay: true]; | ||
| // Force the view to display immediately instead of waiting for the next event loop | ||
| [impl->cairoView displayIfNeeded]; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @implementation CairoView | ||
| -(void) drawRect: (NSRect)rect | ||
| { | ||
| // Lock the mutex when actually drawing, not before | ||
| std::optional<std::lock_guard<std::recursive_mutex>> lock; | ||
| if (winfo->cmdMutex) | ||
| lock.emplace(*winfo->cmdMutex); | ||
|
Comment on lines
+113
to
+116
|
||
|
|
||
| auto context = [[NSGraphicsContext currentContext] CGContext]; | ||
| auto frame=[self frame]; | ||
| CGContextTranslateCTM(context,winfo->offsetLeft,winfo->childHeight+(winfo->hasScrollBars?20:0)); | ||
|
|
@@ -116,7 +124,7 @@ namespace minsky | |
| cairo_surface_set_device_offset(winfo->bufferSurface->surface(), 0, 20); | ||
| winfo->draw(); | ||
| winfo->bufferSurface.reset(); | ||
| winfo->lock.reset(); // unlock any mutex attached to this window | ||
| // lock will be automatically released when it goes out of scope | ||
| } | ||
| - (NSView *) hitTest: (NSPoint) aPoint | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to
nativeWindowsToRedraw.clear()on line 291 is redundant and potentially incorrect. Line 287 already moves the contents ofnativeWindowsToRedrawinto the localwindowsvariable viaswap(), leavingnativeWindowsToRedrawempty. This clear operation has no effect. If new windows are added tonativeWindowsToRedrawbetween the swap (line 287) and this clear (line 291), they would be incorrectly discarded.