mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
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:
@ -108,7 +108,7 @@ void UpdateFPSDisplay(const char *text)
|
||||
}
|
||||
|
||||
#if defined(HAVE_X11) && HAVE_X11
|
||||
THREAD_RETURN XEventThread(void *pArg);
|
||||
void XEventThread();
|
||||
|
||||
void CreateXWindow (void)
|
||||
{
|
||||
@ -137,7 +137,7 @@ void CreateXWindow (void)
|
||||
XMapRaised(GLWin.evdpy, GLWin.win);
|
||||
XSync(GLWin.evdpy, True);
|
||||
|
||||
GLWin.xEventThread = new Common::Thread(XEventThread, NULL);
|
||||
GLWin.xEventThread = std::thread(XEventThread);
|
||||
}
|
||||
|
||||
void DestroyXWindow(void)
|
||||
@ -150,7 +150,7 @@ void DestroyXWindow(void)
|
||||
XFreeColormap(GLWin.evdpy, GLWin.attr.colormap);
|
||||
}
|
||||
|
||||
THREAD_RETURN XEventThread(void *pArg)
|
||||
void XEventThread()
|
||||
{
|
||||
// Free look variables
|
||||
static bool mouseLookEnabled = false;
|
||||
@ -305,7 +305,6 @@ THREAD_RETURN XEventThread(void *pArg)
|
||||
}
|
||||
Common::SleepCurrentThread(20);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -72,7 +72,7 @@ typedef struct {
|
||||
XVisualInfo *vi;
|
||||
GLXContext ctx;
|
||||
XSetWindowAttributes attr;
|
||||
Common::Thread *xEventThread;
|
||||
std::thread xEventThread;
|
||||
int x, y;
|
||||
unsigned int width, height;
|
||||
#endif
|
||||
|
@ -98,7 +98,7 @@ static bool s_bHaveCoverageMSAA = false;
|
||||
static u32 s_blendMode;
|
||||
|
||||
#if defined(HAVE_WX) && HAVE_WX
|
||||
static Common::Thread *scrshotThread = 0;
|
||||
static std::thread scrshotThread;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -490,8 +490,8 @@ Renderer::~Renderer()
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_WX) && HAVE_WX
|
||||
if (scrshotThread)
|
||||
delete scrshotThread;
|
||||
if (scrshotThread.joinable())
|
||||
scrshotThread.join();
|
||||
#endif
|
||||
|
||||
delete g_framebuffer_manager;
|
||||
@ -1496,10 +1496,8 @@ void Renderer::FlipImageData(u8 *data, int w, int h)
|
||||
}
|
||||
|
||||
#if defined(HAVE_WX) && HAVE_WX
|
||||
THREAD_RETURN TakeScreenshot(void *pArgs)
|
||||
void TakeScreenshot(ScrStrct* threadStruct)
|
||||
{
|
||||
ScrStrct *threadStruct = (ScrStrct *)pArgs;
|
||||
|
||||
// These will contain the final image size
|
||||
float FloatW = (float)threadStruct->W;
|
||||
float FloatH = (float)threadStruct->H;
|
||||
@ -1538,8 +1536,6 @@ THREAD_RETURN TakeScreenshot(void *pArgs)
|
||||
OSD::AddMessage(StringFromFormat("Saved %i x %i %s", (int)FloatW, (int)FloatH,
|
||||
threadStruct->filename.c_str()).c_str(), 2000);
|
||||
delete threadStruct;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1569,20 +1565,17 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle
|
||||
// Create wxImage
|
||||
wxImage *a = new wxImage(W, H, data);
|
||||
|
||||
if (scrshotThread)
|
||||
{
|
||||
delete scrshotThread;
|
||||
scrshotThread = NULL;
|
||||
}
|
||||
if (scrshotThread.joinable())
|
||||
scrshotThread.join();
|
||||
|
||||
ScrStrct *threadStruct = new ScrStrct;
|
||||
threadStruct->filename = filename;
|
||||
threadStruct->img = a;
|
||||
threadStruct->H = H; threadStruct->W = W;
|
||||
|
||||
scrshotThread = new Common::Thread(TakeScreenshot, threadStruct);
|
||||
scrshotThread = std::thread(TakeScreenshot, threadStruct);
|
||||
#ifdef _WIN32
|
||||
scrshotThread->SetPriority(THREAD_PRIORITY_BELOW_NORMAL);
|
||||
SetThreadPriority(scrshotThread.native_handle(), THREAD_PRIORITY_BELOW_NORMAL);
|
||||
#endif
|
||||
bool result = true;
|
||||
|
||||
|
Reference in New Issue
Block a user