From c188729b12db1d8fe6c9b99714af47a74e7dda3a Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 2 Aug 2012 02:57:55 -0400 Subject: [PATCH] Backport from default branch: clean up the thread ID mess in platform_unix. Backported from hg changeset f254870dd7dd. --- physfs.c | 4 ++-- physfs_internal.h | 8 ++++---- platform/beos.cpp | 4 ++-- platform/macosx.c | 4 ++-- platform/os2.c | 4 ++-- platform/pocketpc.c | 4 ++-- platform/unix.c | 21 +++------------------ platform/windows.c | 4 ++-- 8 files changed, 19 insertions(+), 34 deletions(-) diff --git a/physfs.c b/physfs.c index f689d446..3ab031d7 100644 --- a/physfs.c +++ b/physfs.c @@ -43,7 +43,7 @@ typedef struct __PHYSFS_FILEHANDLE__ typedef struct __PHYSFS_ERRMSGTYPE__ { - PHYSFS_uint64 tid; + void *tid; int errorAvailable; char errorString[80]; struct __PHYSFS_ERRMSGTYPE__ *next; @@ -269,7 +269,7 @@ void __PHYSFS_sort(void *entries, PHYSFS_uint32 max, static ErrMsg *findErrorForCurrentThread(void) { ErrMsg *i; - PHYSFS_uint64 tid; + void *tid; if (errorLock != NULL) __PHYSFS_platformGrabMutex(errorLock); diff --git a/physfs_internal.h b/physfs_internal.h index b610aed6..9e83a7eb 100644 --- a/physfs_internal.h +++ b/physfs_internal.h @@ -1305,12 +1305,12 @@ char *__PHYSFS_platformGetUserName(void); char *__PHYSFS_platformGetUserDir(void); /* - * Return a number that uniquely identifies the current thread. - * On a platform without threading, (1) will suffice. These numbers are + * Return a pointer that uniquely identifies the current thread. + * On a platform without threading, (0x1) will suffice. These numbers are * arbitrary; the only requirement is that no two threads have the same - * number. + * pointer. */ -PHYSFS_uint64 __PHYSFS_platformGetThreadID(void); +void *__PHYSFS_platformGetThreadID(void); /* * Return non-zero if filename (in platform-dependent notation) exists. diff --git a/platform/beos.cpp b/platform/beos.cpp index 414b2729..ee7b1908 100644 --- a/platform/beos.cpp +++ b/platform/beos.cpp @@ -197,9 +197,9 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) } /* __PHYSFS_platformCalcBaseDir */ -PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) +void *__PHYSFS_platformGetThreadID(void) { - return((PHYSFS_uint64) find_thread(NULL)); + return((void *) find_thread(NULL)); } /* __PHYSFS_platformGetThreadID */ diff --git a/platform/macosx.c b/platform/macosx.c index 942928ed..a483994b 100644 --- a/platform/macosx.c +++ b/platform/macosx.c @@ -376,9 +376,9 @@ int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a) } /* __PHYSFS_platformSetDefaultAllocator */ -PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) +void *__PHYSFS_platformGetThreadID(void) { - return( (PHYSFS_uint64) ((size_t) MPCurrentTaskID()) ); + return( (void *) ((size_t) MPCurrentTaskID()) ); } /* __PHYSFS_platformGetThreadID */ diff --git a/platform/os2.c b/platform/os2.c index 3a6b0d8b..3372ca35 100644 --- a/platform/os2.c +++ b/platform/os2.c @@ -649,7 +649,7 @@ PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname) } /* __PHYSFS_platformGetLastModTime */ -PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) +void *__PHYSFS_platformGetThreadID(void) { PTIB ptib; PPIB ppib; @@ -659,7 +659,7 @@ PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) * default value (zero might as well do) if it does. */ BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, 0, 0); - return((PHYSFS_uint64) ptib->tib_ordinal); + return((void *) ptib->tib_ordinal); } /* __PHYSFS_platformGetThreadID */ diff --git a/platform/pocketpc.c b/platform/pocketpc.c index e1387fdb..c49c0cf0 100644 --- a/platform/pocketpc.c +++ b/platform/pocketpc.c @@ -161,9 +161,9 @@ char *__PHYSFS_platformGetUserDir(void) } /* __PHYSFS_platformGetUserDir */ -PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) +void *__PHYSFS_platformGetThreadID(void) { - return(1); /* single threaded. */ + return((void *)1); /* single threaded. */ } /* __PHYSFS_platformGetThreadID */ diff --git a/platform/unix.c b/platform/unix.c index 4e714b40..093e7ebf 100644 --- a/platform/unix.c +++ b/platform/unix.c @@ -342,7 +342,7 @@ int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a) #if (defined PHYSFS_NO_THREAD_SUPPORT) -PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) { return(0x0001); } +void *__PHYSFS_platformGetThreadID(void) { return((void *) 0x0001); } void *__PHYSFS_platformCreateMutex(void) { return((void *) 0x0001); } void __PHYSFS_platformDestroyMutex(void *mutex) {} int __PHYSFS_platformGrabMutex(void *mutex) { return(1); } @@ -357,24 +357,9 @@ typedef struct PHYSFS_uint32 count; } PthreadMutex; -/* Just in case; this is a panic value. */ -#if ((!defined SIZEOF_INT) || (SIZEOF_INT <= 0)) -# define SIZEOF_INT 4 -#endif - -#if (SIZEOF_INT == 4) -# define PHTREAD_TO_UI64(thr) ( (PHYSFS_uint64) ((PHYSFS_uint32) (thr)) ) -#elif (SIZEOF_INT == 2) -# define PHTREAD_TO_UI64(thr) ( (PHYSFS_uint64) ((PHYSFS_uint16) (thr)) ) -#elif (SIZEOF_INT == 1) -# define PHTREAD_TO_UI64(thr) ( (PHYSFS_uint64) ((PHYSFS_uint8) (thr)) ) -#else -# define PHTREAD_TO_UI64(thr) ((PHYSFS_uint64) (thr)) -#endif - -PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) +void *__PHYSFS_platformGetThreadID(void) { - return(PHTREAD_TO_UI64(pthread_self())); + return( (void *) ((size_t) pthread_self()) ); } /* __PHYSFS_platformGetThreadID */ diff --git a/platform/windows.c b/platform/windows.c index c62cde3b..2ced9a4a 100644 --- a/platform/windows.c +++ b/platform/windows.c @@ -560,9 +560,9 @@ char *__PHYSFS_platformGetUserDir(void) } /* __PHYSFS_platformGetUserDir */ -PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) +void *__PHYSFS_platformGetThreadID(void) { - return((PHYSFS_uint64) GetCurrentThreadId()); + return( (void *) ((size_t) GetCurrentThreadId()) ); } /* __PHYSFS_platformGetThreadID */