From 89785c6b72f3e1b70614c18151b603855e4bf969 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 10 Jun 2002 20:42:02 +0000 Subject: [PATCH] Pth threading bug fix --- src/SDL.c | 10 ++++++++++ src/thread/SDL_thread.c | 10 ---------- src/thread/pth/SDL_systhread.c | 3 ++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/SDL.c b/src/SDL.c index cf35b96b9..4aeb04ea1 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -150,6 +150,12 @@ int SDL_InitSubSystem(Uint32 flags) int SDL_Init(Uint32 flags) { +#if !defined(DISABLE_THREADS) && defined(ENABLE_PTH) + if (!pth_init()) { + return -1; + } +#endif + /* Clear the error message */ SDL_ClearError(); @@ -223,6 +229,10 @@ void SDL_Quit(void) /* Uninstall any parachute signal handlers */ SDL_UninstallParachute(); + +#if !defined(DISABLE_THREADS) && defined(ENABLE_PTH) + pth_kill(); +#endif } /* Return the library version number */ diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index 2cb373fa3..d65c4472f 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -52,12 +52,6 @@ int SDL_ThreadsInit(void) { int retval; -#ifdef ENABLE_PTH - if (!pth_init()) { - return -1; - } -#endif - retval = 0; /* Set the thread lock creation flag so that we can reuse an existing lock on the system - since this mutex never gets @@ -86,10 +80,6 @@ void SDL_ThreadsQuit() if ( mutex != NULL ) { SDL_DestroyMutex(mutex); } - -#ifdef ENABLE_PTH - pth_kill(); -#endif } /* Routines for manipulating the thread list */ diff --git a/src/thread/pth/SDL_systhread.c b/src/thread/pth/SDL_systhread.c index 70c25f539..08bb326af 100644 --- a/src/thread/pth/SDL_systhread.c +++ b/src/thread/pth/SDL_systhread.c @@ -64,7 +64,8 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) pth_attr_set(type, PTH_ATTR_JOINABLE, TRUE); /* Create the thread and go! */ - if ( pth_spawn(type, RunThread, args) == NULL ) { + thread->handle = pth_spawn(type, RunThread, args); + if ( thread->handle == NULL ) { SDL_SetError("Not enough resources to create thread"); return(-1); }