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.
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
#include "../debug.h"
|
||||
#include "../os/windows/win32.h"
|
||||
#include "../core/mem_func.hpp"
|
||||
#include "../thread/thread.h"
|
||||
#include "../thread.h"
|
||||
#include "../fileio_func.h"
|
||||
#include "../base_media_base.h"
|
||||
#include "dmusic.h"
|
||||
@@ -139,7 +139,7 @@ static struct {
|
||||
} _playback;
|
||||
|
||||
/** Handle to our worker thread. */
|
||||
static ThreadObject *_dmusic_thread = NULL;
|
||||
static std::thread _dmusic_thread;
|
||||
/** Event to signal the thread that it should look at a state change. */
|
||||
static HANDLE _thread_event = NULL;
|
||||
/** Lock access to playback data that is not thread-safe. */
|
||||
@@ -597,7 +597,7 @@ static void TransmitNotesOff(IDirectMusicBuffer *buffer, REFERENCE_TIME block_ti
|
||||
Sleep(Clamp((block_time - cur_time) / MS_TO_REFTIME, 5, 1000));
|
||||
}
|
||||
|
||||
static void MidiThreadProc(void *)
|
||||
static void MidiThreadProc()
|
||||
{
|
||||
DEBUG(driver, 2, "DMusic: Entering playback thread");
|
||||
|
||||
@@ -1169,7 +1169,7 @@ const char *MusicDriver_DMusic::Start(const char * const *parm)
|
||||
_thread_event = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
if (_thread_event == NULL) return "Can't create thread shutdown event";
|
||||
|
||||
if (!ThreadObject::New(&MidiThreadProc, this, &_dmusic_thread, "ottd:dmusic")) return "Can't create MIDI output thread";
|
||||
if (!StartNewThread(&_dmusic_thread, "ottd:dmusic", &MidiThreadProc)) return "Can't create MIDI output thread";
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1183,10 +1183,10 @@ MusicDriver_DMusic::~MusicDriver_DMusic()
|
||||
|
||||
void MusicDriver_DMusic::Stop()
|
||||
{
|
||||
if (_dmusic_thread != NULL) {
|
||||
if (_dmusic_thread.joinable()) {
|
||||
_playback.shutdown = true;
|
||||
SetEvent(_thread_event);
|
||||
_dmusic_thread->Join();
|
||||
_dmusic_thread.join();
|
||||
}
|
||||
|
||||
/* Unloaded any instruments we loaded. */
|
||||
|
Reference in New Issue
Block a user