mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2024-12-02 00:41:51 +00:00
Merge pull request #51 from DanielGibson/debug-threads-freebsd
Fix DEBUG_THREADS on FreeBSD
This commit is contained in:
commit
395d3a35cf
1 changed files with 20 additions and 6 deletions
|
@ -31,7 +31,7 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include "../../precompiled.h"
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <pthread_ng.h> // for pthread_set_name_np
|
||||
#include <pthread_np.h> // for pthread_set_name_np
|
||||
#endif
|
||||
|
||||
// DG: Note: On Linux you need at least (e)glibc 2.12 to be able to set the threadname
|
||||
|
@ -63,18 +63,15 @@ static int Sys_SetThreadName( pthread_t handle, const char* name )
|
|||
ret = pthread_setname_np( handle, name );
|
||||
if( ret != 0 )
|
||||
idLib::common->Printf( "Setting threadname \"%s\" failed, reason: %s (%i)\n", name, strerror( errno ), errno );
|
||||
// pthread_getname_np(pthread_t, char*, size_t)
|
||||
#elif defined(__FreeBSD__)
|
||||
// according to http://www.freebsd.org/cgi/man.cgi?query=pthread_set_name_np&sektion=3
|
||||
// the interface is void pthread_set_name_np(pthread_t tid, const char *name);
|
||||
pthread_set_name_np( handle, name ); // doesn't return anything
|
||||
// seems like there is no get_name equivalent
|
||||
#endif
|
||||
/* TODO: OSX:
|
||||
// according to http://stackoverflow.com/a/7989973
|
||||
// this needs to be called in the thread to be named!
|
||||
ret = pthread_setname_np(name);
|
||||
// int pthread_getname_np(pthread_t, char*, size_t);
|
||||
|
||||
// so we'd have to wrap the xthread_t function in Sys_CreateThread and set the name in the wrapping function...
|
||||
*/
|
||||
|
@ -82,7 +79,24 @@ static int Sys_SetThreadName( pthread_t handle, const char* name )
|
|||
return ret;
|
||||
}
|
||||
|
||||
// TODO: Sys_GetThreadName() ?
|
||||
static int Sys_GetThreadName( pthread_t handle, char* namebuf, size_t buflen )
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef __linux__
|
||||
ret = pthread_getname_np( handle, namebuf, buflen );
|
||||
if( ret != 0 )
|
||||
idLib::common->Printf( "Getting threadname failed, reason: %s (%i)\n", strerror( errno ), errno );
|
||||
#elif defined(__FreeBSD__)
|
||||
// seems like there is no pthread_getname_np equivalent on FreeBSD
|
||||
idStr::snPrintf( namebuf, buflen, "Can't read threadname on this platform!" );
|
||||
#endif
|
||||
/* TODO: OSX:
|
||||
// int pthread_getname_np(pthread_t, char*, size_t);
|
||||
*/
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // DEBUG_THREADS
|
||||
|
||||
|
||||
|
@ -228,7 +242,7 @@ void Sys_DestroyThread( uintptr_t threadHandle )
|
|||
name[0] = '\0';
|
||||
|
||||
#if defined(DEBUG_THREADS)
|
||||
pthread_getname_np( threadHandle, name, sizeof( name ) );
|
||||
Sys_GetThreadName( ( pthread_t )threadHandle, name, sizeof( name ) );
|
||||
#endif
|
||||
|
||||
#if 0 //!defined(__ANDROID__)
|
||||
|
|
Loading…
Reference in a new issue