mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-30 19:24:20 +00:00
thread: Reworked SDL_CreateThread to be consistent across platforms.
Also documented missing and weird bits, rename typedefs to fit SDL standards.
This commit is contained in:
@@ -1633,10 +1633,9 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec
|
||||
|
||||
// Start the audio thread if necessary
|
||||
if (!current_audio.impl.ProvidesOwnCallbackThread) {
|
||||
const size_t stacksize = 0; // just take the system default, since audio streams might have callbacks.
|
||||
char threadname[64];
|
||||
SDL_GetAudioThreadName(device, threadname, sizeof (threadname));
|
||||
device->thread = SDL_CreateThreadInternal(device->iscapture ? CaptureAudioThread : OutputAudioThread, threadname, stacksize, device);
|
||||
device->thread = SDL_CreateThread(device->iscapture ? CaptureAudioThread : OutputAudioThread, threadname, device);
|
||||
|
||||
if (!device->thread) {
|
||||
ClosePhysicalAudioDevice(device);
|
||||
|
||||
@@ -952,7 +952,7 @@ static int COREAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
char threadname[64];
|
||||
SDL_GetAudioThreadName(device, threadname, sizeof(threadname));
|
||||
device->hidden->thread = SDL_CreateThreadInternal(AudioQueueThreadEntry, threadname, 0, device);
|
||||
device->hidden->thread = SDL_CreateThread(AudioQueueThreadEntry, threadname, device);
|
||||
if (!device->hidden->thread) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -978,7 +978,7 @@ static void PULSEAUDIO_DetectDevices(SDL_AudioDevice **default_output, SDL_Audio
|
||||
|
||||
// ok, we have a sane list, let's set up hotplug notifications now...
|
||||
SDL_AtomicSet(&pulseaudio_hotplug_thread_active, 1);
|
||||
pulseaudio_hotplug_thread = SDL_CreateThreadInternal(HotplugThread, "PulseHotplug", 256 * 1024, ready_sem); // !!! FIXME: this can probably survive in significantly less stack space.
|
||||
pulseaudio_hotplug_thread = SDL_CreateThreadWithStackSize(HotplugThread, "PulseHotplug", 256 * 1024, ready_sem); // !!! FIXME: this can probably survive in significantly less stack space.
|
||||
SDL_WaitSemaphore(ready_sem);
|
||||
SDL_DestroySemaphore(ready_sem);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ static int InitManagementThread(void)
|
||||
|
||||
SDL_AtomicSetPtr((void **) &ManagementThreadPendingTasks, NULL);
|
||||
SDL_AtomicSet(&ManagementThreadShutdown, 0);
|
||||
ManagementThread = SDL_CreateThreadInternal(ManagementThreadEntry, "SDLWASAPIMgmt", 256 * 1024, &mgmtdata); // !!! FIXME: maybe even smaller stack size?
|
||||
ManagementThread = SDL_CreateThreadWithStackSize(ManagementThreadEntry, "SDLWASAPIMgmt", 256 * 1024, &mgmtdata); // !!! FIXME: maybe even smaller stack size?
|
||||
if (!ManagementThread) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1150,7 +1150,7 @@ SDL_Camera *SDL_OpenCameraDevice(SDL_CameraDeviceID instance_id, const SDL_Camer
|
||||
if (!camera_driver.impl.ProvidesOwnCallbackThread) {
|
||||
char threadname[64];
|
||||
SDL_GetCameraThreadName(device, threadname, sizeof (threadname));
|
||||
device->thread = SDL_CreateThreadInternal(CameraThread, threadname, 0, device);
|
||||
device->thread = SDL_CreateThread(CameraThread, threadname, device);
|
||||
if (!device->thread) {
|
||||
ClosePhysicalCameraDevice(device);
|
||||
ReleaseCameraDevice(device);
|
||||
|
||||
@@ -107,7 +107,7 @@ static int StartBeApp(void *unused)
|
||||
static int StartBeLooper()
|
||||
{
|
||||
if (!be_app) {
|
||||
SDL_AppThread = SDL_CreateThreadInternal(StartBeApp, "SDLApplication", 0, NULL);
|
||||
SDL_AppThread = SDL_CreateThread(StartBeApp, "SDLApplication", NULL);
|
||||
if (!SDL_AppThread) {
|
||||
return SDL_SetError("Couldn't create BApplication thread");
|
||||
}
|
||||
|
||||
@@ -459,7 +459,7 @@ void SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL
|
||||
args->callback = callback;
|
||||
args->userdata = userdata;
|
||||
|
||||
thread = SDL_CreateThreadInternal(windows_file_dialog_thread, "SDL_ShowOpenFileDialog", 0, (void *) args);
|
||||
thread = SDL_CreateThread(windows_file_dialog_thread, "SDL_ShowOpenFileDialog", (void *) args);
|
||||
|
||||
if (thread == NULL) {
|
||||
callback(userdata, NULL, -1);
|
||||
@@ -495,7 +495,7 @@ void SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL
|
||||
args->callback = callback;
|
||||
args->userdata = userdata;
|
||||
|
||||
thread = SDL_CreateThreadInternal(windows_file_dialog_thread, "SDL_ShowSaveFileDialog", 0, (void *) args);
|
||||
thread = SDL_CreateThread(windows_file_dialog_thread, "SDL_ShowSaveFileDialog", (void *) args);
|
||||
|
||||
if (thread == NULL) {
|
||||
callback(userdata, NULL, -1);
|
||||
@@ -528,7 +528,7 @@ void SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void* userdata, S
|
||||
args->default_folder = default_location;
|
||||
args->userdata = userdata;
|
||||
|
||||
thread = SDL_CreateThreadInternal(windows_folder_dialog_thread, "SDL_ShowOpenFolderDialog", 0, (void *) args);
|
||||
thread = SDL_CreateThread(windows_folder_dialog_thread, "SDL_ShowOpenFolderDialog", (void *) args);
|
||||
|
||||
if (thread == NULL) {
|
||||
callback(userdata, NULL, -1);
|
||||
|
||||
@@ -84,8 +84,8 @@ SDL3_0.0.0 {
|
||||
SDL_CreateTexture;
|
||||
SDL_CreateTextureFromSurface;
|
||||
SDL_CreateTextureWithProperties;
|
||||
SDL_CreateThread;
|
||||
SDL_CreateThreadWithStackSize;
|
||||
SDL_CreateThreadRuntime;
|
||||
SDL_CreateThreadWithStackSizeRuntime;
|
||||
SDL_CreateWindow;
|
||||
SDL_CreateWindowAndRenderer;
|
||||
SDL_CreateWindowWithProperties;
|
||||
|
||||
@@ -109,8 +109,8 @@
|
||||
#define SDL_CreateTexture SDL_CreateTexture_REAL
|
||||
#define SDL_CreateTextureFromSurface SDL_CreateTextureFromSurface_REAL
|
||||
#define SDL_CreateTextureWithProperties SDL_CreateTextureWithProperties_REAL
|
||||
#define SDL_CreateThread SDL_CreateThread_REAL
|
||||
#define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL
|
||||
#define SDL_CreateThreadRuntime SDL_CreateThreadRuntime_REAL
|
||||
#define SDL_CreateThreadWithStackSizeRuntime SDL_CreateThreadWithStackSizeRuntime_REAL
|
||||
#define SDL_CreateWindow SDL_CreateWindow_REAL
|
||||
#define SDL_CreateWindowAndRenderer SDL_CreateWindowAndRenderer_REAL
|
||||
#define SDL_CreateWindowWithProperties SDL_CreateWindowWithProperties_REAL
|
||||
|
||||
@@ -46,26 +46,6 @@ SDL_DYNAPI_PROC(int,SDL_sscanf,(const char *a, SDL_SCANF_FORMAT_STRING const cha
|
||||
SDL_DYNAPI_PROC(int,SDL_swprintf,(SDL_OUT_Z_CAP(b) wchar_t *a, size_t b, SDL_PRINTF_FORMAT_STRING const wchar_t *c, ...),(a,b,c),return)
|
||||
#endif
|
||||
|
||||
#ifdef SDL_CreateThread
|
||||
#undef SDL_CreateThread
|
||||
#endif
|
||||
|
||||
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
|
||||
SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThread,(SDL_ThreadFunction a, const char *b, void *c, pfnSDL_CurrentBeginThread d, pfnSDL_CurrentEndThread e),(a,b,c,d,e),return)
|
||||
#else
|
||||
SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThread,(SDL_ThreadFunction a, const char *b, void *c),(a,b,c),return)
|
||||
#endif
|
||||
|
||||
#ifdef SDL_CreateThreadWithStackSize
|
||||
#undef SDL_CreateThreadWithStackSize
|
||||
#endif
|
||||
|
||||
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
|
||||
SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d, pfnSDL_CurrentBeginThread e, pfnSDL_CurrentEndThread f),(a,b,c,d,e,f),return)
|
||||
#else
|
||||
SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d),(a,b,c,d),return)
|
||||
#endif
|
||||
|
||||
/* New API symbols are added at the end */
|
||||
SDL_DYNAPI_PROC(SDL_Surface*,SDL_AcquireCameraFrame,(SDL_Camera *a, Uint64 *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_AddEventWatch,(SDL_EventFilter a, void *b),(a,b),return)
|
||||
@@ -149,6 +129,8 @@ SDL_DYNAPI_PROC(SDL_TLSID,SDL_CreateTLS,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTexture,(SDL_Renderer *a, SDL_PixelFormatEnum b, int c, int d, int e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureFromSurface,(SDL_Renderer *a, SDL_Surface *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureWithProperties,(SDL_Renderer *a, SDL_PropertiesID b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadRuntime,(SDL_ThreadFunction a, const char *b, void *c, SDL_FunctionPointer d, SDL_FunctionPointer e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSizeRuntime,(SDL_ThreadFunction a, const char *b, const size_t c, void *d, SDL_FunctionPointer e, SDL_FunctionPointer f),(a,b,c,d,e,f),return)
|
||||
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindow,(const char *a, int b, int c, SDL_WindowFlags d),(a,b,c,d),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_CreateWindowAndRenderer,(const char *a, int b, int c, SDL_WindowFlags d, SDL_Window **e, SDL_Renderer **f),(a,b,c,d,e,f),return)
|
||||
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindowWithProperties,(SDL_PropertiesID a),(a),return)
|
||||
|
||||
@@ -179,7 +179,7 @@ static void hidapi_thread_create(hidapi_thread_state *state, void *(*func)(void*
|
||||
*/
|
||||
param->func = func;
|
||||
param->func_arg = func_arg;
|
||||
state->thread = SDL_CreateThreadInternal(RunInputThread, "libusb", 0, param);
|
||||
state->thread = SDL_CreateThread(RunInputThread, "libusb", param);
|
||||
}
|
||||
|
||||
static void hidapi_thread_join(hidapi_thread_state *state)
|
||||
|
||||
@@ -156,7 +156,7 @@ static int SDL_HIDAPI_StartRumbleThread(SDL_HIDAPI_RumbleContext *ctx)
|
||||
}
|
||||
|
||||
SDL_AtomicSet(&ctx->running, SDL_TRUE);
|
||||
ctx->thread = SDL_CreateThreadInternal(SDL_HIDAPI_RumbleThread, "HIDAPI Rumble", 0, ctx);
|
||||
ctx->thread = SDL_CreateThread(SDL_HIDAPI_RumbleThread, "HIDAPI Rumble", ctx);
|
||||
if (!ctx->thread) {
|
||||
SDL_HIDAPI_StopRumbleThread(ctx);
|
||||
return -1;
|
||||
|
||||
@@ -286,7 +286,7 @@ static int SDL_StartJoystickThread(void)
|
||||
}
|
||||
|
||||
s_bJoystickThreadQuit = SDL_FALSE;
|
||||
s_joystickThread = SDL_CreateThreadInternal(SDL_JoystickThread, "SDL_joystick", 64 * 1024, NULL);
|
||||
s_joystickThread = SDL_CreateThreadWithStackSize(SDL_JoystickThread, "SDL_joystick", 64 * 1024, NULL);
|
||||
if (!s_joystickThread) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ static int SDL_ANDROID_StartSensorThread(SDL_AndroidSensorThreadContext *ctx)
|
||||
}
|
||||
|
||||
SDL_AtomicSet(&ctx->running, SDL_TRUE);
|
||||
ctx->thread = SDL_CreateThreadInternal(SDL_ANDROID_SensorThread, "Sensors", 0, ctx);
|
||||
ctx->thread = SDL_CreateThread(SDL_ANDROID_SensorThread, "Sensors", ctx);
|
||||
if (!ctx->thread) {
|
||||
SDL_ANDROID_StopSensorThread(ctx);
|
||||
return -1;
|
||||
|
||||
@@ -36,13 +36,9 @@ extern "C" {
|
||||
saves a system-dependent thread id in thread->id, and returns 0
|
||||
on success.
|
||||
*/
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
extern int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread);
|
||||
#else
|
||||
extern int SDL_SYS_CreateThread(SDL_Thread *thread);
|
||||
#endif
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread);
|
||||
|
||||
/* This function does any necessary setup in the child thread */
|
||||
extern void SDL_SYS_SetupThread(const char *name);
|
||||
@@ -64,11 +60,6 @@ extern SDL_TLSData *SDL_SYS_GetTLSData(void);
|
||||
/* 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);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -307,28 +307,22 @@ void SDL_RunThread(SDL_Thread *thread)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SDL_CreateThread
|
||||
#undef SDL_CreateThread
|
||||
#undef SDL_CreateThreadWithStackSize
|
||||
#endif
|
||||
#if SDL_DYNAMIC_API
|
||||
#define SDL_CreateThread SDL_CreateThread_REAL
|
||||
#define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL
|
||||
#endif
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *),
|
||||
SDL_Thread *SDL_CreateThreadWithStackSizeRuntime(SDL_ThreadFunction fn,
|
||||
const char *name, const size_t stacksize, void *data,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread)
|
||||
#else
|
||||
SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *),
|
||||
const char *name, const size_t stacksize, void *data)
|
||||
#endif
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
SDL_Thread *thread;
|
||||
int ret;
|
||||
|
||||
// rather than check this in every backend, just make sure it's correct upfront. Only allow non-NULL if non-WinRT Windows, or Microsoft GDK.
|
||||
#if (!defined(SDL_PLATFORM_WIN32) && !defined(SDL_PLATFORM_GDK)) || defined(SDL_PLATFORM_WINRT)
|
||||
if (pfnBeginThread || pfnEndThread) {
|
||||
SDL_SetError("_beginthreadex/_endthreadex not supported on this platform");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Allocate memory for the thread info structure */
|
||||
thread = (SDL_Thread *)SDL_calloc(1, sizeof(*thread));
|
||||
if (!thread) {
|
||||
@@ -351,11 +345,7 @@ SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *),
|
||||
thread->stacksize = stacksize;
|
||||
|
||||
/* Create the thread and go! */
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
ret = SDL_SYS_CreateThread(thread, pfnBeginThread, pfnEndThread);
|
||||
#else
|
||||
ret = SDL_SYS_CreateThread(thread);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
/* Oops, failed. Gotta free everything */
|
||||
SDL_free(thread->name);
|
||||
@@ -367,31 +357,12 @@ SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *),
|
||||
return thread;
|
||||
}
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
SDL_Thread *SDLCALL SDL_CreateThread(int(SDLCALL *fn)(void *),
|
||||
SDL_Thread *SDL_CreateThreadRuntime(SDL_ThreadFunction fn,
|
||||
const char *name, void *data,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread)
|
||||
#else
|
||||
SDL_Thread *SDLCALL SDL_CreateThread(int(SDLCALL *fn)(void *),
|
||||
const char *name, void *data)
|
||||
#endif
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
return SDL_CreateThreadWithStackSize(fn, name, 0, data, pfnBeginThread, pfnEndThread);
|
||||
#else
|
||||
return SDL_CreateThreadWithStackSize(fn, name, 0, 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
|
||||
return SDL_CreateThreadWithStackSizeRuntime(fn, name, 0, data, pfnBeginThread, pfnEndThread);
|
||||
}
|
||||
|
||||
SDL_ThreadID SDL_GetThreadID(SDL_Thread *thread)
|
||||
|
||||
@@ -24,13 +24,9 @@
|
||||
|
||||
#include "../SDL_systhread.h"
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread)
|
||||
#else
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
#endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
return SDL_SetError("Threads are not supported on this platform");
|
||||
}
|
||||
|
||||
@@ -42,11 +42,10 @@ static void ThreadEntry(void *arg)
|
||||
threadExit(0);
|
||||
}
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
#error "SDL_PASSED_BEGINTHREAD_ENDTHREAD is not supported on N3DS"
|
||||
#endif
|
||||
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
s32 priority = 0x30;
|
||||
int cpu = -1;
|
||||
|
||||
@@ -57,7 +57,9 @@ int CreateUnique(TInt (*aFunc)(const TDesC &aName, TAny *, TAny *), TAny *aPtr1,
|
||||
return status;
|
||||
}
|
||||
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
RThread rthread;
|
||||
|
||||
|
||||
@@ -54,7 +54,9 @@ static int childThread(void *arg)
|
||||
return res;
|
||||
}
|
||||
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
ee_thread_status_t status;
|
||||
ee_thread_t eethread;
|
||||
|
||||
@@ -38,7 +38,9 @@ static int ThreadEntry(SceSize args, void *argp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
SceKernelThreadInfo status;
|
||||
int priority = 32;
|
||||
|
||||
@@ -77,7 +77,9 @@ static int (*ppthread_setname_np)(const char *) = NULL;
|
||||
static SDL_bool checked_setname = SDL_FALSE;
|
||||
static int (*ppthread_setname_np)(pthread_t, const char *) = NULL;
|
||||
#endif
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
pthread_attr_t type;
|
||||
|
||||
|
||||
@@ -41,7 +41,9 @@ static void RunThread(void *args)
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
try {
|
||||
// !!! FIXME: no way to set a thread stack size here.
|
||||
|
||||
@@ -48,7 +48,10 @@ static int ThreadEntry(SceSize args, void *argp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
|
||||
{
|
||||
char thread_name[VITA_THREAD_NAME_MAX];
|
||||
size_t stack_size = VITA_THREAD_STACK_SIZE_DEFAULT;
|
||||
|
||||
@@ -32,20 +32,15 @@
|
||||
#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
|
||||
#endif
|
||||
|
||||
#ifndef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
/* We'll use the C library from this DLL */
|
||||
#include <process.h>
|
||||
typedef uintptr_t(__cdecl *pfnSDL_CurrentBeginThread)(void *, unsigned,
|
||||
unsigned(__stdcall *func)(void*),
|
||||
void *arg, unsigned,
|
||||
unsigned *threadID);
|
||||
typedef void(__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
|
||||
#endif /* !SDL_PASSED_BEGINTHREAD_ENDTHREAD */
|
||||
typedef void (__cdecl * SDL_EndThreadExCallback) (unsigned retval);
|
||||
typedef uintptr_t (__cdecl * SDL_BeginThreadExCallback)
|
||||
(void *security, unsigned stacksize, unsigned (__stdcall *startaddr)(void *),
|
||||
void * arglist, unsigned initflag, unsigned *threadaddr);
|
||||
|
||||
static DWORD RunThread(void *data)
|
||||
{
|
||||
SDL_Thread *thread = (SDL_Thread *)data;
|
||||
pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread)thread->endfunc;
|
||||
SDL_EndThreadExCallback pfnEndThread = (SDL_EndThreadExCallback)thread->endfunc;
|
||||
SDL_RunThread(thread);
|
||||
if (pfnEndThread) {
|
||||
pfnEndThread(0);
|
||||
@@ -63,26 +58,16 @@ static unsigned __stdcall MINGW32_FORCEALIGN RunThreadViaBeginThreadEx(void *dat
|
||||
return (unsigned)RunThread(data);
|
||||
}
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread)
|
||||
SDL_FunctionPointer vpfnBeginThread,
|
||||
SDL_FunctionPointer vpfnEndThread)
|
||||
{
|
||||
#elif defined(SDL_PLATFORM_CYGWIN) || defined(SDL_PLATFORM_WINRT)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
{
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread = NULL;
|
||||
pfnSDL_CurrentEndThread pfnEndThread = NULL;
|
||||
#else
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
{
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread = (pfnSDL_CurrentBeginThread)_beginthreadex;
|
||||
pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread)_endthreadex;
|
||||
#endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
|
||||
SDL_BeginThreadExCallback pfnBeginThread = (SDL_BeginThreadExCallback) vpfnBeginThread;
|
||||
|
||||
const DWORD flags = thread->stacksize ? STACK_SIZE_PARAM_IS_A_RESERVATION : 0;
|
||||
|
||||
/* Save the function which we will have to call to clear the RTL of calling app! */
|
||||
thread->endfunc = (SDL_FunctionPointer)pfnEndThread;
|
||||
thread->endfunc = vpfnEndThread;
|
||||
|
||||
/* thread->stacksize == 0 means "system default", same as win32 expects */
|
||||
if (pfnBeginThread) {
|
||||
|
||||
@@ -221,7 +221,7 @@ int SDL_InitTimers(void)
|
||||
SDL_AtomicSet(&data->active, 1);
|
||||
|
||||
/* Timer threads use a callback into the app, so we can't set a limited stack size here. */
|
||||
data->thread = SDL_CreateThreadInternal(SDL_TimerThread, name, 0, data);
|
||||
data->thread = SDL_CreateThread(SDL_TimerThread, name, data);
|
||||
if (!data->thread) {
|
||||
SDL_QuitTimers();
|
||||
return -1;
|
||||
|
||||
@@ -252,7 +252,7 @@ int PSP_EventInit(SDL_VideoDevice *_this)
|
||||
return SDL_SetError("Can't create input semaphore");
|
||||
}
|
||||
running = 1;
|
||||
if ((thread = SDL_CreateThreadInternal(EventUpdate, "PSPInputThread", 4096, NULL)) == NULL) {
|
||||
if ((thread = SDL_CreateThreadWithStackSize(EventUpdate, "PSPInputThread", 4096, NULL)) == NULL) {
|
||||
return SDL_SetError("Can't create input thread");
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -105,7 +105,7 @@ void WINRT_CycleXAMLThread(void)
|
||||
|
||||
_mutex = SDL_CreateMutex();
|
||||
_threadState = ThreadState_Running;
|
||||
_XAMLThread = SDL_CreateThreadInternal(WINRT_XAMLThreadMain, "SDL/XAML App Thread", 0, nullptr);
|
||||
_XAMLThread = SDL_CreateThread(WINRT_XAMLThreadMain, "SDL/XAML App Thread", nullptr);
|
||||
|
||||
SDL_LockMutex(_mutex);
|
||||
while (_threadState != ThreadState_Yielding) {
|
||||
|
||||
Reference in New Issue
Block a user