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:
parent
e9e12ff100
commit
0e2b4d8306
|
@ -187,7 +187,8 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address) {
|
||||||
str2ba(address, &addr.l2_bdaddr);
|
str2ba(address, &addr.l2_bdaddr);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bacmp(bdaddr, BDADDR_ANY);
|
if (bacmp(bdaddr, BDADDR_ANY) == 0)
|
||||||
|
return 0;
|
||||||
/* use address of device discovered */
|
/* use address of device discovered */
|
||||||
addr.l2_bdaddr = *bdaddr;
|
addr.l2_bdaddr = *bdaddr;
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,6 @@ namespace Common
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
void InitThreading()
|
|
||||||
{
|
|
||||||
// Nothing to do in Win32 build.
|
|
||||||
}
|
|
||||||
|
|
||||||
CriticalSection::CriticalSection(int spincount)
|
CriticalSection::CriticalSection(int spincount)
|
||||||
{
|
{
|
||||||
if (spincount)
|
if (spincount)
|
||||||
|
@ -306,7 +301,8 @@ namespace Common
|
||||||
|
|
||||||
#else // !WIN32, so must be POSIX threads
|
#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)
|
CriticalSection::CriticalSection(int spincount_unused)
|
||||||
{
|
{
|
||||||
|
@ -412,17 +408,6 @@ namespace Common
|
||||||
return pthread_equal(pthread_self(), thread_id) != 0;
|
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)
|
void SleepCurrentThread(int ms)
|
||||||
{
|
{
|
||||||
usleep(1000 * ms);
|
usleep(1000 * ms);
|
||||||
|
@ -433,16 +418,26 @@ namespace Common
|
||||||
usleep(1000 * 1);
|
usleep(1000 * 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void FreeThreadName(void* threadname)
|
||||||
|
{
|
||||||
|
free(threadname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ThreadnameKeyAlloc()
|
||||||
|
{
|
||||||
|
pthread_key_create(&threadname_key, FreeThreadName);
|
||||||
|
}
|
||||||
|
|
||||||
void SetCurrentThreadName(const TCHAR* szThreadName)
|
void SetCurrentThreadName(const TCHAR* szThreadName)
|
||||||
{
|
{
|
||||||
char *name = strdup(szThreadName);
|
pthread_once(&threadname_key_once, ThreadnameKeyAlloc);
|
||||||
// pthread_setspecific returns 0 on success
|
|
||||||
// free the string from strdup if fails
|
void* threadname;
|
||||||
// creates a memory leak if it actually doesn't fail
|
if ((threadname = pthread_getspecific(threadname_key)) != NULL)
|
||||||
// since we don't delete it once we delete the thread
|
free(threadname);
|
||||||
// we are using a single threadname_key anyway for all threads
|
|
||||||
if(!pthread_setspecific(threadname_key, name))
|
pthread_setspecific(threadname_key, strdup(szThreadName));
|
||||||
free(name);
|
|
||||||
INFO_LOG(COMMON, "%s(%s)\n", __FUNCTION__, szThreadName);
|
INFO_LOG(COMMON, "%s(%s)\n", __FUNCTION__, szThreadName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,6 @@ namespace Common
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void InitThreading();
|
|
||||||
void SleepCurrentThread(int ms);
|
void SleepCurrentThread(int ms);
|
||||||
void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms
|
void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms
|
||||||
|
|
||||||
|
|
|
@ -190,8 +190,6 @@ bool Init()
|
||||||
CPluginManager &pManager = CPluginManager::GetInstance();
|
CPluginManager &pManager = CPluginManager::GetInstance();
|
||||||
SCoreStartupParameter &_CoreParameter = SConfig::GetInstance().m_LocalCoreStartupParameter;
|
SCoreStartupParameter &_CoreParameter = SConfig::GetInstance().m_LocalCoreStartupParameter;
|
||||||
|
|
||||||
Common::InitThreading();
|
|
||||||
|
|
||||||
g_CoreStartupParameter = _CoreParameter;
|
g_CoreStartupParameter = _CoreParameter;
|
||||||
// FIXME DEBUG_LOG(BOOT, dump_params());
|
// FIXME DEBUG_LOG(BOOT, dump_params());
|
||||||
Host_SetWaitCursor(true);
|
Host_SetWaitCursor(true);
|
||||||
|
|
Loading…
Reference in New Issue