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:
Steve Checkoway
2005-12-15 08:32:29 +00:00
parent bdf4898ecb
commit 315d907ef1
4 changed files with 42 additions and 12 deletions
+6
View File
@@ -1,5 +1,6 @@
#include "global.h"
#include "RageUtil.h"
#include "RageThreads.h"
#import <Cocoa/Cocoa.h>
#include "ProductInfo.h"
@@ -109,6 +110,11 @@ static void setupMenus( void )
int main( int argc, char **argv )
{
RageThread guiThread;
guiThread.SetName( "GUIThread" );
guiThread.CreateThisThread();
[SMApplication poseAsClass:[NSApplication class]];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+31 -12
View File
@@ -244,21 +244,35 @@ void RageThread::Create( int (*fn)(void *), void *data )
m_pSlot->pImpl = MakeThread( fn, data, &m_pSlot->id );
}
/* On startup, register the main thread's slot. We do this in a static constructor,
* and not InitThreads(), to guarantee it happens in the main thread. */
static struct SetupMainThread
void RageThread::CreateThisThread()
{
SetupMainThread()
ASSERT( m_pSlot == NULL );
InitThreads();
LockMut( g_ThreadSlotsLock );
int slotno = FindEmptyThreadSlot();
m_pSlot = &g_ThreadSlots[slotno];
if( name == "" )
{
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();
if( LOG )
LOG->Warn( "Created a thread without naming it first." );
/* If you don't name it, I will: */
strcpy( m_pSlot->name, "Jon" );
}
} SetupMainThreadObj;
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()
{
@@ -294,7 +308,12 @@ int RageThread::Wait()
{
ASSERT( m_pSlot != 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);
+1
View File
@@ -19,6 +19,7 @@ public:
void SetName( const CString &n ) { name = n; }
CString GetName() const { return name; }
void Create( int (*fn)(void *), void *data );
void CreateThisThread();
/* For crash handlers: kill or suspend all threads (except for
* the running one) immediately. */
+4
View File
@@ -926,6 +926,10 @@ int main(int argc, char* argv[])
int argc = 1;
char *argv[] = {"default.xbe"};
#endif
RageThread mainThread;
mainThread.SetName( "MainThread" );
mainThread.CreateThisThread();
SetCommandlineArguments( argc, argv );