cocoa: Change the new sync_dispatch hint to async_dispatch.

This is so the default is safer.
This commit is contained in:
Ryan C. Gordon 2022-08-10 10:48:23 -04:00
parent c6c0a8394e
commit 3119d58ff5
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
2 changed files with 18 additions and 12 deletions

View File

@ -981,13 +981,19 @@ extern "C" {
* \brief A variable controlling whether dispatching OpenGL context updates should block the dispatching thread until the main thread finishes processing
*
* This variable can be set to the following values:
* "0" - Dispatching OpenGL context updates will allow the dispatching thread to continue execution.
* "1" - Dispatching OpenGL context updates will block the dispatching thread until the main thread finishes processing.
* "0" - Dispatching OpenGL context updates will block the dispatching thread until the main thread finishes processing (default).
* "1" - Dispatching OpenGL context updates will allow the dispatching thread to continue execution.
*
* This hint only applies to Mac OS X
* Generally you want the default, but if you have OpenGL code in a background thread on a Mac, and the main thread
* hangs because it's waiting for that background thread, but that background thread is also hanging because it's
* waiting for the main thread to do an update, this might fix your issue.
*
* This hint only applies to macOS.
*
* This hint is available since SDL 2.24.0.
*
*/
#define SDL_HINT_MAC_OPENGL_SYNC_DISPATCH "SDL_MAC_OPENGL_SYNC_DISPATCH"
#define SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH "SDL_MAC_OPENGL_ASYNC_DISPATCH"
/**
* \brief A variable setting the double click radius, in pixels.

View File

@ -44,12 +44,12 @@
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
static SDL_bool SDL_opengl_sync_dispatch = SDL_FALSE;
static SDL_bool SDL_opengl_async_dispatch = SDL_FALSE;
static void SDLCALL
SDL_OpenGLSyncDispatchChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
SDL_OpenGLAsyncDispatchChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
SDL_opengl_sync_dispatch = SDL_GetStringBoolean(hint, SDL_FALSE);
SDL_opengl_async_dispatch = SDL_GetStringBoolean(hint, SDL_FALSE);
}
@implementation SDLOpenGLContext : NSOpenGLContext
@ -63,7 +63,7 @@ SDL_OpenGLSyncDispatchChanged(void *userdata, const char *name, const char *oldV
self->window = NULL;
}
SDL_AddHintCallback(SDL_HINT_MAC_OPENGL_SYNC_DISPATCH, SDL_OpenGLSyncDispatchChanged, NULL);
SDL_AddHintCallback(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, SDL_OpenGLAsyncDispatchChanged, NULL);
return self;
}
@ -147,17 +147,17 @@ SDL_OpenGLSyncDispatchChanged(void *userdata, const char *name, const char *oldV
if ([NSThread isMainThread]) {
[super update];
} else {
if (SDL_opengl_sync_dispatch) {
dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
} else {
if (SDL_opengl_async_dispatch) {
dispatch_async(dispatch_get_main_queue(), ^{ [super update]; });
} else {
dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
}
}
}
- (void)dealloc
{
SDL_DelHintCallback(SDL_HINT_MAC_OPENGL_SYNC_DISPATCH, SDL_OpenGLSyncDispatchChanged, NULL);
SDL_DelHintCallback(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, SDL_OpenGLAsyncDispatchChanged, NULL);
}
@end