Replaced Common::Thread with a partial implementation of std::thread. (rvalue references are used if available, <thread> is used if possible) Eliminates the need to use dynamic memory allocation for threads, so it's impossible to forget to delete a thread or set a pointer to NULL. Enables use of type-safe thread functions, no need to cast to and from void*. I've made sure the code compiles in vs08 and tested the functionality of "StdThread.h" on Linux so I'm hoping everything will work :p. In the future "StdThread.h" can be removed (maybe when OS X ships with gcc 4.4 and vs2015 is released :p).

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6933 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak
2011-01-27 20:47:58 +00:00
parent 0371f15c23
commit 2c05c49a04
29 changed files with 484 additions and 396 deletions

View File

@ -69,7 +69,7 @@ static u8 *undoLoad = NULL;
static bool const bCompressed = true;
static Common::Thread *saveThread = NULL;
static std::thread saveThread;
// Don't forget to increase this after doing changes on the savestate system
@ -159,9 +159,8 @@ void VerifyBufferStateCallback(u64 userdata, int cyclesLate)
state_op_in_progress = false;
}
THREAD_RETURN CompressAndDumpState(void *pArgs)
void CompressAndDumpState(saveStruct* saveArg)
{
saveStruct *saveArg = (saveStruct *)pArgs;
u8 *buffer = saveArg->buffer;
size_t sz = saveArg->size;
lzo_uint out_len = 0;
@ -185,7 +184,7 @@ THREAD_RETURN CompressAndDumpState(void *pArgs)
{
Core::DisplayMessage("Could not save state", 2000);
delete[] buffer;
return 0;
return;
}
// Setting up the header
@ -229,7 +228,6 @@ THREAD_RETURN CompressAndDumpState(void *pArgs)
filename.c_str()).c_str(), 2000);
state_op_in_progress = false;
return 0;
}
void SaveStateCallback(u64 userdata, int cyclesLate)
@ -263,7 +261,7 @@ void SaveStateCallback(u64 userdata, int cyclesLate)
Core::DisplayMessage("Saving State...", 1000);
saveThread = new Common::Thread(CompressAndDumpState, saveData);
saveThread = std::thread(CompressAndDumpState, saveData);
// Resume the clock
PowerPC::Start();
@ -592,10 +590,9 @@ void State_VerifyBuffer(u8 **buffer)
void State_Flush()
{
// If already saving state, wait for it to finish
if (saveThread)
if (saveThread.joinable())
{
delete saveThread;
saveThread = NULL;
saveThread.join();
}
}