1.3 API CHANGE: Add support for naming threads.
--HG-- extra : rebase_source : ae532d4b4d68ef86de0fc2cb6794a622e0841bce
This commit is contained in:
parent
dead491b27
commit
0863dee582
22 changed files with 183 additions and 45 deletions
|
@ -188,25 +188,19 @@ typedef struct
|
|||
void
|
||||
SDL_RunThread(void *data)
|
||||
{
|
||||
thread_args *args;
|
||||
int (SDLCALL * userfunc) (void *);
|
||||
void *userdata;
|
||||
int *statusloc;
|
||||
thread_args *args = (thread_args *) data;
|
||||
int (SDLCALL * userfunc) (void *) = args->func;
|
||||
void *userdata = args->data;
|
||||
int *statusloc = &args->info->status;
|
||||
|
||||
/* Perform any system-dependent setup
|
||||
- this function cannot fail, and cannot use SDL_SetError()
|
||||
*/
|
||||
SDL_SYS_SetupThread();
|
||||
SDL_SYS_SetupThread(args->info->name);
|
||||
|
||||
/* Get the thread id */
|
||||
args = (thread_args *) data;
|
||||
args->info->threadid = SDL_ThreadID();
|
||||
|
||||
/* Figure out what function to run */
|
||||
userfunc = args->func;
|
||||
userdata = args->data;
|
||||
statusloc = &args->info->status;
|
||||
|
||||
/* Wake up the parent thread */
|
||||
SDL_SemPost(args->wait);
|
||||
|
||||
|
@ -217,12 +211,14 @@ SDL_RunThread(void *data)
|
|||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
#undef SDL_CreateThread
|
||||
DECLSPEC SDL_Thread *SDLCALL
|
||||
SDL_CreateThread(int (SDLCALL * fn) (void *), void *data,
|
||||
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 *), void *data)
|
||||
SDL_CreateThread(int (SDLCALL * fn) (void *),
|
||||
const char *name, void *data)
|
||||
#endif
|
||||
{
|
||||
SDL_Thread *thread;
|
||||
|
@ -238,10 +234,21 @@ SDL_CreateThread(int (SDLCALL * fn) (void *), void *data)
|
|||
SDL_memset(thread, 0, (sizeof *thread));
|
||||
thread->status = -1;
|
||||
|
||||
/* Set up the arguments for the thread */
|
||||
if (name != NULL) {
|
||||
thread->name = SDL_strdup(name);
|
||||
if (thread->name == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(thread);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set up the arguments for the thread */
|
||||
args = (thread_args *) SDL_malloc(sizeof(*args));
|
||||
if (args == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(thread->name);
|
||||
SDL_free(thread);
|
||||
return (NULL);
|
||||
}
|
||||
|
@ -250,6 +257,7 @@ SDL_CreateThread(int (SDLCALL * fn) (void *), void *data)
|
|||
args->info = thread;
|
||||
args->wait = SDL_CreateSemaphore(0);
|
||||
if (args->wait == NULL) {
|
||||
SDL_free(thread->name);
|
||||
SDL_free(thread);
|
||||
SDL_free(args);
|
||||
return (NULL);
|
||||
|
@ -270,6 +278,7 @@ SDL_CreateThread(int (SDLCALL * fn) (void *), void *data)
|
|||
} else {
|
||||
/* Oops, failed. Gotta free everything */
|
||||
SDL_DelThread(thread);
|
||||
SDL_free(thread->name);
|
||||
SDL_free(thread);
|
||||
thread = NULL;
|
||||
}
|
||||
|
@ -293,6 +302,12 @@ SDL_GetThreadID(SDL_Thread * thread)
|
|||
return id;
|
||||
}
|
||||
|
||||
const char *
|
||||
SDL_GetThreadName(SDL_Thread * thread)
|
||||
{
|
||||
return thread->name;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
|
@ -308,6 +323,7 @@ SDL_WaitThread(SDL_Thread * thread, int *status)
|
|||
*status = thread->status;
|
||||
}
|
||||
SDL_DelThread(thread);
|
||||
SDL_free(thread->name);
|
||||
SDL_free(thread);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue