Add CreateThisThread(). Use it instead of the static object to name the main thread (and the GUI thread on OS X).
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
|
#include "RageThreads.h"
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#include "ProductInfo.h"
|
#include "ProductInfo.h"
|
||||||
@@ -109,6 +110,11 @@ static void setupMenus( void )
|
|||||||
|
|
||||||
int main( int argc, char **argv )
|
int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
|
RageThread guiThread;
|
||||||
|
|
||||||
|
guiThread.SetName( "GUIThread" );
|
||||||
|
guiThread.CreateThisThread();
|
||||||
|
|
||||||
[SMApplication poseAsClass:[NSApplication class]];
|
[SMApplication poseAsClass:[NSApplication class]];
|
||||||
|
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|||||||
@@ -244,21 +244,35 @@ void RageThread::Create( int (*fn)(void *), void *data )
|
|||||||
m_pSlot->pImpl = MakeThread( fn, data, &m_pSlot->id );
|
m_pSlot->pImpl = MakeThread( fn, data, &m_pSlot->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* On startup, register the main thread's slot. We do this in a static constructor,
|
void RageThread::CreateThisThread()
|
||||||
* and not InitThreads(), to guarantee it happens in the main thread. */
|
|
||||||
static struct SetupMainThread
|
|
||||||
{
|
{
|
||||||
SetupMainThread()
|
ASSERT( m_pSlot == NULL );
|
||||||
{
|
|
||||||
LockMut(g_ThreadSlotsLock);
|
|
||||||
int slot = FindEmptyThreadSlot();
|
|
||||||
strcpy( g_ThreadSlots[slot].name, "MainThread" );
|
|
||||||
sprintf( g_ThreadSlots[slot].ThreadFormattedOutput, "Thread: %s", g_ThreadSlots[slot].name );
|
|
||||||
g_ThreadSlots[slot].id = RageThread::GetCurrentThreadID();
|
|
||||||
g_ThreadSlots[slot].pImpl = MakeThisThread();
|
|
||||||
}
|
|
||||||
} SetupMainThreadObj;
|
|
||||||
|
|
||||||
|
InitThreads();
|
||||||
|
|
||||||
|
LockMut( g_ThreadSlotsLock );
|
||||||
|
|
||||||
|
int slotno = FindEmptyThreadSlot();
|
||||||
|
|
||||||
|
m_pSlot = &g_ThreadSlots[slotno];
|
||||||
|
|
||||||
|
if( name == "" )
|
||||||
|
{
|
||||||
|
if( LOG )
|
||||||
|
LOG->Warn( "Created a thread without naming it first." );
|
||||||
|
|
||||||
|
/* If you don't name it, I will: */
|
||||||
|
strcpy( m_pSlot->name, "Jon" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcpy( m_pSlot->name, name.c_str() );
|
||||||
|
}
|
||||||
|
sprintf( m_pSlot->ThreadFormattedOutput, "Thread: %s", name.c_str() );
|
||||||
|
|
||||||
|
m_pSlot->id = GetThisThreadId();
|
||||||
|
m_pSlot->pImpl = MakeThisThread();
|
||||||
|
}
|
||||||
|
|
||||||
const char *RageThread::GetCurThreadName()
|
const char *RageThread::GetCurThreadName()
|
||||||
{
|
{
|
||||||
@@ -294,7 +308,12 @@ int RageThread::Wait()
|
|||||||
{
|
{
|
||||||
ASSERT( m_pSlot != NULL );
|
ASSERT( m_pSlot != NULL );
|
||||||
ASSERT( m_pSlot->pImpl != NULL );
|
ASSERT( m_pSlot->pImpl != NULL );
|
||||||
int ret = m_pSlot->pImpl->Wait();
|
int ret;
|
||||||
|
|
||||||
|
if( m_pSlot->id == GetThisThreadId() )
|
||||||
|
ret = 0;
|
||||||
|
else
|
||||||
|
ret = m_pSlot->pImpl->Wait();
|
||||||
|
|
||||||
LockMut(g_ThreadSlotsLock);
|
LockMut(g_ThreadSlotsLock);
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
void SetName( const CString &n ) { name = n; }
|
void SetName( const CString &n ) { name = n; }
|
||||||
CString GetName() const { return name; }
|
CString GetName() const { return name; }
|
||||||
void Create( int (*fn)(void *), void *data );
|
void Create( int (*fn)(void *), void *data );
|
||||||
|
void CreateThisThread();
|
||||||
|
|
||||||
/* For crash handlers: kill or suspend all threads (except for
|
/* For crash handlers: kill or suspend all threads (except for
|
||||||
* the running one) immediately. */
|
* the running one) immediately. */
|
||||||
|
|||||||
@@ -926,6 +926,10 @@ int main(int argc, char* argv[])
|
|||||||
int argc = 1;
|
int argc = 1;
|
||||||
char *argv[] = {"default.xbe"};
|
char *argv[] = {"default.xbe"};
|
||||||
#endif
|
#endif
|
||||||
|
RageThread mainThread;
|
||||||
|
|
||||||
|
mainThread.SetName( "MainThread" );
|
||||||
|
mainThread.CreateThisThread();
|
||||||
|
|
||||||
SetCommandlineArguments( argc, argv );
|
SetCommandlineArguments( argc, argv );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user