summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
Diffstat (limited to 'src/video')
-rw-r--r--src/video/dedicated_v.cpp3
-rw-r--r--src/video/sdl_v.cpp15
-rw-r--r--src/video/win32_v.cpp14
3 files changed, 12 insertions, 20 deletions
diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp
index 58d7d04e0..e0096c893 100644
--- a/src/video/dedicated_v.cpp
+++ b/src/video/dedicated_v.cpp
@@ -73,6 +73,7 @@ static void DedicatedSignalHandler(int sig)
# include <time.h>
# include <tchar.h>
# include "../os/windows/win32.h"
+# include "../thread.h"
static HANDLE _hInputReady, _hWaitForInputHandling;
static HANDLE _hThread; // Thread to close
static char _win_console_thread_buffer[200];
@@ -80,7 +81,7 @@ static char _win_console_thread_buffer[200];
/* Windows Console thread. Just loop and signal when input has been received */
static void WINAPI CheckForConsoleInput()
{
- SetWin32ThreadName(-1, "ottd:win-console");
+ SetCurrentThreadName("ottd:win-console");
DWORD nb;
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
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;
}
}
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index ef7bc89e2..5aec329b2 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -19,7 +19,7 @@
#include "../core/math_func.hpp"
#include "../core/random_func.hpp"
#include "../texteff.hpp"
-#include "../thread/thread.h"
+#include "../thread.h"
#include "../progress.h"
#include "../window_gui.h"
#include "../window_func.h"
@@ -67,8 +67,6 @@ DWORD _imm_props;
/** 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. */
@@ -395,7 +393,7 @@ static void PaintWindow(HDC dc)
DeleteDC(dc2);
}
-static void PaintWindowThread(void *)
+static void PaintWindowThread()
{
/* First tell the main thread we're started */
std::unique_lock<std::recursive_mutex> lock(*_draw_mutex);
@@ -426,8 +424,6 @@ static void PaintWindowThread(void *)
_draw_signal->wait(*_draw_mutex);
}
-
- _draw_thread->Exit();
}
/** Forward key presses to the window system. */
@@ -1190,6 +1186,7 @@ void VideoDriver_Win32::MainLoop()
uint32 last_cur_ticks = cur_ticks;
uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
+ std::thread draw_thread;
std::unique_lock<std::recursive_mutex> draw_lock;
if (_draw_threaded) {
@@ -1206,7 +1203,7 @@ void VideoDriver_Win32::MainLoop()
draw_lock = std::unique_lock<std::recursive_mutex>(*_draw_mutex);
_draw_continue = true;
- _draw_threaded = ThreadObject::New(&PaintWindowThread, NULL, &_draw_thread, "ottd:draw-win32");
+ _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-win32", &PaintWindowThread);
/* Free the mutex if we won't be able to use it. */
if (!_draw_threaded) {
@@ -1308,11 +1305,10 @@ void VideoDriver_Win32::MainLoop()
_draw_signal->notify_all();
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;
}