From dec7875a6e23212021e4d9080330a42832dfe02a Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Tue, 15 Jun 2021 01:40:19 +0000
Subject: [PATCH] update SDL soruce to 2.0.14
---
source/src/thread/SDL_thread.c | 72 +++++++-----------------------------
1 files changed, 14 insertions(+), 58 deletions(-)
diff --git a/source/src/thread/SDL_thread.c b/source/src/thread/SDL_thread.c
index c53ddcd..5757ba0 100644
--- a/source/src/thread/SDL_thread.c
+++ b/source/src/thread/SDL_thread.c
@@ -22,7 +22,6 @@
/* System independent thread management routines for SDL */
-#include "SDL_assert.h"
#include "SDL_thread.h"
#include "SDL_thread_c.h"
#include "SDL_systhread.h"
@@ -258,22 +257,12 @@
}
-/* Arguments and callback to setup and run the user thread function */
-typedef struct
-{
- int (SDLCALL * func) (void *);
- void *data;
- SDL_Thread *info;
- SDL_sem *wait;
-} thread_args;
-
void
-SDL_RunThread(void *data)
+SDL_RunThread(SDL_Thread *thread)
{
- thread_args *args = (thread_args *) data;
- int (SDLCALL * userfunc) (void *) = args->func;
- void *userdata = args->data;
- SDL_Thread *thread = args->info;
+ void *userdata = thread->userdata;
+ int (SDLCALL * userfunc) (void *) = thread->userfunc;
+
int *statusloc = &thread->status;
/* Perform any system-dependent setup - this function may not fail */
@@ -281,9 +270,6 @@
/* Get the thread id */
thread->threadid = SDL_ThreadID();
-
- /* Wake up the parent thread */
- SDL_SemPost(args->wait);
/* Run the function */
*statusloc = userfunc(userdata);
@@ -325,16 +311,14 @@
#endif
{
SDL_Thread *thread;
- thread_args *args;
int ret;
/* Allocate memory for the thread info structure */
- thread = (SDL_Thread *) SDL_malloc(sizeof(*thread));
+ thread = (SDL_Thread *) SDL_calloc(1, sizeof(*thread));
if (thread == NULL) {
SDL_OutOfMemory();
- return (NULL);
+ return NULL;
}
- SDL_zerop(thread);
thread->status = -1;
SDL_AtomicSet(&thread->state, SDL_THREAD_STATE_ALIVE);
@@ -344,57 +328,29 @@
if (thread->name == NULL) {
SDL_OutOfMemory();
SDL_free(thread);
- return (NULL);
+ return NULL;
}
}
- /* Set up the arguments for the thread */
- args = (thread_args *) SDL_malloc(sizeof(*args));
- if (args == NULL) {
- SDL_OutOfMemory();
- if (thread->name) {
- SDL_free(thread->name);
- }
- SDL_free(thread);
- return (NULL);
- }
- args->func = fn;
- args->data = data;
- args->info = thread;
- args->wait = SDL_CreateSemaphore(0);
- if (args->wait == NULL) {
- if (thread->name) {
- SDL_free(thread->name);
- }
- SDL_free(thread);
- SDL_free(args);
- return (NULL);
- }
-
+ thread->userfunc = fn;
+ thread->userdata = data;
thread->stacksize = stacksize;
/* Create the thread and go! */
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
- ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread);
+ ret = SDL_SYS_CreateThread(thread, pfnBeginThread, pfnEndThread);
#else
- ret = SDL_SYS_CreateThread(thread, args);
+ ret = SDL_SYS_CreateThread(thread);
#endif
- if (ret >= 0) {
- /* Wait for the thread function to use arguments */
- SDL_SemWait(args->wait);
- } else {
+ if (ret < 0) {
/* Oops, failed. Gotta free everything */
- if (thread->name) {
- SDL_free(thread->name);
- }
+ SDL_free(thread->name);
SDL_free(thread);
thread = NULL;
}
- SDL_DestroySemaphore(args->wait);
- SDL_free(args);
/* Everything is running now */
- return (thread);
+ return thread;
}
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
--
Gitblit v1.9.3