mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 07:04:36 +00:00
Updates SDL to 2.0.5
This commit is contained in:
parent
00a4a21e3f
commit
1e671bfc7a
274 changed files with 11502 additions and 4656 deletions
|
|
@ -60,6 +60,11 @@ extern SDL_TLSData *SDL_SYS_GetTLSData();
|
|||
/* Set the thread local storage for this thread */
|
||||
extern int SDL_SYS_SetTLSData(SDL_TLSData *data);
|
||||
|
||||
/* This is for internal SDL use, so we don't need #ifdefs everywhere. */
|
||||
extern SDL_Thread *
|
||||
SDL_CreateThreadInternal(int (SDLCALL * fn) (void *), const char *name,
|
||||
const size_t stacksize, void *data);
|
||||
|
||||
#endif /* _SDL_systhread_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include "SDL_thread.h"
|
||||
#include "SDL_thread_c.h"
|
||||
#include "SDL_systhread.h"
|
||||
#include "SDL_hints.h"
|
||||
#include "../SDL_error_c.h"
|
||||
|
||||
|
||||
|
|
@ -304,15 +305,15 @@ SDL_RunThread(void *data)
|
|||
#endif
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
DECLSPEC SDL_Thread *SDLCALL
|
||||
SDL_CreateThread(int (SDLCALL * fn) (void *),
|
||||
const char *name, void *data,
|
||||
static SDL_Thread *
|
||||
SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
|
||||
const char *name, const size_t stacksize, void *data,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread)
|
||||
#else
|
||||
DECLSPEC SDL_Thread *SDLCALL
|
||||
SDL_CreateThread(int (SDLCALL * fn) (void *),
|
||||
const char *name, void *data)
|
||||
static SDL_Thread *
|
||||
SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
|
||||
const char *name, const size_t stacksize, void *data)
|
||||
#endif
|
||||
{
|
||||
SDL_Thread *thread;
|
||||
|
|
@ -362,6 +363,8 @@ SDL_CreateThread(int (SDLCALL * fn) (void *),
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
thread->stacksize = stacksize;
|
||||
|
||||
/* Create the thread and go! */
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread);
|
||||
|
|
@ -386,6 +389,50 @@ SDL_CreateThread(int (SDLCALL * fn) (void *),
|
|||
return (thread);
|
||||
}
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
DECLSPEC SDL_Thread *SDLCALL
|
||||
SDL_CreateThread(int (SDLCALL * fn) (void *),
|
||||
const char *name, void *data,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread)
|
||||
#else
|
||||
DECLSPEC SDL_Thread *SDLCALL
|
||||
SDL_CreateThread(int (SDLCALL * fn) (void *),
|
||||
const char *name, void *data)
|
||||
#endif
|
||||
{
|
||||
/* !!! FIXME: in 2.1, just make stackhint part of the usual API. */
|
||||
const char *stackhint = SDL_GetHint(SDL_HINT_THREAD_STACK_SIZE);
|
||||
size_t stacksize = 0;
|
||||
|
||||
/* If the SDL_HINT_THREAD_STACK_SIZE exists, use it */
|
||||
if (stackhint != NULL) {
|
||||
char *endp = NULL;
|
||||
const Sint64 hintval = SDL_strtoll(stackhint, &endp, 10);
|
||||
if ((*stackhint != '\0') && (*endp == '\0')) { /* a valid number? */
|
||||
if (hintval > 0) { /* reject bogus values. */
|
||||
stacksize = (size_t) hintval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
return SDL_CreateThreadWithStackSize(fn, name, stacksize, data, pfnBeginThread, pfnEndThread);
|
||||
#else
|
||||
return SDL_CreateThreadWithStackSize(fn, name, stacksize, data);
|
||||
#endif
|
||||
}
|
||||
|
||||
SDL_Thread *
|
||||
SDL_CreateThreadInternal(int (SDLCALL * fn) (void *), const char *name,
|
||||
const size_t stacksize, void *data) {
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
return SDL_CreateThreadWithStackSize(fn, name, stacksize, data, NULL, NULL);
|
||||
#else
|
||||
return SDL_CreateThreadWithStackSize(fn, name, stacksize, data);
|
||||
#endif
|
||||
}
|
||||
|
||||
SDL_threadID
|
||||
SDL_GetThreadID(SDL_Thread * thread)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ struct SDL_Thread
|
|||
SDL_atomic_t state; /* SDL_THREAD_STATE_* */
|
||||
SDL_error errbuf;
|
||||
char *name;
|
||||
size_t stacksize; /* 0 for default, >0 for user-specified stack size. */
|
||||
void *data;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
|
|||
priority = status.currentPriority;
|
||||
}
|
||||
|
||||
thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry,
|
||||
priority, 0x8000,
|
||||
thread->handle = sceKernelCreateThread(thread->name, ThreadEntry,
|
||||
priority, thread->stacksize ? ((int) thread->stacksize) : 0x8000,
|
||||
PSP_THREAD_ATTR_VFPU, NULL);
|
||||
if (thread->handle < 0) {
|
||||
return SDL_SetError("sceKernelCreateThread() failed");
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@
|
|||
|
||||
#include "SDL_platform.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_hints.h"
|
||||
#include "../SDL_thread_c.h"
|
||||
#include "../SDL_systhread.h"
|
||||
#ifdef __ANDROID__
|
||||
|
|
@ -87,7 +86,6 @@ int
|
|||
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
||||
{
|
||||
pthread_attr_t type;
|
||||
const char *hint = SDL_GetHint(SDL_HINT_THREAD_STACK_SIZE);
|
||||
|
||||
/* do this here before any threads exist, so there's no race condition. */
|
||||
#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
|
||||
|
|
@ -108,12 +106,9 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
|||
}
|
||||
pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
/* If the SDL_HINT_THREAD_STACK_SIZE exists and it seems to be a positive number, use it */
|
||||
if (hint && hint[0] >= '0' && hint[0] <= '9') {
|
||||
const size_t stacksize = (size_t) SDL_atoi(hint);
|
||||
if (stacksize > 0) {
|
||||
pthread_attr_setstacksize(&type, stacksize);
|
||||
}
|
||||
/* Set caller-requested stack size. Otherwise: use the system default. */
|
||||
if (thread->stacksize) {
|
||||
pthread_attr_setstacksize(&type, (size_t) thread->stacksize);
|
||||
}
|
||||
|
||||
/* Create the thread and go! */
|
||||
|
|
@ -127,10 +122,10 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
|||
void
|
||||
SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
#if !defined(__ANDROID__) && !defined(__NACL__)
|
||||
#if !defined(__NACL__)
|
||||
int i;
|
||||
sigset_t mask;
|
||||
#endif /* !__ANDROID__ && !__NACL__ */
|
||||
#endif /* !__NACL__ */
|
||||
|
||||
if (name != NULL) {
|
||||
#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
|
||||
|
|
@ -160,14 +155,14 @@ SDL_SYS_SetupThread(const char *name)
|
|||
}
|
||||
|
||||
/* NativeClient does not yet support signals.*/
|
||||
#if !defined(__ANDROID__) && !defined(__NACL__)
|
||||
#if !defined(__NACL__)
|
||||
/* Mask asynchronous signals for this thread */
|
||||
sigemptyset(&mask);
|
||||
for (i = 0; sig_list[i]; ++i) {
|
||||
sigaddset(&mask, sig_list[i]);
|
||||
}
|
||||
pthread_sigmask(SIG_BLOCK, &mask, 0);
|
||||
#endif /* !__ANDROID__ && !__NACL__ */
|
||||
#endif /* !__NACL__ */
|
||||
|
||||
|
||||
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
|
||||
|
|
@ -204,6 +199,10 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
|||
if (setpriority(PRIO_PROCESS, syscall(SYS_gettid), value) < 0) {
|
||||
/* Note that this fails if you're trying to set high priority
|
||||
and you don't have root permission. BUT DON'T RUN AS ROOT!
|
||||
|
||||
You can grant the ability to increase thread priority by
|
||||
running the following command on your application binary:
|
||||
sudo setcap 'cap_sys_nice=eip' <application>
|
||||
*/
|
||||
return SDL_SetError("setpriority() failed");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ int
|
|||
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
||||
{
|
||||
try {
|
||||
// !!! FIXME: no way to set a thread stack size here.
|
||||
std::thread cpp_thread(RunThread, args);
|
||||
thread->handle = (void *) new std::thread(std::move(cpp_thread));
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
/* Win32 thread management routines for SDL */
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "../SDL_thread_c.h"
|
||||
#include "../SDL_systhread.h"
|
||||
|
|
@ -33,6 +34,10 @@
|
|||
/* We'll use the C library from this DLL */
|
||||
#include <process.h>
|
||||
|
||||
#ifndef STACK_SIZE_PARAM_IS_A_RESERVATION
|
||||
#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
|
||||
#endif
|
||||
|
||||
/* Cygwin gcc-3 ... MingW64 (even with a i386 host) does this like MSVC. */
|
||||
#if (defined(__MINGW32__) && (__GNUC__ < 4))
|
||||
typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
|
||||
|
|
@ -121,6 +126,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
|||
#endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
|
||||
pThreadStartParms pThreadParms =
|
||||
(pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms));
|
||||
const DWORD flags = thread->stacksize ? STACK_SIZE_PARAM_IS_A_RESERVATION : 0;
|
||||
if (!pThreadParms) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
|
@ -129,15 +135,18 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
|||
/* Also save the real parameters we have to pass to thread function */
|
||||
pThreadParms->args = args;
|
||||
|
||||
/* thread->stacksize == 0 means "system default", same as win32 expects */
|
||||
if (pfnBeginThread) {
|
||||
unsigned threadid = 0;
|
||||
thread->handle = (SYS_ThreadHandle)
|
||||
((size_t) pfnBeginThread(NULL, 0, RunThreadViaBeginThreadEx,
|
||||
pThreadParms, 0, &threadid));
|
||||
((size_t) pfnBeginThread(NULL, (unsigned int) thread->stacksize,
|
||||
RunThreadViaBeginThreadEx,
|
||||
pThreadParms, flags, &threadid));
|
||||
} else {
|
||||
DWORD threadid = 0;
|
||||
thread->handle = CreateThread(NULL, 0, RunThreadViaCreateThread,
|
||||
pThreadParms, 0, &threadid);
|
||||
thread->handle = CreateThread(NULL, thread->stacksize,
|
||||
RunThreadViaCreateThread,
|
||||
pThreadParms, flags, &threadid);
|
||||
}
|
||||
if (thread->handle == NULL) {
|
||||
return SDL_SetError("Not enough resources to create thread");
|
||||
|
|
@ -145,9 +154,6 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 0 /* !!! FIXME: revisit this later. See https://bugzilla.libsdl.org/show_bug.cgi?id=2089 */
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4733)
|
||||
#pragma pack(push,8)
|
||||
typedef struct tagTHREADNAME_INFO
|
||||
{
|
||||
|
|
@ -158,48 +164,26 @@ typedef struct tagTHREADNAME_INFO
|
|||
} THREADNAME_INFO;
|
||||
#pragma pack(pop)
|
||||
|
||||
static EXCEPTION_DISPOSITION
|
||||
ignore_exception(void *a, void *b, void *c, void *d)
|
||||
{
|
||||
return ExceptionContinueExecution;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void
|
||||
SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
if (name != NULL) {
|
||||
#if 0 /* !!! FIXME: revisit this later. See https://bugzilla.libsdl.org/show_bug.cgi?id=2089 */
|
||||
#if (defined(_MSC_VER) && defined(_M_IX86))
|
||||
/* This magic tells the debugger to name a thread if it's listening.
|
||||
The inline asm sets up SEH (__try/__except) without C runtime
|
||||
support. See Microsoft Systems Journal, January 1997:
|
||||
http://www.microsoft.com/msj/0197/exception/exception.aspx */
|
||||
INT_PTR handler = (INT_PTR) ignore_exception;
|
||||
if ((name != NULL) && IsDebuggerPresent()) {
|
||||
THREADNAME_INFO inf;
|
||||
|
||||
/* C# and friends will try to catch this Exception, let's avoid it. */
|
||||
if (SDL_GetHintBoolean(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, SDL_FALSE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* This magic tells the debugger to name a thread if it's listening. */
|
||||
SDL_zero(inf);
|
||||
inf.dwType = 0x1000;
|
||||
inf.szName = name;
|
||||
inf.dwThreadID = (DWORD) -1;
|
||||
inf.dwFlags = 0;
|
||||
|
||||
__asm { /* set up SEH */
|
||||
push handler
|
||||
push fs:[0]
|
||||
mov fs:[0],esp
|
||||
}
|
||||
|
||||
/* The program itself should ignore this bogus exception. */
|
||||
RaiseException(0x406D1388, 0, sizeof(inf)/sizeof(DWORD), (DWORD*)&inf);
|
||||
|
||||
__asm { /* tear down SEH. */
|
||||
mov eax,[esp]
|
||||
mov fs:[0], eax
|
||||
add esp, 8
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
/* The debugger catches this, renames the thread, continues on. */
|
||||
RaiseException(0x406D1388, 0, sizeof(inf) / sizeof(ULONG), (const ULONG_PTR*) &inf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -230,11 +214,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
|||
void
|
||||
SDL_SYS_WaitThread(SDL_Thread * thread)
|
||||
{
|
||||
#if __WINRT__
|
||||
WaitForSingleObjectEx(thread->handle, INFINITE, FALSE);
|
||||
#else
|
||||
WaitForSingleObject(thread->handle, INFINITE);
|
||||
#endif
|
||||
CloseHandle(thread->handle);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue