summaryrefslogtreecommitdiff
path: root/src/video/sdl_v.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2019-03-17 01:59:46 +0100
committerMichael Lutz <michi@icosahedron.de>2019-04-06 11:27:39 +0200
commit05bc2ed7cbe07cb4cd535932f10778b35f72e944 (patch)
tree0faaf12fd1bafb0786236ffc82052e8b83dfca60 /src/video/sdl_v.cpp
parent05f4e7360886e36b221ef5c3af4426625a3de686 (diff)
downloadopenttd-05bc2ed7cbe07cb4cd535932f10778b35f72e944.tar.xz
Codechange: Replace custom thread code with C++11 thread objects.
We assume a conforming C++11 compiler environment that has a valid <thread>-header. Failure to run a real thread is handled gracefully.
Diffstat (limited to 'src/video/sdl_v.cpp')
-rw-r--r--src/video/sdl_v.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index b1609f7b3..5e3fb4552 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -17,7 +17,7 @@
#include "../rev.h"
#include "../blitter/factory.hpp"
#include "../network/network.h"
-#include "../thread/thread.h"
+#include "../thread.h"
#include "../progress.h"
#include "../core/random_func.hpp"
#include "../core/math_func.hpp"
@@ -38,8 +38,6 @@ static bool _all_modes;
/** Whether the drawing is/may be done in a separate thread. */
static bool _draw_threaded;
-/** Thread used to 'draw' to the screen, i.e. push data to the screen. */
-static ThreadObject *_draw_thread = NULL;
/** Mutex to keep the access to the shared memory controlled. */
static std::recursive_mutex *_draw_mutex = NULL;
/** Signal to draw the next frame. */
@@ -173,7 +171,7 @@ static void DrawSurfaceToScreen()
}
}
-static void DrawSurfaceToScreenThread(void *)
+static void DrawSurfaceToScreenThread()
{
/* First tell the main thread we're started */
std::unique_lock<std::recursive_mutex> lock(*_draw_mutex);
@@ -188,8 +186,6 @@ static void DrawSurfaceToScreenThread(void *)
DrawSurfaceToScreen();
_draw_signal->wait(lock);
}
-
- _draw_thread->Exit();
}
static const Dimension _default_resolutions[] = {
@@ -671,6 +667,7 @@ void VideoDriver_SDL::MainLoop()
CheckPaletteAnim();
+ std::thread draw_thread;
std::unique_lock<std::recursive_mutex> draw_lock;
if (_draw_threaded) {
/* Initialise the mutex first, because that's the thing we *need*
@@ -683,7 +680,7 @@ void VideoDriver_SDL::MainLoop()
_draw_signal = new std::condition_variable_any();
_draw_continue = true;
- _draw_threaded = ThreadObject::New(&DrawSurfaceToScreenThread, NULL, &_draw_thread, "ottd:draw-sdl");
+ _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-sdl", &DrawSurfaceToScreenThread);
/* Free the mutex if we won't be able to use it. */
if (!_draw_threaded) {
@@ -795,15 +792,13 @@ void VideoDriver_SDL::MainLoop()
_draw_signal->notify_one();
if (draw_lock.owns_lock()) draw_lock.unlock();
draw_lock.release();
- _draw_thread->Join();
+ draw_thread.join();
delete _draw_mutex;
delete _draw_signal;
- delete _draw_thread;
_draw_mutex = NULL;
_draw_signal = NULL;
- _draw_thread = NULL;
}
}