The thread ID is an unsigned long so it can hold pthread_t so people can do naughty things with it.

I'm going to be adding additional useful thread API functions, but this should prevent crashes in people's existing code on 64-bit architectures.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404327
This commit is contained in:
Sam Lantinga 2009-12-16 04:48:11 +00:00
parent 83fbb6981f
commit 3f0f9188ed
23 changed files with 53 additions and 51 deletions

View file

@ -159,7 +159,7 @@ SDL_GetErrBuf(void)
errbuf = &SDL_global_error;
if (SDL_Threads) {
int i;
Uint32 this_thread;
SDL_threadID this_thread;
this_thread = SDL_ThreadID();
SDL_mutexP(thread_lock);
@ -292,17 +292,17 @@ SDL_WaitThread(SDL_Thread * thread, int *status)
}
}
Uint32
SDL_threadID
SDL_GetThreadID(SDL_Thread * thread)
{
Uint32 id;
SDL_threadID id;
if (thread) {
id = thread->threadid;
} else {
id = SDL_ThreadID();
}
return (id);
return id;
}
void

View file

@ -50,7 +50,7 @@
/* This is the system-independent thread info structure */
struct SDL_Thread
{
Uint32 threadid;
SDL_threadID threadid;
SYS_ThreadHandle handle;
int status;
SDL_error errbuf;

View file

@ -84,10 +84,10 @@ SDL_SYS_SetupThread(void)
SDL_MaskSignals(NULL);
}
Uint32
SDL_threadID
SDL_ThreadID(void)
{
return ((Uint32) find_thread(NULL));
return ((SDL_threadID) find_thread(NULL));
}
void

View file

@ -30,7 +30,7 @@
struct SDL_mutex
{
int recursive;
Uint32 owner;
SDL_threadID owner;
SDL_sem *sem;
};
@ -76,7 +76,7 @@ SDL_mutexP(SDL_mutex * mutex)
#if SDL_THREADS_DISABLED
return 0;
#else
Uint32 this_thread;
SDL_threadID this_thread;
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");

View file

@ -39,7 +39,7 @@ SDL_SYS_SetupThread(void)
return;
}
Uint32
SDL_threadID
SDL_ThreadID(void)
{
return (0);

View file

@ -64,14 +64,12 @@ SDL_SYS_SetupThread(void)
sigprocmask(SIG_BLOCK, &mask, NULL);
}
/* WARNING: This may not work for systems with 64-bit pid_t */
Uint32
SDL_threadID
SDL_ThreadID(void)
{
return ((Uint32) getpid());
return ((SDL_threadID) getpid());
}
/* WARNING: This may not work for systems with 64-bit pid_t */
void
SDL_WaitThread(SDL_Thread * thread, int *status)
{

View file

@ -38,7 +38,7 @@ static char rcsid =
struct SDL_mutex
{
int recursive;
Uint32 owner;
SDL_threadID owner;
SDL_sem *sem;
};
@ -84,7 +84,7 @@ SDL_mutexP(SDL_mutex * mutex)
#ifdef DISABLE_THREADS
return 0;
#else
Uint32 this_thread;
SDL_threadID this_thread;
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");

View file

@ -44,7 +44,7 @@ SDL_SYS_SetupThread(void)
return;
}
Uint32
SDL_threadID
SDL_ThreadID(void)
{
return (0);

View file

@ -88,11 +88,10 @@ SDL_SYS_SetupThread(void)
pth_cancel_state(PTH_CANCEL_ASYNCHRONOUS, &oldstate);
}
/* WARNING: This may not work for systems with 64-bit pid_t */
Uint32
SDL_threadID
SDL_ThreadID(void)
{
return ((Uint32) pth_self());
return ((SDL_threadID) pth_self());
}
void

View file

@ -38,7 +38,7 @@ static const int sig_list[] = {
/* RISC OS needs to know the main thread for
* it's timer and event processing. */
int riscos_using_threads = 0;
Uint32 riscos_main_thread = 0; /* Thread running events */
SDL_threadID riscos_main_thread = 0; /* Thread running events */
#endif
@ -99,11 +99,10 @@ SDL_SYS_SetupThread(void)
#endif
}
/* WARNING: This may not work for systems with 64-bit pid_t */
Uint32
SDL_threadID
SDL_ThreadID(void)
{
return ((Uint32) pthread_self());
return ((SDL_threadID) pthread_self());
}
void

View file

@ -24,4 +24,5 @@
#include <pthread.h>
typedef pthread_t SYS_ThreadHandle;
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -42,7 +42,7 @@ SDL_SYS_SetupThread(void)
return;
}
Uint32
SDL_threadID
SDL_ThreadID(void)
{
return (0);

View file

@ -151,10 +151,10 @@ SDL_SYS_SetupThread(void)
return;
}
Uint32
SDL_threadID
SDL_ThreadID(void)
{
return ((Uint32) GetCurrentThreadId());
return ((SDL_threadID) GetCurrentThreadId());
}
void

View file

@ -25,4 +25,5 @@
#include <windows.h>
typedef HANDLE SYS_ThreadHandle;
/* vi: set ts=4 sw=4 expandtab: */