Browse Source

cocoa: Prevent a deadlock when using SIMPLE_THREADS on macOS

Closes #491
Fixes #490
Donny Lawrence 7 years ago
parent
commit
f29643dd14

+ 2 - 2
panda/src/cocoadisplay/cocoaGraphicsStateGuardian.h

@@ -50,8 +50,8 @@ public:
   FrameBufferProperties _fbprops;
   FrameBufferProperties _fbprops;
 
 
   CVDisplayLinkRef _display_link = nullptr;
   CVDisplayLinkRef _display_link = nullptr;
-  Mutex _swap_lock;
-  ConditionVar _swap_condition;
+  TrueMutexImpl _swap_lock;
+  TrueConditionVarImpl _swap_condition;
   AtomicAdjust::Integer _last_wait_frame = 0;
   AtomicAdjust::Integer _last_wait_frame = 0;
 
 
 protected:
 protected:

+ 4 - 2
panda/src/cocoadisplay/cocoaGraphicsStateGuardian.mm

@@ -37,8 +37,9 @@ display_link_cb(CVDisplayLinkRef link, const CVTimeStamp *now,
                 const CVTimeStamp* output_time, CVOptionFlags flags_in,
                 const CVTimeStamp* output_time, CVOptionFlags flags_in,
                 CVOptionFlags *flags_out, void *context) {
                 CVOptionFlags *flags_out, void *context) {
   CocoaGraphicsStateGuardian *gsg = (CocoaGraphicsStateGuardian *)context;
   CocoaGraphicsStateGuardian *gsg = (CocoaGraphicsStateGuardian *)context;
-  MutexHolder swap_holder(gsg->_swap_lock);
+  gsg->_swap_lock.lock();
   gsg->_swap_condition.notify();
   gsg->_swap_condition.notify();
+  gsg->_swap_lock.unlock();
   return kCVReturnSuccess;
   return kCVReturnSuccess;
 }
 }
 
 
@@ -73,8 +74,9 @@ CocoaGraphicsStateGuardian::
   if (_display_link != nil) {
   if (_display_link != nil) {
     CVDisplayLinkRelease(_display_link);
     CVDisplayLinkRelease(_display_link);
     _display_link = nil;
     _display_link = nil;
-    MutexHolder swap_holder(_swap_lock);
+    _swap_lock.lock();
     _swap_condition.notify();
     _swap_condition.notify();
+    _swap_lock.unlock();
   }
   }
   if (_context != nil) {
   if (_context != nil) {
     [_context clearDrawable];
     [_context clearDrawable];

+ 2 - 1
panda/src/cocoadisplay/cocoaGraphicsWindow.mm

@@ -277,8 +277,9 @@ end_flip() {
     if (_vsync_enabled) {
     if (_vsync_enabled) {
       AtomicAdjust::Integer cur_frame = ClockObject::get_global_clock()->get_frame_count();
       AtomicAdjust::Integer cur_frame = ClockObject::get_global_clock()->get_frame_count();
       if (AtomicAdjust::set(cocoagsg->_last_wait_frame, cur_frame) != cur_frame) {
       if (AtomicAdjust::set(cocoagsg->_last_wait_frame, cur_frame) != cur_frame) {
-        MutexHolder swap_holder(cocoagsg->_swap_lock);
+        cocoagsg->_swap_lock.lock();
         cocoagsg->_swap_condition.wait();
         cocoagsg->_swap_condition.wait();
+        cocoagsg->_swap_lock.unlock();
       }
       }
     }
     }
 
 

+ 13 - 0
panda/src/pipeline/conditionVarImpl.h

@@ -50,4 +50,17 @@ typedef ConditionVarPosixImpl ConditionVarFullImpl;
 
 
 #endif
 #endif
 
 
+#if defined(WIN32_VC)
+#include "conditionVarWin32Impl.h"
+typedef ConditionVarWin32Impl TrueConditionVarImpl;
+
+#elif defined(HAVE_POSIX_THREADS)
+#include "conditionVarPosixImpl.h"
+typedef ConditionVarPosixImpl TrueConditionVarImpl;
+
+#else
+// No true threads, sorry.  Better not try to use 'em.
+
+#endif
+
 #endif
 #endif