aboutsummaryrefslogtreecommitdiffstats
path: root/src/MusicPipe.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-04 20:50:26 +0100
committerMax Kellermann <max@duempel.org>2013-01-04 21:24:29 +0100
commitefbfe66f21a8865454bc7a9e32305c84c09ba4be (patch)
tree7ea7b79cba8e3356c7735ef98bd251ca513d4ade /src/MusicPipe.cxx
parent6886063703704796f03d7bfe35747fc2cb01ded2 (diff)
downloadmpd-efbfe66f21a8865454bc7a9e32305c84c09ba4be.tar.gz
mpd-efbfe66f21a8865454bc7a9e32305c84c09ba4be.tar.xz
mpd-efbfe66f21a8865454bc7a9e32305c84c09ba4be.zip
Mutex: new wrapper for std::mutex, replaces GMutex
Diffstat (limited to 'src/MusicPipe.cxx')
-rw-r--r--src/MusicPipe.cxx38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/MusicPipe.cxx b/src/MusicPipe.cxx
index 38c3af776..010da97ba 100644
--- a/src/MusicPipe.cxx
+++ b/src/MusicPipe.cxx
@@ -21,6 +21,7 @@
#include "MusicPipe.hxx"
#include "MusicBuffer.hxx"
#include "MusicChunk.hxx"
+#include "thread/Mutex.hxx"
#include <glib.h>
@@ -37,16 +38,14 @@ struct music_pipe {
unsigned size;
/** a mutex which protects #head and #tail_r */
- GMutex *mutex;
+ mutable Mutex mutex;
#ifndef NDEBUG
struct audio_format audio_format;
#endif
music_pipe()
- :head(nullptr), tail_r(&head),
- size(0),
- mutex(g_mutex_new()) {
+ :head(nullptr), tail_r(&head), size(0) {
#ifndef NDEBUG
audio_format_clear(&audio_format);
#endif
@@ -55,8 +54,6 @@ struct music_pipe {
~music_pipe() {
assert(head == nullptr);
assert(tail_r == &head);
-
- g_mutex_free(mutex);
}
};
@@ -89,17 +86,12 @@ bool
music_pipe_contains(const struct music_pipe *mp,
const struct music_chunk *chunk)
{
- g_mutex_lock(mp->mutex);
+ const ScopeLock protect(mp->mutex);
for (const struct music_chunk *i = mp->head;
- i != NULL; i = i->next) {
- if (i == chunk) {
- g_mutex_unlock(mp->mutex);
+ i != NULL; i = i->next)
+ if (i == chunk)
return true;
- }
- }
-
- g_mutex_unlock(mp->mutex);
return false;
}
@@ -115,11 +107,9 @@ music_pipe_peek(const struct music_pipe *mp)
struct music_chunk *
music_pipe_shift(struct music_pipe *mp)
{
- struct music_chunk *chunk;
-
- g_mutex_lock(mp->mutex);
+ const ScopeLock protect(mp->mutex);
- chunk = mp->head;
+ struct music_chunk *chunk = mp->head;
if (chunk != NULL) {
assert(!music_chunk_is_empty(chunk));
@@ -145,8 +135,6 @@ music_pipe_shift(struct music_pipe *mp)
#endif
}
- g_mutex_unlock(mp->mutex);
-
return chunk;
}
@@ -165,7 +153,7 @@ music_pipe_push(struct music_pipe *mp, struct music_chunk *chunk)
assert(!music_chunk_is_empty(chunk));
assert(chunk->length == 0 || audio_format_valid(&chunk->audio_format));
- g_mutex_lock(mp->mutex);
+ const ScopeLock protect(mp->mutex);
assert(mp->size > 0 || !audio_format_defined(&mp->audio_format));
assert(!audio_format_defined(&mp->audio_format) ||
@@ -181,15 +169,11 @@ music_pipe_push(struct music_pipe *mp, struct music_chunk *chunk)
mp->tail_r = &chunk->next;
++mp->size;
-
- g_mutex_unlock(mp->mutex);
}
unsigned
music_pipe_size(const struct music_pipe *mp)
{
- g_mutex_lock(mp->mutex);
- unsigned size = mp->size;
- g_mutex_unlock(mp->mutex);
- return size;
+ const ScopeLock protect(mp->mutex);
+ return mp->size;
}