mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
cocoa: Prevent a deadlock when using SIMPLE_THREADS on macOS
Closes #491 Fixes #490
This commit is contained in:
parent
862906b86d
commit
f29643dd14
@ -50,8 +50,8 @@ public:
|
|||||||
FrameBufferProperties _fbprops;
|
FrameBufferProperties _fbprops;
|
||||||
|
|
||||||
CVDisplayLinkRef _display_link = nullptr;
|
CVDisplayLinkRef _display_link = nullptr;
|
||||||
Mutex _swap_lock;
|
TrueMutexImpl _swap_lock;
|
||||||
ConditionVar _swap_condition;
|
TrueConditionVarImpl _swap_condition;
|
||||||
AtomicAdjust::Integer _last_wait_frame = 0;
|
AtomicAdjust::Integer _last_wait_frame = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -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];
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user