Only use pthread_attr_set_qos_class_np if it's available

Noticed in nixOS that DDNet package is marked as broken on Darwin for this reason:
https://github.com/NixOS/nixpkgs/blob/master/pkgs/games/ddnet/default.nix
This commit is contained in:
Dennis Felsing 2022-10-07 16:10:58 +02:00
parent 028ef41a52
commit ccc6cd59de
2 changed files with 6 additions and 2 deletions

View file

@ -3,7 +3,7 @@ if(CMAKE_VERSION VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_VERSION})
endif()
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13 CACHE INTERNAL "")
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13 CACHE INTERNAL "Minimum macOS deployment version")
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.13)
message(WARNING "Building for macOS < 10.13 is not supported")
endif()

View file

@ -53,6 +53,10 @@
#include <Carbon/Carbon.h>
#include <mach-o/dyld.h>
#include <mach/mach_time.h>
#if defined(__MAC_10_10) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10
#include <pthread/qos.h>
#endif
#endif
#elif defined(CONF_FAMILY_WINDOWS)
@ -742,7 +746,7 @@ void *thread_init(void (*threadfunc)(void *), void *u, const char *name)
pthread_t id;
pthread_attr_t attr;
pthread_attr_init(&attr);
#if defined(CONF_PLATFORM_MACOS)
#if defined(CONF_PLATFORM_MACOS) && defined(__MAC_10_10) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10
pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INTERACTIVE, 0);
#endif
int result = pthread_create(&id, &attr, thread_run, data);