merged windows/linux atomic operations,

please test on windows


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1391 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee 2008-12-04 10:58:45 +00:00
parent 9692fca60e
commit b64877d464
5 changed files with 36 additions and 63 deletions

View File

@ -123,6 +123,7 @@ inline u32 _rotr(u32 x, int shift) {
return (x >> shift) | (x << (32 - shift));
}
#define LONG int
#ifdef __LINUX__
typedef union _LARGE_INTEGER
{

View File

@ -343,8 +343,11 @@ void Event::Wait()
pthread_mutex_unlock(&mutex_);
}
int InterlockedIncrement(int *Addend)
LONG InterlockedIncrement(LONG *Addend)
{
#ifdef _WIN32
return InterlockedIncrement(Addend);
#else
#if defined(__GNUC__) && defined (__GNUC_MINOR__) && ((4 < __GNUC__) || (4 == __GNUC__ && 1 <= __GNUC_MINOR__))
return __sync_add_and_fetch(Addend, 1);
#else
@ -354,11 +357,15 @@ int InterlockedIncrement(int *Addend)
: "0" (Increment), "m" (1)
: "memory");
return result + 1;
#endif
#endif
#endif
}
int InterlockedExchangeAdd(int *Addend, int Increment)
LONG InterlockedExchangeAdd(LONG *Addend, LONG Increment)
{
#ifdef _WIN32
return InterlockedExchangeAdd(Addend, Increment);
#else
#if defined(__GNUC__) && defined (__GNUC_MINOR__) && ((4 < __GNUC__) || (4 == __GNUC__ && 1 <= __GNUC_MINOR__))
return __sync_add_and_fetch(Addend, Increment);
#else
@ -369,14 +376,19 @@ int InterlockedExchangeAdd(int *Addend, int Increment)
: "memory");
return result + Increment;
#endif
#endif
}
int InterlockedExchange(int *Addend, int Increment)
LONG InterlockedExchange(LONG *Addend, LONG Increment)
{
#ifdef _WIN32
return InterlockedExchange(Addend, Increment);
#else
#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
#error Implement support older GCC Versions
#endif
#endif
}

View File

@ -171,13 +171,9 @@ void UpdateInterrupts();
//inline void WriteLow (u32& _reg, u16 lowbits) {_reg = (_reg & 0xFFFF0000) | lowbits;}
//inline void WriteHigh(u32& _reg, u16 highbits) {_reg = (_reg & 0x0000FFFF) | ((u32)highbits << 16);}
#ifdef _WIN32
inline void WriteLow (volatile u32& _reg, u16 lowbits) {InterlockedExchange((LONG*)&_reg,(_reg & 0xFFFF0000) | lowbits);}
inline void WriteHigh(volatile u32& _reg, u16 highbits) {InterlockedExchange((LONG*)&_reg,(_reg & 0x0000FFFF) | ((u32)highbits << 16));}
#else
inline void WriteLow (volatile u32& _reg, u16 lowbits) {Common::InterlockedExchange((int*)&_reg,(_reg & 0xFFFF0000) | lowbits);}
inline void WriteHigh(volatile u32& _reg, u16 highbits) {Common::InterlockedExchange((int*)&_reg,(_reg & 0x0000FFFF) | ((u32)highbits << 16));}
#endif
inline void WriteLow (volatile u32& _reg, u16 lowbits) {Common::InterlockedExchange((LONG*)&_reg,(_reg & 0xFFFF0000) | lowbits);}
inline void WriteHigh(volatile u32& _reg, u16 highbits) {Common::InterlockedExchange((LONG*)&_reg,(_reg & 0x0000FFFF) | ((u32)highbits << 16));}
inline u16 ReadLow (u32 _reg) {return (u16)(_reg & 0xFFFF);}
inline u16 ReadHigh (u32 _reg) {return (u16)(_reg >> 16);}
@ -186,11 +182,7 @@ int et_UpdateInterrupts;
// for GP watchdog hack
void IncrementGPWDToken()
{
#ifdef _WIN32
InterlockedIncrement((LONG*)&fifo.Fake_GPWDToken);
#else
Common::InterlockedIncrement((int*)&fifo.Fake_GPWDToken);
#endif
Common::InterlockedIncrement((LONG*)&fifo.Fake_GPWDToken);
}
// Check every FAKE_GP_WATCHDOG_PERIOD if a PE-frame-finish occured
@ -419,15 +411,10 @@ void Write16(const u16 _Value, const u32 _Address)
{
UCPCtrlReg tmpCtrl(_Value);
#ifdef _WIN32
InterlockedExchange((LONG*)&fifo.bFF_GPReadEnable, tmpCtrl.GPReadEnable);
InterlockedExchange((LONG*)&fifo.bFF_GPLinkEnable, tmpCtrl.GPLinkEnable);
InterlockedExchange((LONG*)&fifo.bFF_BPEnable, tmpCtrl.BPEnable);
#else
Common::InterlockedExchange((int*)&fifo.bFF_GPReadEnable, tmpCtrl.GPReadEnable);
Common::InterlockedExchange((int*)&fifo.bFF_GPLinkEnable, tmpCtrl.GPLinkEnable);
Common::InterlockedExchange((int*)&fifo.bFF_BPEnable, tmpCtrl.BPEnable);
#endif
Common::InterlockedExchange((LONG*)&fifo.bFF_GPReadEnable, tmpCtrl.GPReadEnable);
Common::InterlockedExchange((LONG*)&fifo.bFF_GPLinkEnable, tmpCtrl.GPLinkEnable);
Common::InterlockedExchange((LONG*)&fifo.bFF_BPEnable, tmpCtrl.BPEnable);
// 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
// the game is of course faster but looks stable too.
@ -589,11 +576,7 @@ void GatherPipeBursted()
fifo.CPWritePointer += GPFifo::GATHER_PIPE_SIZE;
if (fifo.CPWritePointer >= fifo.CPEnd)
fifo.CPWritePointer = fifo.CPBase;
#ifdef _WIN32
InterlockedExchangeAdd((LONG*)&fifo.CPReadWriteDistance, GPFifo::GATHER_PIPE_SIZE);
#else
Common::InterlockedExchangeAdd((int*)&fifo.CPReadWriteDistance, GPFifo::GATHER_PIPE_SIZE);
#endif
Common::InterlockedExchangeAdd((LONG*)&fifo.CPReadWriteDistance, GPFifo::GATHER_PIPE_SIZE);
// High watermark overflow handling (hacked way)
u32 ct=0;
@ -717,11 +700,8 @@ void UpdateFifoRegister()
else
dist = (wp - fifo.CPBase) + (fifo.CPEnd - rp);
//fifo.CPReadWriteDistance = dist;
#ifdef _WIN32
InterlockedExchange((LONG*)&fifo.CPReadWriteDistance, dist);
#else
Common::InterlockedExchange((int*)&fifo.CPReadWriteDistance, dist);
#endif
Common::InterlockedExchange((LONG*)&fifo.CPReadWriteDistance, dist);
if (!Core::g_CoreStartupParameter.bUseDualCore)
CatchUpGPU();
}

View File

@ -202,11 +202,7 @@ void SetToken(const u16 _token, const int _bSetTokenAcknowledge)
{
// we do it directly from videoThread because of
// Super Monkey Ball Advance
#ifdef _WIN32
InterlockedExchange((LONG*)&CommandProcessor::fifo.PEToken, _token);
#else
Common::InterlockedExchange((int*)&CommandProcessor::fifo.PEToken, _token);
#endif
Common::InterlockedExchange((LONG*)&CommandProcessor::fifo.PEToken, _token);
}
}

View File

@ -104,11 +104,7 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize)
// check if we are able to run this buffer
if ((_fifo.bFF_GPReadEnable) && _fifo.CPReadWriteDistance && !(_fifo.bFF_BPEnable && _fifo.bFF_Breakpoint))
{
#ifdef _WIN32
InterlockedExchange((LONG*)&_fifo.CPReadIdle, 0);
#else
Common::InterlockedExchange((int*)&_fifo.CPReadIdle, 0);
#endif
Common::InterlockedExchange((LONG*)&_fifo.CPReadIdle, 0);
//video_initialize.pLog("RUN...........................",FALSE);
int peek_counter = 0;
while (_fifo.bFF_GPReadEnable && (_fifo.CPReadWriteDistance > 0))
@ -129,11 +125,8 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize)
if (readPtr == _fifo.CPBreakpoint)
{
video_initialize.pLog("!!! BP irq raised",FALSE);
#ifdef _WIN32
InterlockedExchange((LONG*)&_fifo.bFF_Breakpoint, 1);
#else
Common::InterlockedExchange((int*)&_fifo.bFF_Breakpoint, 1);
#endif
Common::InterlockedExchange((LONG*)&_fifo.bFF_Breakpoint, 1);
video_initialize.pUpdateInterrupts();
break;
}
@ -163,20 +156,11 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize)
#endif
}
Video_SendFifoData(uData, distToSend);
#ifdef _WIN32
InterlockedExchange((LONG*)&_fifo.CPReadPointer, readPtr);
InterlockedExchangeAdd((LONG*)&_fifo.CPReadWriteDistance, -distToSend);
#else
Common::InterlockedExchange((int*)&_fifo.CPReadPointer, readPtr);
Common::InterlockedExchangeAdd((int*)&_fifo.CPReadWriteDistance, -distToSend);
#endif
Common::InterlockedExchange((LONG*)&_fifo.CPReadPointer, readPtr);
Common::InterlockedExchangeAdd((LONG*)&_fifo.CPReadWriteDistance, -distToSend);
}
//video_initialize.pLog("..........................IDLE",FALSE);
#ifdef _WIN32
InterlockedExchange((LONG*)&_fifo.CPReadIdle, 1);
#else
Common::InterlockedExchange((int*)&_fifo.CPReadIdle, 1);
#endif
Common::InterlockedExchange((LONG*)&_fifo.CPReadIdle, 1);
}
}
}