diff --git a/Source/Core/Common/Src/Thread.cpp b/Source/Core/Common/Src/Thread.cpp index 95b5d1ca65..ce95776242 100644 --- a/Source/Core/Common/Src/Thread.cpp +++ b/Source/Core/Common/Src/Thread.cpp @@ -358,6 +358,15 @@ int InterlockedExchangeAdd(int *Addend, int Increment) return result + Increment; #endif } +int InterlockedExchange(int *Addend, int Increment) +{ +#if defined(__GNUC__) && defined (__GNUC_MINOR__) && ((4 < __GNUC__) || (4 == __GNUC__ && 1 <= __GNUC_MINOR__)) + return __sync_lock_test_and_set(Addend, Increment); +#else + // TODO: + #warning Support older GCC Versions +#endif +} #endif diff --git a/Source/Core/Common/Src/Thread.h b/Source/Core/Common/Src/Thread.h index e71306baf1..069397a838 100644 --- a/Source/Core/Common/Src/Thread.h +++ b/Source/Core/Common/Src/Thread.h @@ -116,6 +116,7 @@ void SetCurrentThreadName(const char *name); #ifndef _WIN32 int InterlockedExchangeAdd(int *Addend, int Increment); +int InterlockedExchange(int *Addend, int Increment); #endif } // end of namespace Common diff --git a/Source/Core/Core/Src/HW/CommandProcessor.cpp b/Source/Core/Core/Src/HW/CommandProcessor.cpp index e3890aa2c5..79761edff5 100644 --- a/Source/Core/Core/Src/HW/CommandProcessor.cpp +++ b/Source/Core/Core/Src/HW/CommandProcessor.cpp @@ -360,11 +360,9 @@ void Write16(const u16 _Value, const u32 _Address) InterlockedExchange((LONG*)&fifo.bFF_GPLinkEnable, m_CPCtrlReg.GPLinkEnable); InterlockedExchange((LONG*)&fifo.bFF_BPEnable, m_CPCtrlReg.BPEnable); #else -#warning "Hi pingouin lover :p. Just make sure the following is ok for linux please." - // TODO: safely? - fifo.bFF_GPReadEnable = m_CPCtrlReg.GPReadEnable; - fifo.bFF_GPLinkEnable = m_CPCtrlReg.GPLinkEnable; - fifo.bFF_BPEnable = m_CPCtrlReg.BPEnable; + Common::InterlockedExchange((int*)&fifo.bFF_GPReadEnable, m_CPCtrlReg.GPReadEnable); + Common::InterlockedExchange((int*)&fifo.bFF_GPLinkEnable, m_CPCtrlReg.GPLinkEnable); + Common::InterlockedExchange((int*)&fifo.bFF_BPEnable, m_CPCtrlReg.BPEnable); #endif // TOCHECK (mb2): could BP irq be cleared with w16 to STATUS_REGISTER? // funny hack: eg in MP1 if we disable the clear breakpoint ability by commenting this block diff --git a/Source/Core/VideoCommon/Src/Fifo.cpp b/Source/Core/VideoCommon/Src/Fifo.cpp index 0e0f454f25..6b19c07b4d 100644 --- a/Source/Core/VideoCommon/Src/Fifo.cpp +++ b/Source/Core/VideoCommon/Src/Fifo.cpp @@ -135,7 +135,7 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize) #ifdef _WIN32 InterlockedExchange((LONG*)&_fifo.bFF_Breakpoint, 1); #else - _fifo.bFF_Breakpoint = true; + Common::InterlockedExchange((int*)&_fifo.bFF_Breakpoint, 1); #endif video_initialize.pUpdateInterrupts(); break; @@ -159,7 +159,7 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize) InterlockedExchangeAdd((LONG*)&_fifo.CPReadWriteDistance, -32); //LeaveCriticalSection(&_fifo.sync); #else - _fifo.CPReadPointer = readPtr; + Common::InterlockedExchange((int*)&_fifo.CPReadPointer, readPtr); Common::InterlockedExchangeAdd((int*)&_fifo.CPReadWriteDistance, -32); _fifo.sync->Leave(); #endif