mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-14 13:56:00 +00:00
Define SDL_PLATFORM_* macros instead of underscored ones (#8875)
This commit is contained in:

committed by
GitHub

parent
ceccf24519
commit
31d133db40
@@ -28,7 +28,7 @@
|
||||
|
||||
/* Wrapper around POSIX 1003.1b semaphores */
|
||||
|
||||
#if defined(__MACOS__) || defined(__IOS__)
|
||||
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)
|
||||
/* macOS doesn't support sem_getvalue() as of version 10.4 */
|
||||
#include "../generic/SDL_syssem.c"
|
||||
#else
|
||||
@@ -177,4 +177,4 @@ int SDL_PostSemaphore(SDL_Semaphore *sem)
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* __MACOS__ */
|
||||
#endif /* SDL_PLATFORM_MACOS */
|
||||
|
@@ -29,16 +29,16 @@
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef __LINUX__
|
||||
#ifdef SDL_PLATFORM_LINUX
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../../core/linux/SDL_dbus.h"
|
||||
#endif /* __LINUX__ */
|
||||
#endif /* SDL_PLATFORM_LINUX */
|
||||
|
||||
#if (defined(__LINUX__) || defined(__MACOS__) || defined(__IOS__)) && defined(HAVE_DLOPEN)
|
||||
#if (defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)) && defined(HAVE_DLOPEN)
|
||||
#include <dlfcn.h>
|
||||
#ifndef RTLD_DEFAULT
|
||||
#define RTLD_DEFAULT NULL
|
||||
@@ -47,11 +47,11 @@
|
||||
|
||||
#include "../SDL_thread_c.h"
|
||||
#include "../SDL_systhread.h"
|
||||
#ifdef __ANDROID__
|
||||
#ifdef SDL_PLATFORM_ANDROID
|
||||
#include "../../core/android/SDL_android.h"
|
||||
#endif
|
||||
|
||||
#ifdef __HAIKU__
|
||||
#ifdef SDL_PLATFORM_HAIKU
|
||||
#include <kernel/OS.h>
|
||||
#endif
|
||||
|
||||
@@ -63,17 +63,17 @@ static const int sig_list[] = {
|
||||
|
||||
static void *RunThread(void *data)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
#ifdef SDL_PLATFORM_ANDROID
|
||||
Android_JNI_SetupThread();
|
||||
#endif
|
||||
SDL_RunThread((SDL_Thread *)data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if (defined(__MACOS__) || defined(__IOS__)) && defined(HAVE_DLOPEN)
|
||||
#if (defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)) && defined(HAVE_DLOPEN)
|
||||
static SDL_bool checked_setname = SDL_FALSE;
|
||||
static int (*ppthread_setname_np)(const char *) = NULL;
|
||||
#elif defined(__LINUX__) && defined(HAVE_DLOPEN)
|
||||
#elif defined(SDL_PLATFORM_LINUX) && defined(HAVE_DLOPEN)
|
||||
static SDL_bool checked_setname = SDL_FALSE;
|
||||
static int (*ppthread_setname_np)(pthread_t, const char *) = NULL;
|
||||
#endif
|
||||
@@ -82,12 +82,12 @@ int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
pthread_attr_t type;
|
||||
|
||||
/* do this here before any threads exist, so there's no race condition. */
|
||||
#if (defined(__MACOS__) || defined(__IOS__) || defined(__LINUX__)) && defined(HAVE_DLOPEN)
|
||||
#if (defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_LINUX)) && defined(HAVE_DLOPEN)
|
||||
if (!checked_setname) {
|
||||
void *fn = dlsym(RTLD_DEFAULT, "pthread_setname_np");
|
||||
#if defined(__MACOS__) || defined(__IOS__)
|
||||
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)
|
||||
ppthread_setname_np = (int (*)(const char *))fn;
|
||||
#elif defined(__LINUX__)
|
||||
#elif defined(SDL_PLATFORM_LINUX)
|
||||
ppthread_setname_np = (int (*)(pthread_t, const char *))fn;
|
||||
#endif
|
||||
checked_setname = SDL_TRUE;
|
||||
@@ -119,12 +119,12 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
sigset_t mask;
|
||||
|
||||
if (name) {
|
||||
#if (defined(__MACOS__) || defined(__IOS__) || defined(__LINUX__)) && defined(HAVE_DLOPEN)
|
||||
#if (defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_LINUX)) && defined(HAVE_DLOPEN)
|
||||
SDL_assert(checked_setname);
|
||||
if (ppthread_setname_np) {
|
||||
#if defined(__MACOS__) || defined(__IOS__)
|
||||
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)
|
||||
ppthread_setname_np(name);
|
||||
#elif defined(__LINUX__)
|
||||
#elif defined(SDL_PLATFORM_LINUX)
|
||||
if (ppthread_setname_np(pthread_self(), name) == ERANGE) {
|
||||
char namebuf[16]; /* Limited to 16 char */
|
||||
SDL_strlcpy(namebuf, name, sizeof(namebuf));
|
||||
@@ -133,7 +133,7 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
#endif
|
||||
}
|
||||
#elif defined(HAVE_PTHREAD_SETNAME_NP)
|
||||
#ifdef __NETBSD__
|
||||
#ifdef SDL_PLATFORM_NETBSD
|
||||
pthread_setname_np(pthread_self(), "%s", name);
|
||||
#else
|
||||
if (pthread_setname_np(pthread_self(), name) == ERANGE) {
|
||||
@@ -144,7 +144,7 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
#endif
|
||||
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
|
||||
pthread_set_name_np(pthread_self(), name);
|
||||
#elif defined(__HAIKU__)
|
||||
#elif defined(SDL_PLATFORM_HAIKU)
|
||||
/* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
|
||||
char namebuf[B_OS_NAME_LENGTH];
|
||||
SDL_strlcpy(namebuf, name, sizeof(namebuf));
|
||||
@@ -175,7 +175,7 @@ SDL_ThreadID SDL_GetCurrentThreadID(void)
|
||||
|
||||
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
#ifdef __RISCOS__
|
||||
#ifdef SDL_PLATFORM_RISCOS
|
||||
/* FIXME: Setting thread priority does not seem to be supported */
|
||||
return 0;
|
||||
#else
|
||||
@@ -200,7 +200,7 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
break;
|
||||
case SDL_THREAD_PRIORITY_HIGH:
|
||||
case SDL_THREAD_PRIORITY_TIME_CRITICAL:
|
||||
#if defined(__MACOS__) || defined(__IOS__) || defined(__TVOS__)
|
||||
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS)
|
||||
/* Apple requires SCHED_RR for high priority threads */
|
||||
pri_policy = SCHED_RR;
|
||||
break;
|
||||
@@ -233,7 +233,7 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
policy = pri_policy;
|
||||
}
|
||||
|
||||
#ifdef __LINUX__
|
||||
#ifdef SDL_PLATFORM_LINUX
|
||||
{
|
||||
pid_t linuxTid = syscall(SYS_gettid);
|
||||
return SDL_LinuxSetThreadPriorityAndPolicy(linuxTid, priority, policy);
|
||||
@@ -247,7 +247,7 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
int min_priority = sched_get_priority_min(policy);
|
||||
int max_priority = sched_get_priority_max(policy);
|
||||
|
||||
#if defined(__MACOS__) || defined(__IOS__) || defined(__TVOS__)
|
||||
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS)
|
||||
if (min_priority == 15 && max_priority == 47) {
|
||||
/* Apple has a specific set of thread priorities */
|
||||
if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
||||
@@ -256,7 +256,7 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
sched.sched_priority = 37;
|
||||
}
|
||||
} else
|
||||
#endif /* __MACOS__ || __IOS__ || __TVOS__ */
|
||||
#endif /* SDL_PLATFORM_MACOS || SDL_PLATFORM_IOS || SDL_PLATFORM_TVOS */
|
||||
{
|
||||
sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
|
||||
if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
||||
@@ -269,7 +269,7 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
}
|
||||
return 0;
|
||||
#endif /* linux */
|
||||
#endif /* #if __RISCOS__ */
|
||||
#endif /* #if SDL_PLATFORM_RISCOS */
|
||||
}
|
||||
|
||||
void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
|
@@ -31,7 +31,7 @@ extern "C" {
|
||||
#include <thread>
|
||||
#include <system_error>
|
||||
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
@@ -66,7 +66,7 @@ SDL_SYS_SetupThread(const char *name)
|
||||
extern "C" SDL_ThreadID
|
||||
SDL_GetCurrentThreadID(void)
|
||||
{
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
return GetCurrentThreadId();
|
||||
#else
|
||||
// HACK: Mimic a thread ID, if one isn't otherwise available.
|
||||
@@ -87,7 +87,7 @@ SDL_GetCurrentThreadID(void)
|
||||
extern "C" int
|
||||
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
int value;
|
||||
|
||||
if (priority == SDL_THREAD_PRIORITY_LOW) {
|
||||
|
@@ -56,7 +56,7 @@ typedef struct CONDITION_VARIABLE
|
||||
} CONDITION_VARIABLE, *PCONDITION_VARIABLE;
|
||||
#endif
|
||||
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
#define pWakeConditionVariable WakeConditionVariable
|
||||
#define pWakeAllConditionVariable WakeAllConditionVariable
|
||||
#define pSleepConditionVariableSRW SleepConditionVariableSRW
|
||||
@@ -186,7 +186,7 @@ static const SDL_cond_impl_t SDL_cond_impl_cv = {
|
||||
};
|
||||
|
||||
|
||||
#ifndef __WINRT__
|
||||
#ifndef SDL_PLATFORM_WINRT
|
||||
/* Generic Condition Variable implementation using SDL_Mutex and SDL_Semaphore */
|
||||
static const SDL_cond_impl_t SDL_cond_impl_generic = {
|
||||
&SDL_CreateCondition_generic,
|
||||
@@ -213,7 +213,7 @@ SDL_Condition *SDL_CreateCondition(void)
|
||||
SDL_assert(SDL_mutex_impl_active.Type != SDL_MUTEX_INVALID);
|
||||
}
|
||||
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Link statically on this platform */
|
||||
impl = &SDL_cond_impl_cv;
|
||||
#else
|
||||
|
@@ -39,7 +39,7 @@ SDL_mutex_impl_t SDL_mutex_impl_active = { 0 };
|
||||
* Implementation based on Slim Reader/Writer (SRW) Locks for Win 7 and newer.
|
||||
*/
|
||||
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Functions are guaranteed to be available */
|
||||
#define pInitializeSRWLock InitializeSRWLock
|
||||
#define pReleaseSRWLockExclusive ReleaseSRWLockExclusive
|
||||
@@ -143,7 +143,7 @@ static SDL_Mutex *SDL_CreateMutex_cs(void)
|
||||
if (mutex) {
|
||||
// Initialize
|
||||
// On SMP systems, a non-zero spin count generally helps performance
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
InitializeCriticalSectionEx(&mutex->cs, 2000, 0);
|
||||
#else
|
||||
InitializeCriticalSectionAndSpinCount(&mutex->cs, 2000);
|
||||
@@ -197,7 +197,7 @@ SDL_Mutex *SDL_CreateMutex(void)
|
||||
const SDL_mutex_impl_t *impl = &SDL_mutex_impl_cs;
|
||||
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_WINDOWS_FORCE_MUTEX_CRITICAL_SECTIONS, SDL_FALSE)) {
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
// Link statically on this platform
|
||||
impl = &SDL_mutex_impl_srw;
|
||||
#else
|
||||
|
@@ -35,7 +35,7 @@ typedef VOID(WINAPI *pfnReleaseSRWLockExclusive)(PSRWLOCK);
|
||||
typedef VOID(WINAPI *pfnAcquireSRWLockExclusive)(PSRWLOCK);
|
||||
typedef BOOLEAN(WINAPI *pfnTryAcquireSRWLockExclusive)(PSRWLOCK);
|
||||
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Functions are guaranteed to be available */
|
||||
#define pTryAcquireSRWLockExclusive TryAcquireSRWLockExclusive
|
||||
#define pInitializeSRWLock InitializeSRWLock
|
||||
@@ -163,7 +163,7 @@ static const SDL_rwlock_impl_t SDL_rwlock_impl_srw = {
|
||||
&SDL_UnlockRWLock_srw
|
||||
};
|
||||
|
||||
#ifndef __WINRT__
|
||||
#ifndef SDL_PLATFORM_WINRT
|
||||
|
||||
#include "../generic/SDL_sysrwlock_c.h"
|
||||
|
||||
@@ -184,7 +184,7 @@ SDL_RWLock *SDL_CreateRWLock(void)
|
||||
if (!SDL_rwlock_impl_active.Create) {
|
||||
const SDL_rwlock_impl_t *impl;
|
||||
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Link statically on this platform */
|
||||
impl = &SDL_rwlock_impl_srw;
|
||||
#else
|
||||
|
@@ -61,7 +61,7 @@ static SDL_sem_impl_t SDL_sem_impl_active = { 0 };
|
||||
/* https://www.microsoft.com/en-us/download/details.aspx?id=47328 */
|
||||
|
||||
#if !SDL_WINAPI_FAMILY_PHONE
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Functions are guaranteed to be available */
|
||||
#define pWaitOnAddress WaitOnAddress
|
||||
#define pWakeByAddressSingle WakeByAddressSingle
|
||||
@@ -223,7 +223,7 @@ static SDL_Semaphore *SDL_CreateSemaphore_kern(Uint32 initial_value)
|
||||
if (sem) {
|
||||
/* Create the semaphore, with max value 32K */
|
||||
// !!! FIXME: CreateSemaphoreEx is available in Vista and later, so if XP support is dropped, we can lose this #ifdef.
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS);
|
||||
#else
|
||||
sem->id = CreateSemaphore(NULL, initial_value, 32 * 1024, NULL);
|
||||
@@ -331,7 +331,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
|
||||
#if !SDL_WINAPI_FAMILY_PHONE
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_WINDOWS_FORCE_SEMAPHORE_KERNEL, SDL_FALSE)) {
|
||||
#ifdef __WINRT__
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Link statically on this platform */
|
||||
impl = &SDL_sem_impl_atom;
|
||||
#else
|
||||
|
@@ -68,7 +68,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread)
|
||||
{
|
||||
#elif defined(__CYGWIN__) || defined(__WINRT__)
|
||||
#elif defined(SDL_PLATFORM_CYGWIN) || defined(SDL_PLATFORM_WINRT)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
{
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread = NULL;
|
||||
@@ -124,7 +124,7 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
if (name) {
|
||||
PVOID exceptionHandlerHandle;
|
||||
#ifndef __WINRT__ /* !!! FIXME: There's no LoadLibrary() in WinRT; don't know if SetThreadDescription is available there at all at the moment. */
|
||||
#ifndef SDL_PLATFORM_WINRT /* !!! FIXME: There's no LoadLibrary() in WinRT; don't know if SetThreadDescription is available there at all at the moment. */
|
||||
static pfnSetThreadDescription pSetThreadDescription = NULL;
|
||||
static HMODULE kernel32 = NULL;
|
||||
|
||||
|
Reference in New Issue
Block a user