shutting down some threads explicitly on app close in hopes that this will reduce the frequency of random shutdown crashes

This commit is contained in:
nitsuja 2009-11-08 19:03:05 +00:00
parent 00b28e5807
commit 07331b522e
4 changed files with 56 additions and 15 deletions

View File

@ -939,6 +939,7 @@ public:
static Task rasterizerUnitTask[4];
static RasterizerUnit rasterizerUnit[4];
static int rasterizerCores;
static bool rasterizerUnitTasksInited = false;
static void* execRasterizerUnit(void* arg)
{
@ -949,9 +950,10 @@ static void* execRasterizerUnit(void* arg)
static char SoftRastInit(void)
{
static bool tables_generated = false;
if(!tables_generated)
if(!rasterizerUnitTasksInited)
{
rasterizerUnitTasksInited = true;
if(CommonSettings.num_cores>=4)
{
rasterizerCores = 4;
@ -981,8 +983,11 @@ static char SoftRastInit(void)
rasterizerUnit[0].SLI_MASK = 0;
rasterizerUnit[0].SLI_VALUE = 0;
}
}
static bool tables_generated = false;
if(!tables_generated)
{
tables_generated = true;
clipper.clippedPolys = clippedPolys = new GFX3D_Clipper::TClippedPoly[POLYLIST_SIZE*2];
@ -1023,6 +1028,9 @@ static void SoftRastReset() {
static void SoftRastClose()
{
for(int i=0;i<4;i++)
rasterizerUnitTask[i].shutdown();
rasterizerUnitTasksInited = false;
}
static void SoftRastVramReconfigureSignal() {

View File

@ -32,6 +32,7 @@ public:
bool spinlock;
void start(bool spinlock);
void shutdown();
//execute some work
void execute(const TWork &work, void* param);
@ -60,14 +61,7 @@ static void* killTask(void* task)
Task::Impl::~Impl()
{
if(!bStarted) return;
execute(killTask,this);
finish();
CloseHandle(incomingWork);
CloseHandle(workDone);
CloseHandle(hThread);
shutdown();
}
Task::Impl::Impl()
@ -76,6 +70,9 @@ Task::Impl::Impl()
, bWorkDone(true)
, bKill(false)
, bStarted(false)
, incomingWork(INVALID_HANDLE_VALUE)
, workDone(INVALID_HANDLE_VALUE)
, hThread(INVALID_HANDLE_VALUE)
{
}
@ -112,6 +109,22 @@ void Task::Impl::start(bool spinlock)
workDone = CreateEvent(NULL,FALSE,FALSE,NULL);
hThread = CreateThread(NULL,0,Task::Impl::s_taskProc,(void*)this, 0, NULL);
}
void Task::Impl::shutdown()
{
if(!bStarted) return;
bStarted = false;
execute(killTask,this);
finish();
CloseHandle(incomingWork);
CloseHandle(workDone);
CloseHandle(hThread);
incomingWork = INVALID_HANDLE_VALUE;
workDone = INVALID_HANDLE_VALUE;
hThread = INVALID_HANDLE_VALUE;
}
void Task::Impl::execute(const TWork &work, void* param)
{
@ -144,6 +157,7 @@ public:
~Impl() {}
void start(bool spinlock) {}
void shutdown() {}
void* ret;
void execute(const TWork &work, void* param) { ret = work(param); }
@ -168,7 +182,8 @@ public:
pthread_t thread;
static void* s_taskProc(void *ptr);
void taskProc();
void init();
void start();
void shutdown();
//the work function that shall be executed
TWork work;
@ -243,11 +258,18 @@ void Task::Impl::taskProc()
}
}
void Task::Impl::init()
void Task::Impl::start()
{
pthread_create( &thread, NULL, Task::Impl::s_taskProc, (void*)this );
initialized = true;
}
void Task::Impl::shutdown()
{
if(!initialized)
return;
// pthread_join or something, NYI, this code is all disabled anyway at the time of this writing
initialized = false;
}
void Task::Impl::execute(const TWork &work, void* param)
{
@ -271,6 +293,7 @@ void* Task::Impl::finish()
#endif
void Task::start(bool spinlock) { impl->start(spinlock); }
void Task::shutdown() { impl->shutdown(); }
Task::Task() : impl(new Task::Impl()) {}
Task::~Task() { delete impl; }
void Task::execute(const TWork &work, void* param) { impl->execute(work,param); }

View File

@ -29,6 +29,7 @@ public:
typedef void * (*TWork)(void *);
// initialize task runner
void start(bool spinlock);
//execute some work
@ -37,6 +38,9 @@ public:
//wait for the work to complete
void* finish();
// does the opposite of start
void shutdown();
class Impl;
Impl *impl;

View File

@ -2549,8 +2549,14 @@ int _main()
}
MainWindow->Show(SW_NORMAL);
//------DO EVERYTHING
run();
//------SHUTDOWN
KillDisplay();
SaveRecentRoms();
@ -2559,12 +2565,12 @@ int _main()
NDS_DeInit();
//------SHUTDOWN
#ifdef DEBUG
//LogStop();
#endif
timeKillEvent(hKeyInputTimer);
GInfo_DeInit();
SoundView_DlgClose();