summaryrefslogtreecommitdiff
path: root/src/music
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2019-03-11 00:45:39 +0100
committerMichael Lutz <michi@icosahedron.de>2019-04-06 11:27:39 +0200
commit05f4e7360886e36b221ef5c3af4426625a3de686 (patch)
tree27aed9756e80eca86ff95f5805901a80048b0fb1 /src/music
parent3b86f54fc739510277f434c68e17a93ab6448ed4 (diff)
downloadopenttd-05f4e7360886e36b221ef5c3af4426625a3de686.tar.xz
Codechange: Replace custom mutex code with C++11 mutex'es.
A conforming compiler with a valid <mutex>-header is expected. Most parts of the code assume that locking a mutex will never fail unexpectedly, which is generally true on all common platforms that don't just pretend to be C++11. The use of condition variables in driver code is checked.
Diffstat (limited to 'src/music')
-rw-r--r--src/music/dmusic.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp
index 241ab191b..4b9a22c72 100644
--- a/src/music/dmusic.cpp
+++ b/src/music/dmusic.cpp
@@ -30,6 +30,7 @@
#include <dmksctrl.h>
#include <dmusicc.h>
#include <algorithm>
+#include <mutex>
#include "../safeguards.h"
@@ -142,7 +143,7 @@ static ThreadObject *_dmusic_thread = NULL;
/** 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. */
-static ThreadMutex *_thread_mutex = NULL;
+static std::mutex _thread_mutex;
/** The direct music object manages buffers and ports. */
static IDirectMusic *_music = NULL;
@@ -655,7 +656,7 @@ static void MidiThreadProc(void *)
DEBUG(driver, 2, "DMusic thread: Starting playback");
{
/* New scope to limit the time the mutex is locked. */
- ThreadMutexLocker lock(_thread_mutex);
+ std::lock_guard<std::mutex> lock(_thread_mutex);
current_file.MoveFrom(_playback.next_file);
std::swap(_playback.next_segment, current_segment);
@@ -1167,8 +1168,6 @@ const char *MusicDriver_DMusic::Start(const char * const *parm)
/* Create playback thread and synchronization primitives. */
_thread_event = CreateEvent(NULL, FALSE, FALSE, NULL);
if (_thread_event == NULL) return "Can't create thread shutdown event";
- _thread_mutex = ThreadMutex::New();
- if (_thread_mutex == NULL) return "Can't create thread mutex";
if (!ThreadObject::New(&MidiThreadProc, this, &_dmusic_thread, "ottd:dmusic")) return "Can't create MIDI output thread";
@@ -1223,7 +1222,6 @@ void MusicDriver_DMusic::Stop()
}
CloseHandle(_thread_event);
- delete _thread_mutex;
CoUninitialize();
}
@@ -1231,7 +1229,7 @@ void MusicDriver_DMusic::Stop()
void MusicDriver_DMusic::PlaySong(const MusicSongInfo &song)
{
- ThreadMutexLocker lock(_thread_mutex);
+ std::lock_guard<std::mutex> lock(_thread_mutex);
if (!_playback.next_file.LoadSong(song)) return;