Fix some random crashing on exit. Add some log spam threshold handling (untested).

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2500 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2010-01-23 23:48:54 +00:00
parent a323d31bf3
commit 6307feebc4
4 changed files with 56 additions and 20 deletions

View File

@ -188,7 +188,7 @@ protected:
{ {
Yield( 3 ); Yield( 3 );
static const int BlockSize = 0x10000; static const int BlockSize = 0x20000;
int curidx = 0; int curidx = 0;
do do
{ {
@ -196,7 +196,7 @@ protected:
if( gzwrite( m_gzfp, state_buffer.GetPtr(curidx), thisBlockSize ) < thisBlockSize ) if( gzwrite( m_gzfp, state_buffer.GetPtr(curidx), thisBlockSize ) < thisBlockSize )
throw Exception::BadStream( m_filename ); throw Exception::BadStream( m_filename );
curidx += thisBlockSize; curidx += thisBlockSize;
Yield( 10 ); Yield( 1 );
} while( curidx < state_buffer.GetSizeInBytes() ); } while( curidx < state_buffer.GetSizeInBytes() );
Console.WriteLn( "State saved to disk without error." ); Console.WriteLn( "State saved to disk without error." );

View File

@ -232,12 +232,15 @@ ConsoleLogFrame::ConsoleLogFrame( MainEmuFrame *parent, const wxString& title, A
: wxFrame(parent, wxID_ANY, title) : wxFrame(parent, wxID_ANY, title)
, m_conf( options ) , m_conf( options )
, m_TextCtrl( *new pxLogTextCtrl(this) ) , m_TextCtrl( *new pxLogTextCtrl(this) )
, m_timer_FlushLimiter( this )
, m_ColorTable( options.FontSize ) , m_ColorTable( options.FontSize )
, m_QueueColorSection( L"ConsoleLog::QueueColorSection" ) , m_QueueColorSection( L"ConsoleLog::QueueColorSection" )
, m_QueueBuffer( L"ConsoleLog::QueueBuffer" ) , m_QueueBuffer( L"ConsoleLog::QueueBuffer" )
, m_threadlogger( EnableThreadedLoggingTest ? new ConsoleTestThread() : NULL ) , m_threadlogger( EnableThreadedLoggingTest ? new ConsoleTestThread() : NULL )
{ {
m_flushevent_counter = 0;
m_CurQueuePos = 0; m_CurQueuePos = 0;
m_pendingFlushes = 0; m_pendingFlushes = 0;
m_WaitingThreadsForFlush = 0; m_WaitingThreadsForFlush = 0;
@ -318,16 +321,17 @@ ConsoleLogFrame::ConsoleLogFrame( MainEmuFrame *parent, const wxString& title, A
Connect( m_item_StdoutEE->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( ConsoleLogFrame::OnLogSourceChanged ) ); Connect( m_item_StdoutEE->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( ConsoleLogFrame::OnLogSourceChanged ) );
Connect( m_item_StdoutIOP->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( ConsoleLogFrame::OnLogSourceChanged ) ); Connect( m_item_StdoutIOP->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( ConsoleLogFrame::OnLogSourceChanged ) );
Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler(ConsoleLogFrame::OnCloseWindow) ); Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler (ConsoleLogFrame::OnCloseWindow) );
Connect( wxEVT_MOVE, wxMoveEventHandler(ConsoleLogFrame::OnMoveAround) ); Connect( wxEVT_MOVE, wxMoveEventHandler (ConsoleLogFrame::OnMoveAround) );
Connect( wxEVT_SIZE, wxSizeEventHandler(ConsoleLogFrame::OnResize) ); Connect( wxEVT_SIZE, wxSizeEventHandler (ConsoleLogFrame::OnResize) );
Connect( wxEVT_ACTIVATE, wxActivateEventHandler(ConsoleLogFrame::OnActivate) ); Connect( wxEVT_ACTIVATE, wxActivateEventHandler (ConsoleLogFrame::OnActivate) );
Connect( wxEVT_SetTitleText, wxCommandEventHandler(ConsoleLogFrame::OnSetTitle) ); Connect( wxEVT_SetTitleText, wxCommandEventHandler (ConsoleLogFrame::OnSetTitle) );
Connect( wxEVT_DockConsole, wxCommandEventHandler(ConsoleLogFrame::OnDockedMove) ); Connect( wxEVT_DockConsole, wxCommandEventHandler (ConsoleLogFrame::OnDockedMove) );
Connect( wxEVT_FlushQueue, wxCommandEventHandler(ConsoleLogFrame::OnFlushEvent) ); Connect( wxEVT_FlushQueue, wxCommandEventHandler (ConsoleLogFrame::OnFlushEvent) );
//Connect( wxEVT_IDLE, wxIdleEventHandler(ConsoleLogFrame::OnIdleEvent) ); Connect( wxEVT_IDLE, wxIdleEventHandler (ConsoleLogFrame::OnIdleEvent) );
Connect( wxEVT_TIMER, wxTimerEventHandler (ConsoleLogFrame::OnFlushLimiterTimer) );
m_item_Deci2 ->Check( g_Conf->EmuOptions.Log.Deci2 ); m_item_Deci2 ->Check( g_Conf->EmuOptions.Log.Deci2 );
m_item_StdoutEE ->Check( g_Conf->EmuOptions.Log.StdoutEE ); m_item_StdoutEE ->Check( g_Conf->EmuOptions.Log.StdoutEE );
@ -588,24 +592,52 @@ void ConsoleLogFrame::OnSetTitle( wxCommandEvent& event )
SetTitle( event.GetString() ); SetTitle( event.GetString() );
} }
void ConsoleLogFrame::OnIdleEvent( wxIdleEvent& evt ) void ConsoleLogFrame::OnIdleEvent( wxIdleEvent& )
{ {
// bah, wx's Idle Events are the most worthless crap. // When the GUI is idle then it's a safe bet we can resume suspended console log
//::SendMessage((HWND)m_TextCtrl.GetHWND(), WM_VSCROLL, SB_BOTTOM, (LPARAM)NULL); // flushing, on the theory that the user's had a good chance to field user input.
m_flushevent_counter = 0;
m_timer_FlushLimiter.Stop();
wxCommandEvent sendevt( wxEVT_FlushQueue );
GetEventHandler()->AddPendingEvent( sendevt );
} }
void ConsoleLogFrame::OnFlushEvent( wxCommandEvent& evt ) void ConsoleLogFrame::OnFlushLimiterTimer( wxTimerEvent& )
{
m_flushevent_counter = 0;
wxCommandEvent sendevt( wxEVT_FlushQueue );
GetEventHandler()->AddPendingEvent( sendevt );
}
void ConsoleLogFrame::OnFlushEvent( wxCommandEvent& )
{ {
ScopedLock locker( m_QueueLock ); ScopedLock locker( m_QueueLock );
m_pendingFlushMsg = false; m_pendingFlushMsg = false;
// recursion guard needed due to Mutex lock/acquire code below. // recursion guard needed due to Mutex lock/acquire code below, which can end up yielding
// to the gui and attempting to process more messages (which in turn would result in re-
// entering this handler).
static int recursion_counter = 0; static int recursion_counter = 0;
RecursionGuard recguard( recursion_counter ); RecursionGuard recguard( recursion_counter );
if( recguard.IsReentrant() ) return; if( recguard.IsReentrant() ) return;
if( m_CurQueuePos != 0 ) if( m_CurQueuePos != 0 )
{ {
if( !m_timer_FlushLimiter.IsRunning() )
{
m_timer_FlushLimiter.Start( 500, true );
m_flushevent_counter = 0;
}
else
{
if( m_flushevent_counter >= 1000 )
return;
++m_flushevent_counter;
}
if( m_ThreadedLogInQueue && (m_pendingFlushes < 20) ) if( m_ThreadedLogInQueue && (m_pendingFlushes < 20) )
{ {
// Hacky Speedup --> // Hacky Speedup -->

View File

@ -172,7 +172,10 @@ protected:
protected: protected:
ConLogConfig& m_conf; ConLogConfig& m_conf;
pxLogTextCtrl& m_TextCtrl; pxLogTextCtrl& m_TextCtrl;
wxTimer m_timer_FlushLimiter;
ColorArray m_ColorTable; ColorArray m_ColorTable;
int m_flushevent_counter;
// this int throttles freeze/thaw of the display, by cycling from -2 to 4, roughly. // this int throttles freeze/thaw of the display, by cycling from -2 to 4, roughly.
// (negative values force thaw, positive values indicate thaw is disabled. This is // (negative values force thaw, positive values indicate thaw is disabled. This is
@ -268,6 +271,7 @@ protected:
void OnSetTitle( wxCommandEvent& event ); void OnSetTitle( wxCommandEvent& event );
void OnDockedMove( wxCommandEvent& event ); void OnDockedMove( wxCommandEvent& event );
void OnIdleEvent( wxIdleEvent& event ); void OnIdleEvent( wxIdleEvent& event );
void OnFlushLimiterTimer( wxTimerEvent& evt );
void OnFlushEvent( wxCommandEvent& event ); void OnFlushEvent( wxCommandEvent& event );
// common part of OnClose() and OnCloseWindow() // common part of OnClose() and OnCloseWindow()

View File

@ -71,6 +71,8 @@ void MainEmuFrame::UpdateIsoSrcSelection()
// //
void MainEmuFrame::OnCloseWindow(wxCloseEvent& evt) void MainEmuFrame::OnCloseWindow(wxCloseEvent& evt)
{ {
if( IsBeingDeleted() ) return;
CoreThread.Suspend(); CoreThread.Suspend();
bool isClosing = false; bool isClosing = false;
@ -88,14 +90,12 @@ void MainEmuFrame::OnCloseWindow(wxCloseEvent& evt)
// closing PCSX2 difficult). A non-blocking suspend with modal dialog might suffice // closing PCSX2 difficult). A non-blocking suspend with modal dialog might suffice
// however. --air // however. --air
//evt.Veto( true );
if( StateCopy_InvokeOnSaveComplete( new InvokeAction_MenuCommand( MenuId_Exit ) ) ) return; if( StateCopy_InvokeOnSaveComplete( new InvokeAction_MenuCommand( MenuId_Exit ) ) ) return;
} }
if( isClosing ) wxGetApp().PrepForExit();
wxGetApp().PrepForExit();
else
evt.Veto( true );
sApp.OnMainFrameClosed(); sApp.OnMainFrameClosed();
evt.Skip(); evt.Skip();