mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-01 21:52:41 +02:00
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:
parent
9692fca60e
commit
b64877d464
@ -123,6 +123,7 @@ inline u32 _rotr(u32 x, int shift) {
|
|||||||
return (x >> shift) | (x << (32 - shift));
|
return (x >> shift) | (x << (32 - shift));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define LONG int
|
||||||
#ifdef __LINUX__
|
#ifdef __LINUX__
|
||||||
typedef union _LARGE_INTEGER
|
typedef union _LARGE_INTEGER
|
||||||
{
|
{
|
||||||
|
@ -343,8 +343,11 @@ void Event::Wait()
|
|||||||
pthread_mutex_unlock(&mutex_);
|
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__))
|
#if defined(__GNUC__) && defined (__GNUC_MINOR__) && ((4 < __GNUC__) || (4 == __GNUC__ && 1 <= __GNUC_MINOR__))
|
||||||
return __sync_add_and_fetch(Addend, 1);
|
return __sync_add_and_fetch(Addend, 1);
|
||||||
#else
|
#else
|
||||||
@ -354,11 +357,15 @@ int InterlockedIncrement(int *Addend)
|
|||||||
: "0" (Increment), "m" (1)
|
: "0" (Increment), "m" (1)
|
||||||
: "memory");
|
: "memory");
|
||||||
return result + 1;
|
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__))
|
#if defined(__GNUC__) && defined (__GNUC_MINOR__) && ((4 < __GNUC__) || (4 == __GNUC__ && 1 <= __GNUC_MINOR__))
|
||||||
return __sync_add_and_fetch(Addend, Increment);
|
return __sync_add_and_fetch(Addend, Increment);
|
||||||
#else
|
#else
|
||||||
@ -369,14 +376,19 @@ int InterlockedExchangeAdd(int *Addend, int Increment)
|
|||||||
: "memory");
|
: "memory");
|
||||||
return result + Increment;
|
return result + Increment;
|
||||||
#endif
|
#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__))
|
#if defined(__GNUC__) && defined (__GNUC_MINOR__) && ((4 < __GNUC__) || (4 == __GNUC__ && 1 <= __GNUC_MINOR__))
|
||||||
return __sync_lock_test_and_set(Addend, Increment);
|
return __sync_lock_test_and_set(Addend, Increment);
|
||||||
#else
|
#else
|
||||||
// TODO:
|
// TODO:
|
||||||
#warning Support older GCC Versions
|
#error Implement support older GCC Versions
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,13 +171,9 @@ void UpdateInterrupts();
|
|||||||
|
|
||||||
//inline void WriteLow (u32& _reg, u16 lowbits) {_reg = (_reg & 0xFFFF0000) | lowbits;}
|
//inline void WriteLow (u32& _reg, u16 lowbits) {_reg = (_reg & 0xFFFF0000) | lowbits;}
|
||||||
//inline void WriteHigh(u32& _reg, u16 highbits) {_reg = (_reg & 0x0000FFFF) | ((u32)highbits << 16);}
|
//inline void WriteHigh(u32& _reg, u16 highbits) {_reg = (_reg & 0x0000FFFF) | ((u32)highbits << 16);}
|
||||||
#ifdef _WIN32
|
inline void WriteLow (volatile u32& _reg, u16 lowbits) {Common::InterlockedExchange((LONG*)&_reg,(_reg & 0xFFFF0000) | lowbits);}
|
||||||
inline void WriteLow (volatile u32& _reg, u16 lowbits) {InterlockedExchange((LONG*)&_reg,(_reg & 0xFFFF0000) | lowbits);}
|
inline void WriteHigh(volatile u32& _reg, u16 highbits) {Common::InterlockedExchange((LONG*)&_reg,(_reg & 0x0000FFFF) | ((u32)highbits << 16));}
|
||||||
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 u16 ReadLow (u32 _reg) {return (u16)(_reg & 0xFFFF);}
|
inline u16 ReadLow (u32 _reg) {return (u16)(_reg & 0xFFFF);}
|
||||||
inline u16 ReadHigh (u32 _reg) {return (u16)(_reg >> 16);}
|
inline u16 ReadHigh (u32 _reg) {return (u16)(_reg >> 16);}
|
||||||
|
|
||||||
@ -186,11 +182,7 @@ int et_UpdateInterrupts;
|
|||||||
// for GP watchdog hack
|
// for GP watchdog hack
|
||||||
void IncrementGPWDToken()
|
void IncrementGPWDToken()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
Common::InterlockedIncrement((LONG*)&fifo.Fake_GPWDToken);
|
||||||
InterlockedIncrement((LONG*)&fifo.Fake_GPWDToken);
|
|
||||||
#else
|
|
||||||
Common::InterlockedIncrement((int*)&fifo.Fake_GPWDToken);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check every FAKE_GP_WATCHDOG_PERIOD if a PE-frame-finish occured
|
// 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);
|
UCPCtrlReg tmpCtrl(_Value);
|
||||||
|
|
||||||
#ifdef _WIN32
|
Common::InterlockedExchange((LONG*)&fifo.bFF_GPReadEnable, tmpCtrl.GPReadEnable);
|
||||||
InterlockedExchange((LONG*)&fifo.bFF_GPReadEnable, tmpCtrl.GPReadEnable);
|
Common::InterlockedExchange((LONG*)&fifo.bFF_GPLinkEnable, tmpCtrl.GPLinkEnable);
|
||||||
InterlockedExchange((LONG*)&fifo.bFF_GPLinkEnable, tmpCtrl.GPLinkEnable);
|
Common::InterlockedExchange((LONG*)&fifo.bFF_BPEnable, tmpCtrl.BPEnable);
|
||||||
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
|
|
||||||
// TOCHECK (mb2): could BP irq be cleared with w16 to STATUS_REGISTER?
|
// 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
|
// 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.
|
// the game is of course faster but looks stable too.
|
||||||
@ -589,11 +576,7 @@ void GatherPipeBursted()
|
|||||||
fifo.CPWritePointer += GPFifo::GATHER_PIPE_SIZE;
|
fifo.CPWritePointer += GPFifo::GATHER_PIPE_SIZE;
|
||||||
if (fifo.CPWritePointer >= fifo.CPEnd)
|
if (fifo.CPWritePointer >= fifo.CPEnd)
|
||||||
fifo.CPWritePointer = fifo.CPBase;
|
fifo.CPWritePointer = fifo.CPBase;
|
||||||
#ifdef _WIN32
|
Common::InterlockedExchangeAdd((LONG*)&fifo.CPReadWriteDistance, GPFifo::GATHER_PIPE_SIZE);
|
||||||
InterlockedExchangeAdd((LONG*)&fifo.CPReadWriteDistance, GPFifo::GATHER_PIPE_SIZE);
|
|
||||||
#else
|
|
||||||
Common::InterlockedExchangeAdd((int*)&fifo.CPReadWriteDistance, GPFifo::GATHER_PIPE_SIZE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// High watermark overflow handling (hacked way)
|
// High watermark overflow handling (hacked way)
|
||||||
u32 ct=0;
|
u32 ct=0;
|
||||||
@ -717,11 +700,8 @@ void UpdateFifoRegister()
|
|||||||
else
|
else
|
||||||
dist = (wp - fifo.CPBase) + (fifo.CPEnd - rp);
|
dist = (wp - fifo.CPBase) + (fifo.CPEnd - rp);
|
||||||
//fifo.CPReadWriteDistance = dist;
|
//fifo.CPReadWriteDistance = dist;
|
||||||
#ifdef _WIN32
|
Common::InterlockedExchange((LONG*)&fifo.CPReadWriteDistance, dist);
|
||||||
InterlockedExchange((LONG*)&fifo.CPReadWriteDistance, dist);
|
|
||||||
#else
|
|
||||||
Common::InterlockedExchange((int*)&fifo.CPReadWriteDistance, dist);
|
|
||||||
#endif
|
|
||||||
if (!Core::g_CoreStartupParameter.bUseDualCore)
|
if (!Core::g_CoreStartupParameter.bUseDualCore)
|
||||||
CatchUpGPU();
|
CatchUpGPU();
|
||||||
}
|
}
|
||||||
|
@ -202,11 +202,7 @@ void SetToken(const u16 _token, const int _bSetTokenAcknowledge)
|
|||||||
{
|
{
|
||||||
// we do it directly from videoThread because of
|
// we do it directly from videoThread because of
|
||||||
// Super Monkey Ball Advance
|
// Super Monkey Ball Advance
|
||||||
#ifdef _WIN32
|
Common::InterlockedExchange((LONG*)&CommandProcessor::fifo.PEToken, _token);
|
||||||
InterlockedExchange((LONG*)&CommandProcessor::fifo.PEToken, _token);
|
|
||||||
#else
|
|
||||||
Common::InterlockedExchange((int*)&CommandProcessor::fifo.PEToken, _token);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,11 +104,7 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize)
|
|||||||
// check if we are able to run this buffer
|
// check if we are able to run this buffer
|
||||||
if ((_fifo.bFF_GPReadEnable) && _fifo.CPReadWriteDistance && !(_fifo.bFF_BPEnable && _fifo.bFF_Breakpoint))
|
if ((_fifo.bFF_GPReadEnable) && _fifo.CPReadWriteDistance && !(_fifo.bFF_BPEnable && _fifo.bFF_Breakpoint))
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
Common::InterlockedExchange((LONG*)&_fifo.CPReadIdle, 0);
|
||||||
InterlockedExchange((LONG*)&_fifo.CPReadIdle, 0);
|
|
||||||
#else
|
|
||||||
Common::InterlockedExchange((int*)&_fifo.CPReadIdle, 0);
|
|
||||||
#endif
|
|
||||||
//video_initialize.pLog("RUN...........................",FALSE);
|
//video_initialize.pLog("RUN...........................",FALSE);
|
||||||
int peek_counter = 0;
|
int peek_counter = 0;
|
||||||
while (_fifo.bFF_GPReadEnable && (_fifo.CPReadWriteDistance > 0))
|
while (_fifo.bFF_GPReadEnable && (_fifo.CPReadWriteDistance > 0))
|
||||||
@ -129,11 +125,8 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize)
|
|||||||
if (readPtr == _fifo.CPBreakpoint)
|
if (readPtr == _fifo.CPBreakpoint)
|
||||||
{
|
{
|
||||||
video_initialize.pLog("!!! BP irq raised",FALSE);
|
video_initialize.pLog("!!! BP irq raised",FALSE);
|
||||||
#ifdef _WIN32
|
Common::InterlockedExchange((LONG*)&_fifo.bFF_Breakpoint, 1);
|
||||||
InterlockedExchange((LONG*)&_fifo.bFF_Breakpoint, 1);
|
|
||||||
#else
|
|
||||||
Common::InterlockedExchange((int*)&_fifo.bFF_Breakpoint, 1);
|
|
||||||
#endif
|
|
||||||
video_initialize.pUpdateInterrupts();
|
video_initialize.pUpdateInterrupts();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -163,20 +156,11 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
Video_SendFifoData(uData, distToSend);
|
Video_SendFifoData(uData, distToSend);
|
||||||
#ifdef _WIN32
|
Common::InterlockedExchange((LONG*)&_fifo.CPReadPointer, readPtr);
|
||||||
InterlockedExchange((LONG*)&_fifo.CPReadPointer, readPtr);
|
Common::InterlockedExchangeAdd((LONG*)&_fifo.CPReadWriteDistance, -distToSend);
|
||||||
InterlockedExchangeAdd((LONG*)&_fifo.CPReadWriteDistance, -distToSend);
|
|
||||||
#else
|
|
||||||
Common::InterlockedExchange((int*)&_fifo.CPReadPointer, readPtr);
|
|
||||||
Common::InterlockedExchangeAdd((int*)&_fifo.CPReadWriteDistance, -distToSend);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
//video_initialize.pLog("..........................IDLE",FALSE);
|
//video_initialize.pLog("..........................IDLE",FALSE);
|
||||||
#ifdef _WIN32
|
Common::InterlockedExchange((LONG*)&_fifo.CPReadIdle, 1);
|
||||||
InterlockedExchange((LONG*)&_fifo.CPReadIdle, 1);
|
|
||||||
#else
|
|
||||||
Common::InterlockedExchange((int*)&_fifo.CPReadIdle, 1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user