diff --git a/pcsx2/GS.cpp b/pcsx2/GS.cpp index 7c0bb58e63..a9fadacf97 100644 --- a/pcsx2/GS.cpp +++ b/pcsx2/GS.cpp @@ -234,6 +234,7 @@ void gsClose() if( mtgsThread != NULL ) { + mtgsThread->Close(); safe_delete( mtgsThread ); } else @@ -373,7 +374,7 @@ __forceinline void _gsSMODEwrite( u32 mem, u32 value ) switch (mem) { case GS_SMODE1: - gsSetVideoRegionType( !!(value & 0x6000) ); + gsSetVideoRegionType( (value & 0x6000) == 0x6000 ); break; case GS_SMODE2: diff --git a/pcsx2/GS.h b/pcsx2/GS.h index 157749788e..8f8e05aedd 100644 --- a/pcsx2/GS.h +++ b/pcsx2/GS.h @@ -137,6 +137,7 @@ enum GS_RINGTYPE , GS_RINGTYPE_WRITECSR , GS_RINGTYPE_MODECHANGE // for issued mode changes. , GS_RINGTYPE_STARTTIME // special case for min==max fps frameskip settings +, GS_RINGTYPE_QUIT }; class mtgsThreadObject : public Threading::Thread @@ -181,9 +182,7 @@ protected: #endif // the MTGS "dummy" GIFtag info! - // 16 byte alignment isn't "critical" here, so if GCC ignores the aignment directive - // it shouldn't cause any issues. - PCSX2_ALIGNED16( GIFPath m_path[3] ); + GIFPath m_path[3]; // contains aligned memory allocations for gs and Ringbuffer. SafeAlignedArray m_RingBuffer; @@ -196,6 +195,7 @@ public: mtgsThreadObject(); virtual ~mtgsThreadObject(); + void Close(); void Reset(); void GIFSoftReset( int mask ); diff --git a/pcsx2/IopSio2.cpp b/pcsx2/IopSio2.cpp index 34d3c6e26e..acad16bcee 100644 --- a/pcsx2/IopSio2.cpp +++ b/pcsx2/IopSio2.cpp @@ -54,7 +54,7 @@ only recv2 & dataout influences padman void sio2Reset() { - SysPrintf("Sio2 init\n"); + DevCon::Status( "Sio2 Reset" ); memzero_obj(sio2); sio2.packet.recvVal1 = 0x1D100; // Nothing is connected at start } @@ -160,7 +160,7 @@ void sio2_serialIn(u8 value){ sioWrite8(value); if (sio2.packet.sendSize > BUFSIZE) {//asadr - SysPrintf("*PCSX2*: sendSize >= %d\n", BUFSIZE); + Console::Notice("*PCSX2*: sendSize >= %d", params BUFSIZE); } else { sio2.buf[sio2.packet.sendSize] = sioRead8(); sio2.packet.sendSize++; @@ -199,11 +199,16 @@ u8 sio2_fifoOut(){ //PAD_LOG("READING %x\n",sio2.buf[sio2.recvIndex]); return sio2.buf[sio2.recvIndex++]; } else { - SysPrintf("*PCSX2*: buffer overrun\n"); + Console::Error( "*PCSX2*: buffer overrun" ); } return 0; // No Data } +void SaveState::sio2Freeze() +{ + Freeze(sio2); +} + ///////////////////////////////////////////////// //////////////////////////////////////////// DMA ///////////////////////////////////////////////// @@ -264,7 +269,3 @@ void psxDMA12Interrupt() psxDmaInterrupt2(5); } -void SaveState::sio2Freeze() { - Freeze(sio2); -} - diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index d3f20c27f3..40f2542365 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -219,10 +219,14 @@ mtgsThreadObject::mtgsThreadObject() : mtgsThreadObject::~mtgsThreadObject() { - Console::WriteLn( "MTGS > Closing GS thread..." ); - SetEvent(); +} - // rest of the cleanup will be handled by the inherited object destructors... +void mtgsThreadObject::Close() +{ + Console::WriteLn( "MTGS > Closing GS thread..." ); + SendSimplePacket( GS_RINGTYPE_QUIT, 0, 0, 0 ); + SetEvent(); + pthread_join( m_thread, NULL ); } void mtgsThreadObject::Reset() @@ -452,10 +456,9 @@ int mtgsThreadObject::Callback() PacketTagType prevCmd; #endif - while( !m_sigterm ) + while( true ) { m_post_event.Wait(); - //if( m_sigterm ) break; AtomicExchange( m_RingBufferIsBusy, 1 ); @@ -592,6 +595,10 @@ int mtgsThreadObject::Callback() m_iSlowStart += tag.data[0]; break; + case GS_RINGTYPE_QUIT: + GSclose(); + return 0; + #ifdef PCSX2_DEVBUILD default: Console::Error("GSThreadProc, bad packet (%x) at m_RingPos: %x, m_WritePos: %x", params tag.command, m_RingPos, m_WritePos); @@ -611,9 +618,6 @@ int mtgsThreadObject::Callback() } AtomicExchange( m_RingBufferIsBusy, 0 ); } - - GSclose(); - return 0; } // Waits for the GS to empty out the entire ring buffer contents. diff --git a/pcsx2/ThreadTools.cpp b/pcsx2/ThreadTools.cpp index a911d89889..528be69284 100644 --- a/pcsx2/ThreadTools.cpp +++ b/pcsx2/ThreadTools.cpp @@ -27,7 +27,6 @@ namespace Threading m_thread() , m_returncode( 0 ) , m_terminated( false ) - , m_sigterm( 0 ) , m_post_event() { if( pthread_create( &m_thread, NULL, _internal_callback, this ) != 0 ) @@ -41,8 +40,7 @@ namespace Threading void Thread::Close() { - AtomicExchange( m_sigterm, 1 ); - m_post_event.Post(); + pthread_cancel( m_thread ); pthread_join( m_thread, NULL ); } diff --git a/pcsx2/Threading.h b/pcsx2/Threading.h index d430aad570..5fbd5e95db 100644 --- a/pcsx2/Threading.h +++ b/pcsx2/Threading.h @@ -83,7 +83,6 @@ namespace Threading pthread_t m_thread; int m_returncode; // value returned from the thread on close. bool m_terminated; // set true after the thread has been closed. - u32 m_sigterm; // set to true(1) when the thread has been requested to exit. Semaphore m_post_event; // general wait event that's needed by most threads. public: diff --git a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj index 8462b56464..8e240c4a0f 100644 --- a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj +++ b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj @@ -52,7 +52,7 @@