Gif: port code to std::atomic

This commit is contained in:
Gregory Hainaut 2016-02-22 20:44:49 +01:00
parent 92078b1c58
commit 3a9bd90a3b
3 changed files with 7 additions and 7 deletions

View File

@ -118,14 +118,14 @@ void Gif_AddCompletedGSPacket(GS_Packet& gsPack, GIF_PATH path) {
} }
else { else {
pxAssertDev(!gsPack.readAmount, "Gif Unit - gsPack.readAmount only valid for MTVU path 1!"); pxAssertDev(!gsPack.readAmount, "Gif Unit - gsPack.readAmount only valid for MTVU path 1!");
AtomicExchangeAdd(gifUnit.gifPath[path].readAmount, gsPack.size); gifUnit.gifPath[path].readAmount.fetch_add(gsPack.size);
GetMTGS().SendSimpleGSPacket(GS_RINGTYPE_GSPACKET, gsPack.offset, gsPack.size, path); GetMTGS().SendSimpleGSPacket(GS_RINGTYPE_GSPACKET, gsPack.offset, gsPack.size, path);
} }
} }
void Gif_AddBlankGSPacket(u32 size, GIF_PATH path) { void Gif_AddBlankGSPacket(u32 size, GIF_PATH path) {
//DevCon.WriteLn("Adding Blank Gif Packet [size=%x]", size); //DevCon.WriteLn("Adding Blank Gif Packet [size=%x]", size);
AtomicExchangeAdd(gifUnit.gifPath[path].readAmount, size); gifUnit.gifPath[path].readAmount.fetch_add(size);
GetMTGS().SendSimpleGSPacket(GS_RINGTYPE_GSPACKET, ~0u, size, path); GetMTGS().SendSimpleGSPacket(GS_RINGTYPE_GSPACKET, ~0u, size, path);
} }

View File

@ -153,7 +153,7 @@ struct Gif_Path_MTVU {
}; };
struct Gif_Path { struct Gif_Path {
__aligned(4) volatile s32 readAmount; // Amount of data MTGS still needs to read std::atomic<int> readAmount; // Amount of data MTGS still needs to read
u8* buffer; // Path packet buffer u8* buffer; // Path packet buffer
u32 buffSize; // Full size of buffer u32 buffSize; // Full size of buffer
u32 buffLimit; // Cut off limit to wrap around u32 buffLimit; // Cut off limit to wrap around
@ -195,7 +195,7 @@ struct Gif_Path {
} }
bool isMTVU() const { return !idx && THREAD_VU1; } bool isMTVU() const { return !idx && THREAD_VU1; }
s32 getReadAmount() { return AtomicRead(readAmount) + gsPack.readAmount; } s32 getReadAmount() { return readAmount.load() + gsPack.readAmount; }
bool hasDataRemaining() const { return curOffset < curSize; } bool hasDataRemaining() const { return curOffset < curSize; }
bool isDone() const { return isMTVU() ? !mtvu.fakePackets : (!hasDataRemaining() && (state == GIF_PATH_IDLE || state == GIF_PATH_WAIT)); } bool isDone() const { return isMTVU() ? !mtvu.fakePackets : (!hasDataRemaining() && (state == GIF_PATH_IDLE || state == GIF_PATH_WAIT)); }
@ -380,7 +380,7 @@ struct Gif_Path {
void FinishGSPacketMTVU() { void FinishGSPacketMTVU() {
if (1) { if (1) {
ScopedLock lock(mtvu.gsPackMutex); ScopedLock lock(mtvu.gsPackMutex);
AtomicExchangeAdd(readAmount, gsPack.size + gsPack.readAmount); readAmount.fetch_add(gsPack.size + gsPack.readAmount);
mtvu.gsPackQueue.push_back(gsPack); mtvu.gsPackQueue.push_back(gsPack);
} }
gsPack.Reset(); gsPack.Reset();

View File

@ -395,7 +395,7 @@ void SysMtgsThread::ExecuteTaskInThread()
u32 offset = tag.data[0]; u32 offset = tag.data[0];
u32 size = tag.data[1]; u32 size = tag.data[1];
if (offset != ~0u) GSgifTransfer((u32*)&path.buffer[offset], size/16); if (offset != ~0u) GSgifTransfer((u32*)&path.buffer[offset], size/16);
AtomicExchangeSub(path.readAmount, size); path.readAmount.fetch_sub(size);
break; break;
} }
@ -409,7 +409,7 @@ void SysMtgsThread::ExecuteTaskInThread()
Gif_Path& path = gifUnit.gifPath[GIF_PATH_1]; Gif_Path& path = gifUnit.gifPath[GIF_PATH_1];
GS_Packet gsPack = path.GetGSPacketMTVU(); // Get vu1 program's xgkick packet(s) GS_Packet gsPack = path.GetGSPacketMTVU(); // Get vu1 program's xgkick packet(s)
if (gsPack.size) GSgifTransfer((u32*)&path.buffer[gsPack.offset], gsPack.size/16); if (gsPack.size) GSgifTransfer((u32*)&path.buffer[gsPack.offset], gsPack.size/16);
AtomicExchangeSub(path.readAmount, gsPack.size + gsPack.readAmount); path.readAmount.fetch_sub(gsPack.size + gsPack.readAmount);
path.PopGSPacketMTVU(); // Should be done last, for proper Gif_MTGS_Wait() path.PopGSPacketMTVU(); // Should be done last, for proper Gif_MTGS_Wait()
break; break;
} }