Implement proper thread naming on linux. This fixes a segmentation fault with thte wiimote new configuration dialog when a thread was named without first calling ThreadInit.

Also take care of some more eols.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5843 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2010-07-06 16:16:07 +00:00
parent e9e12ff100
commit 0e2b4d8306
22 changed files with 1456 additions and 1463 deletions

View File

@ -187,7 +187,8 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address) {
str2ba(address, &addr.l2_bdaddr);
else
{
bacmp(bdaddr, BDADDR_ANY);
if (bacmp(bdaddr, BDADDR_ANY) == 0)
return 0;
/* use address of device discovered */
addr.l2_bdaddr = *bdaddr;

View File

@ -37,11 +37,6 @@ namespace Common
#ifdef _WIN32
void InitThreading()
{
// Nothing to do in Win32 build.
}
CriticalSection::CriticalSection(int spincount)
{
if (spincount)
@ -306,7 +301,8 @@ namespace Common
#else // !WIN32, so must be POSIX threads
pthread_key_t threadname_key;
static pthread_key_t threadname_key;
static pthread_once_t threadname_key_once = PTHREAD_ONCE_INIT;
CriticalSection::CriticalSection(int spincount_unused)
{
@ -412,17 +408,6 @@ namespace Common
return pthread_equal(pthread_self(), thread_id) != 0;
}
void InitThreading() {
static int thread_init_done = 0;
if (thread_init_done)
return;
if (pthread_key_create(&threadname_key, NULL/*free*/) != 0)
perror("Unable to create thread name key: ");
thread_init_done++;
}
void SleepCurrentThread(int ms)
{
usleep(1000 * ms);
@ -433,16 +418,26 @@ namespace Common
usleep(1000 * 1);
}
static void FreeThreadName(void* threadname)
{
free(threadname);
}
static void ThreadnameKeyAlloc()
{
pthread_key_create(&threadname_key, FreeThreadName);
}
void SetCurrentThreadName(const TCHAR* szThreadName)
{
char *name = strdup(szThreadName);
// pthread_setspecific returns 0 on success
// free the string from strdup if fails
// creates a memory leak if it actually doesn't fail
// since we don't delete it once we delete the thread
// we are using a single threadname_key anyway for all threads
if(!pthread_setspecific(threadname_key, name))
free(name);
pthread_once(&threadname_key_once, ThreadnameKeyAlloc);
void* threadname;
if ((threadname = pthread_getspecific(threadname_key)) != NULL)
free(threadname);
pthread_setspecific(threadname_key, strdup(szThreadName));
INFO_LOG(COMMON, "%s(%s)\n", __FUNCTION__, szThreadName);
}

View File

@ -203,7 +203,6 @@ namespace Common
#endif
};
void InitThreading();
void SleepCurrentThread(int ms);
void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms

View File

@ -190,8 +190,6 @@ bool Init()
CPluginManager &pManager = CPluginManager::GetInstance();
SCoreStartupParameter &_CoreParameter = SConfig::GetInstance().m_LocalCoreStartupParameter;
Common::InitThreading();
g_CoreStartupParameter = _CoreParameter;
// FIXME DEBUG_LOG(BOOT, dump_params());
Host_SetWaitCursor(true);