aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-27 17:20:50 +0100
committerMax Kellermann <max@duempel.org>2013-01-27 18:39:32 +0100
commit6f3d70b5e24cebbd6fd8c3a665a801628ef912ff (patch)
tree88ab67b76bac4b88422c3debe7c46d6168a71934
parent257a0dee758049586efbf0dc3f0339b0cef03456 (diff)
DecoderControl, InputStream: use Mutex/Cond instead of GMutex/GCond
-rw-r--r--src/ArchivePlugin.cxx2
-rw-r--r--src/ArchivePlugin.hxx8
-rw-r--r--src/DecoderAPI.cxx14
-rw-r--r--src/DecoderControl.cxx7
-rw-r--r--src/DecoderControl.hxx18
-rw-r--r--src/DecoderInternal.cxx2
-rw-r--r--src/DecoderThread.cxx4
-rw-r--r--src/InputInternal.cxx12
-rw-r--r--src/InputInternal.hxx6
-rw-r--r--src/InputPlugin.hxx2
-rw-r--r--src/InputStream.cxx32
-rw-r--r--src/InputStream.hxx10
-rw-r--r--src/PlaylistAny.cxx4
-rw-r--r--src/PlaylistAny.hxx5
-rw-r--r--src/PlaylistMapper.cxx8
-rw-r--r--src/PlaylistMapper.hxx5
-rw-r--r--src/PlaylistPlugin.hxx7
-rw-r--r--src/PlaylistPrint.cxx12
-rw-r--r--src/PlaylistQueue.cxx12
-rw-r--r--src/PlaylistRegistry.cxx8
-rw-r--r--src/PlaylistRegistry.hxx7
-rw-r--r--src/SongUpdate.cxx16
-rw-r--r--src/TagFile.cxx14
-rw-r--r--src/archive/Bzip2ArchivePlugin.cxx9
-rw-r--r--src/archive/Iso9660ArchivePlugin.cxx2
-rw-r--r--src/archive/ZzipArchivePlugin.cxx2
-rw-r--r--src/decoder/WavpackDecoderPlugin.cxx4
-rw-r--r--src/input/ArchiveInputPlugin.cxx2
-rw-r--r--src/input/CdioParanoiaInputPlugin.cxx4
-rw-r--r--src/input/CurlInputPlugin.cxx39
-rw-r--r--src/input/DespotifyInputPlugin.cxx2
-rw-r--r--src/input/FfmpegInputPlugin.cxx2
-rw-r--r--src/input/FileInputPlugin.cxx4
-rw-r--r--src/input/MmsInputPlugin.cxx4
-rw-r--r--src/input/RewindInputPlugin.cxx2
-rw-r--r--src/input/SoupInputPlugin.cxx39
-rw-r--r--src/input_stream.h10
-rw-r--r--src/playlist/DespotifyPlaylistPlugin.cxx4
-rw-r--r--src/playlist/EmbeddedCuePlaylistPlugin.cxx4
-rw-r--r--src/playlist/LastFMPlaylistPlugin.cxx14
-rw-r--r--src/playlist/SoundCloudPlaylistPlugin.cxx11
-rw-r--r--test/dump_playlist.cxx7
-rw-r--r--test/dump_text_file.cxx7
-rw-r--r--test/read_tags.cxx15
-rw-r--r--test/run_decoder.cxx7
-rw-r--r--test/run_input.cxx7
46 files changed, 182 insertions, 234 deletions
diff --git a/src/ArchivePlugin.cxx b/src/ArchivePlugin.cxx
index b5cb0f07..42c90eec 100644
--- a/src/ArchivePlugin.cxx
+++ b/src/ArchivePlugin.cxx
@@ -82,7 +82,7 @@ archive_file_scan_next(struct archive_file *file)
struct input_stream *
archive_file_open_stream(struct archive_file *file, const char *path,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r)
{
assert(file != NULL);
diff --git a/src/ArchivePlugin.hxx b/src/ArchivePlugin.hxx
index fe701460..66ec6d83 100644
--- a/src/ArchivePlugin.hxx
+++ b/src/ArchivePlugin.hxx
@@ -20,7 +20,9 @@
#ifndef MPD_ARCHIVE_PLUGIN_HXX
#define MPD_ARCHIVE_PLUGIN_HXX
-#include <glib.h>
+#include "thread/Mutex.hxx"
+#include "thread/Cond.hxx"
+#include "gerror.h"
struct input_stream;
struct archive_file;
@@ -71,7 +73,7 @@ struct archive_plugin {
*/
struct input_stream *(*open_stream)(struct archive_file *af,
const char *path,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r);
/**
@@ -101,7 +103,7 @@ archive_file_scan_next(struct archive_file *file);
struct input_stream *
archive_file_open_stream(struct archive_file *file, const char *path,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r);
#endif
diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx
index 56c25e48..857ee72d 100644
--- a/src/DecoderAPI.cxx
+++ b/src/DecoderAPI.cxx
@@ -67,7 +67,7 @@ decoder_initialized(struct decoder *decoder,
dc->Lock();
dc->state = DECODE_STATE_DECODE;
- g_cond_signal(dc->client_cond);
+ dc->client_cond.signal();
dc->Unlock();
g_debug("audio_format=%s, seekable=%s",
@@ -192,7 +192,7 @@ decoder_command_finished(struct decoder *decoder)
}
dc->command = DECODE_COMMAND_NONE;
- g_cond_signal(dc->client_cond);
+ dc->client_cond.signal();
dc->Unlock();
}
@@ -285,7 +285,7 @@ size_t decoder_read(struct decoder *decoder,
if (input_stream_available(is))
break;
- g_cond_wait(is->cond, is->mutex);
+ is->cond->wait(*is->mutex);
}
nbytes = input_stream_read(is, buffer, length, &error);
@@ -324,7 +324,7 @@ do_send_tag(struct decoder *decoder, const struct tag *tag)
/* there is a partial chunk - flush it, we want the
tag in a new chunk */
decoder_flush_chunk(decoder);
- g_cond_signal(decoder->dc->client_cond);
+ decoder->dc->client_cond.signal();
}
assert(decoder->chunk == NULL);
@@ -437,7 +437,7 @@ decoder_data(struct decoder *decoder,
if (dest == NULL) {
/* the chunk is full, flush it */
decoder_flush_chunk(decoder);
- g_cond_signal(dc->client_cond);
+ dc->client_cond.signal();
continue;
}
@@ -456,7 +456,7 @@ decoder_data(struct decoder *decoder,
if (full) {
/* the chunk is full, flush it */
decoder_flush_chunk(decoder);
- g_cond_signal(dc->client_cond);
+ dc->client_cond.signal();
}
data = (const uint8_t *)data + nbytes;
@@ -551,7 +551,7 @@ decoder_replay_gain(struct decoder *decoder,
replay gain values affect the following
samples */
decoder_flush_chunk(decoder);
- g_cond_signal(decoder->dc->client_cond);
+ decoder->dc->client_cond.signal();
}
} else
decoder->replay_gain_serial = 0;
diff --git a/src/DecoderControl.cxx b/src/DecoderControl.cxx
index 3661beaf..c2331105 100644
--- a/src/DecoderControl.cxx
+++ b/src/DecoderControl.cxx
@@ -29,8 +29,6 @@
decoder_control::decoder_control()
:thread(nullptr),
- mutex(g_mutex_new()), cond(g_cond_new()),
- client_cond(g_cond_new()),
state(DECODE_STATE_STOP),
command(DECODE_COMMAND_NONE),
song(nullptr),
@@ -45,9 +43,6 @@ decoder_control::~decoder_control()
if (song != NULL)
song_free(song);
- g_cond_free(client_cond);
- g_cond_free(cond);
- g_mutex_free(mutex);
g_free(mixramp_start);
g_free(mixramp_end);
g_free(mixramp_prev_end);
@@ -57,7 +52,7 @@ static void
dc_command_wait_locked(struct decoder_control *dc)
{
while (dc->command != DECODE_COMMAND_NONE)
- g_cond_wait(dc->client_cond, dc->mutex);
+ dc->WaitForDecoder();
}
static void
diff --git a/src/DecoderControl.hxx b/src/DecoderControl.hxx
index f7769fa6..c2d7b33a 100644
--- a/src/DecoderControl.hxx
+++ b/src/DecoderControl.hxx
@@ -22,6 +22,8 @@
#include "decoder_command.h"
#include "audio_format.h"
+#include "thread/Mutex.hxx"
+#include "thread/Cond.hxx"
#include <glib.h>
@@ -49,20 +51,20 @@ struct decoder_control {
/**
* This lock protects #state and #command.
*/
- GMutex *mutex;
+ mutable Mutex mutex;
/**
* Trigger this object after you have modified #command. This
* is also used by the decoder thread to notify the caller
* when it has finished a command.
*/
- GCond *cond;
+ Cond cond;
/**
* The trigger of this object's client. It is signalled
* whenever an event occurs.
*/
- GCond *client_cond;
+ Cond client_cond;
enum decoder_state state;
enum decoder_command command;
@@ -137,14 +139,14 @@ struct decoder_control {
* Locks the object.
*/
void Lock() const {
- g_mutex_lock(mutex);
+ mutex.lock();
}
/**
* Unlocks the object.
*/
void Unlock() const {
- g_mutex_unlock(mutex);
+ mutex.unlock();
}
/**
@@ -153,7 +155,7 @@ struct decoder_control {
* calling this function.
*/
void Signal() {
- g_cond_signal(cond);
+ cond.signal();
}
/**
@@ -162,7 +164,7 @@ struct decoder_control {
* prior to calling this function.
*/
void Wait() {
- g_cond_wait(cond, mutex);
+ cond.wait(mutex);
}
/**
@@ -171,7 +173,7 @@ struct decoder_control {
* is only valid in the player thread.
*/
void WaitForDecoder() {
- g_cond_wait(client_cond, mutex);
+ client_cond.wait(mutex);
}
bool IsIdle() const {
diff --git a/src/DecoderInternal.cxx b/src/DecoderInternal.cxx
index af36e176..80f0adfd 100644
--- a/src/DecoderInternal.cxx
+++ b/src/DecoderInternal.cxx
@@ -57,7 +57,7 @@ need_chunks(struct decoder_control *dc, bool do_wait)
if (do_wait) {
dc->Wait();
- g_cond_signal(dc->client_cond);
+ dc->client_cond.signal();
return dc->command;
}
diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx
index 4b9cdfd8..67054cbc 100644
--- a/src/DecoderThread.cxx
+++ b/src/DecoderThread.cxx
@@ -58,7 +58,7 @@ decoder_command_finished_locked(struct decoder_control *dc)
dc->command = DECODE_COMMAND_NONE;
- g_cond_signal(dc->client_cond);
+ dc->client_cond.signal();
}
/**
@@ -418,7 +418,7 @@ decoder_run_song(struct decoder_control *dc,
g_free(allocated);
}
- g_cond_signal(dc->client_cond);
+ dc->client_cond.signal();
}
static void
diff --git a/src/InputInternal.cxx b/src/InputInternal.cxx
index 8fc4fa0a..52ca4cf0 100644
--- a/src/InputInternal.cxx
+++ b/src/InputInternal.cxx
@@ -25,7 +25,7 @@
void
input_stream_init(struct input_stream *is, const struct input_plugin *plugin,
- const char *uri, GMutex *mutex, GCond *cond)
+ const char *uri, Mutex &mutex, Cond &cond)
{
assert(is != NULL);
assert(plugin != NULL);
@@ -33,8 +33,8 @@ input_stream_init(struct input_stream *is, const struct input_plugin *plugin,
is->plugin = plugin;
is->uri = g_strdup(uri);
- is->mutex = mutex;
- is->cond = cond;
+ is->mutex = &mutex;
+ is->cond = &cond;
is->ready = false;
is->seekable = false;
is->size = -1;
@@ -56,18 +56,16 @@ void
input_stream_signal_client(struct input_stream *is)
{
if (is->cond != NULL)
- g_cond_broadcast(is->cond);
+ is->cond->broadcast();
}
void
input_stream_set_ready(struct input_stream *is)
{
- g_mutex_lock(is->mutex);
+ const ScopeLock protect(*is->mutex);
if (!is->ready) {
is->ready = true;
input_stream_signal_client(is);
}
-
- g_mutex_unlock(is->mutex);
}
diff --git a/src/InputInternal.hxx b/src/InputInternal.hxx
index 33e010da..9994ea74 100644
--- a/src/InputInternal.hxx
+++ b/src/InputInternal.hxx
@@ -21,15 +21,15 @@
#define MPD_INPUT_INTERNAL_HXX
#include "check.h"
-
-#include <glib.h>
+#include "thread/Mutex.hxx"
+#include "thread/Cond.hxx"
struct input_stream;
struct input_plugin;
void
input_stream_init(struct input_stream *is, const struct input_plugin *plugin,
- const char *uri, GMutex *mutex, GCond *cond);
+ const char *uri, Mutex &mutex, Cond &cond);
void
input_stream_deinit(struct input_stream *is);
diff --git a/src/InputPlugin.hxx b/src/InputPlugin.hxx
index abbd74ff..c1660081 100644
--- a/src/InputPlugin.hxx
+++ b/src/InputPlugin.hxx
@@ -48,7 +48,7 @@ struct input_plugin {
void (*finish)(void);
struct input_stream *(*open)(const char *uri,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r);
void (*close)(struct input_stream *is);
diff --git a/src/InputStream.cxx b/src/InputStream.cxx
index e55450d9..c9d7f212 100644
--- a/src/InputStream.cxx
+++ b/src/InputStream.cxx
@@ -38,12 +38,11 @@ input_quark(void)
struct input_stream *
input_stream_open(const char *url,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r)
{
GError *error = NULL;
- assert(mutex != NULL);
assert(error_r == NULL || *error_r == NULL);
input_plugins_for_each_enabled(plugin) {
@@ -102,7 +101,7 @@ input_stream_wait_ready(struct input_stream *is)
if (is->ready)
break;
- g_cond_wait(is->cond, is->mutex);
+ is->cond->wait(*is->mutex);
}
}
@@ -113,9 +112,8 @@ input_stream_lock_wait_ready(struct input_stream *is)
assert(is->mutex != NULL);
assert(is->cond != NULL);
- g_mutex_lock(is->mutex);
+ const ScopeLock protect(*is->mutex);
input_stream_wait_ready(is);
- g_mutex_unlock(is->mutex);
}
const char *
@@ -197,10 +195,8 @@ input_stream_lock_seek(struct input_stream *is, goffset offset, int whence,
/* no locking */
return input_stream_seek(is, offset, whence, error_r);
- g_mutex_lock(is->mutex);
- bool success = input_stream_seek(is, offset, whence, error_r);
- g_mutex_unlock(is->mutex);
- return success;
+ const ScopeLock protect(*is->mutex);
+ return input_stream_seek(is, offset, whence, error_r);
}
struct tag *
@@ -227,10 +223,8 @@ input_stream_lock_tag(struct input_stream *is)
/* no locking */
return input_stream_tag(is);
- g_mutex_lock(is->mutex);
- struct tag *tag = input_stream_tag(is);
- g_mutex_unlock(is->mutex);
- return tag;
+ const ScopeLock protect(*is->mutex);
+ return input_stream_tag(is);
}
bool
@@ -265,10 +259,8 @@ input_stream_lock_read(struct input_stream *is, void *ptr, size_t size,
/* no locking */
return input_stream_read(is, ptr, size, error_r);
- g_mutex_lock(is->mutex);
- size_t nbytes = input_stream_read(is, ptr, size, error_r);
- g_mutex_unlock(is->mutex);
- return nbytes;
+ const ScopeLock protect(*is->mutex);
+ return input_stream_read(is, ptr, size, error_r);
}
void input_stream_close(struct input_stream *is)
@@ -291,9 +283,7 @@ input_stream_lock_eof(struct input_stream *is)
/* no locking */
return input_stream_eof(is);
- g_mutex_lock(is->mutex);
- bool eof = input_stream_eof(is);
- g_mutex_unlock(is->mutex);
- return eof;
+ const ScopeLock protect(*is->mutex);
+ return input_stream_eof(is);
}
diff --git a/src/InputStream.hxx b/src/InputStream.hxx
index 8a82888f..2c868725 100644
--- a/src/InputStream.hxx
+++ b/src/InputStream.hxx
@@ -22,6 +22,8 @@
#include "input_stream.h"
#include "check.h"
+#include "thread/Mutex.hxx"
+#include "thread/Cond.hxx"
#include "gcc.h"
#include <glib.h>
@@ -46,7 +48,7 @@ struct input_stream {
* This object is allocated by the client, and the client is
* responsible for freeing it.
*/
- GMutex *mutex;
+ Mutex *mutex;
/**
* A cond that gets signalled when the state of this object
@@ -56,7 +58,7 @@ struct input_stream {
* This object is allocated by the client, and the client is
* responsible for freeing it.
*/
- GCond *cond;
+ Cond *cond;
/**
* indicates whether the stream is ready for reading and
@@ -89,14 +91,14 @@ gcc_nonnull(1)
static inline void
input_stream_lock(struct input_stream *is)
{
- g_mutex_lock(is->mutex);
+ is->mutex->lock();
}
gcc_nonnull(1)
static inline void
input_stream_unlock(struct input_stream *is)
{
- g_mutex_unlock(is->mutex);
+ is->mutex->unlock();
}
#endif
diff --git a/src/PlaylistAny.cxx b/src/PlaylistAny.cxx
index 5c307368..3f6733f0 100644
--- a/src/PlaylistAny.cxx
+++ b/src/PlaylistAny.cxx
@@ -30,7 +30,7 @@ extern "C" {
#include <assert.h>
static struct playlist_provider *
-playlist_open_remote(const char *uri, GMutex *mutex, GCond *cond,
+playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond,
struct input_stream **is_r)
{
assert(uri_has_scheme(uri));
@@ -65,7 +65,7 @@ playlist_open_remote(const char *uri, GMutex *mutex, GCond *cond,
}
struct playlist_provider *
-playlist_open_any(const char *uri, GMutex *mutex, GCond *cond,
+playlist_open_any(const char *uri, Mutex &mutex, Cond &cond,
struct input_stream **is_r)
{
return uri_has_scheme(uri)
diff --git a/src/PlaylistAny.hxx b/src/PlaylistAny.hxx
index fbc32542..d69087b3 100644
--- a/src/PlaylistAny.hxx
+++ b/src/PlaylistAny.hxx
@@ -20,7 +20,8 @@
#ifndef MPD_PLAYLIST_ANY_HXX
#define MPD_PLAYLIST_ANY_HXX
-#include <glib.h>
+#include "thread/Mutex.hxx"
+#include "thread/Cond.hxx"
struct playlist_provider;
struct input_stream;
@@ -35,7 +36,7 @@ struct input_stream;
* freed
*/
struct playlist_provider *
-playlist_open_any(const char *uri, GMutex *mutex, GCond *cond,
+playlist_open_any(const char *uri, Mutex &mutex, Cond &cond,
struct input_stream **is_r);
#endif
diff --git a/src/PlaylistMapper.cxx b/src/PlaylistMapper.cxx
index aa37453f..85f47e44 100644
--- a/src/PlaylistMapper.cxx
+++ b/src/PlaylistMapper.cxx
@@ -31,7 +31,7 @@ extern "C" {
#include <assert.h>
static struct playlist_provider *
-playlist_open_path(const char *path_fs, GMutex *mutex, GCond *cond,
+playlist_open_path(const char *path_fs, Mutex &mutex, Cond &cond,
struct input_stream **is_r)
{
struct playlist_provider *playlist;
@@ -49,7 +49,7 @@ playlist_open_path(const char *path_fs, GMutex *mutex, GCond *cond,
* Load a playlist from the configured playlist directory.
*/
static struct playlist_provider *
-playlist_open_in_playlist_dir(const char *uri, GMutex *mutex, GCond *cond,
+playlist_open_in_playlist_dir(const char *uri, Mutex &mutex, Cond &cond,
struct input_stream **is_r)
{
char *path_fs;
@@ -73,7 +73,7 @@ playlist_open_in_playlist_dir(const char *uri, GMutex *mutex, GCond *cond,
* Load a playlist from the configured music directory.
*/
static struct playlist_provider *
-playlist_open_in_music_dir(const char *uri, GMutex *mutex, GCond *cond,
+playlist_open_in_music_dir(const char *uri, Mutex &mutex, Cond &cond,
struct input_stream **is_r)
{
assert(uri_safe_local(uri));
@@ -86,7 +86,7 @@ playlist_open_in_music_dir(const char *uri, GMutex *mutex, GCond *cond,
}
struct playlist_provider *
-playlist_mapper_open(const char *uri, GMutex *mutex, GCond *cond,
+playlist_mapper_open(const char *uri, Mutex &mutex, Cond &cond,
struct input_stream **is_r)
{
struct playlist_provider *playlist;
diff --git a/src/PlaylistMapper.hxx b/src/PlaylistMapper.hxx
index dc4e5cce..abfdb548 100644
--- a/src/PlaylistMapper.hxx
+++ b/src/PlaylistMapper.hxx
@@ -20,7 +20,8 @@
#ifndef MPD_PLAYLIST_MAPPER_HXX
#define MPD_PLAYLIST_MAPPER_HXX
-#include <glib.h>
+#include "thread/Mutex.hxx"
+#include "thread/Cond.hxx"
struct input_stream;
@@ -33,7 +34,7 @@ struct input_stream;
* freed
*/
struct playlist_provider *
-playlist_mapper_open(const char *uri, GMutex *mutex, GCond *cond,
+playlist_mapper_open(const char *uri, Mutex &mutex, Cond &cond,
struct input_stream **is_r);
#endif
diff --git a/src/PlaylistPlugin.hxx b/src/PlaylistPlugin.hxx
index 38e6f857..d422106b 100644
--- a/src/PlaylistPlugin.hxx
+++ b/src/PlaylistPlugin.hxx
@@ -20,7 +20,8 @@
#ifndef MPD_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_PLUGIN_HXX
-#include <glib.h>
+#include "thread/Mutex.hxx"
+#include "thread/Cond.hxx"
#include <stddef.h>
@@ -66,7 +67,7 @@ struct playlist_plugin {
* either matched one of the schemes or one of the suffixes.
*/
struct playlist_provider *(*open_uri)(const char *uri,
- GMutex *mutex, GCond *cond);
+ Mutex &mutex, Cond &cond);
/**
* Opens the playlist in the specified input stream. It has
@@ -113,7 +114,7 @@ playlist_plugin_finish(const struct playlist_plugin *plugin)
static inline struct playlist_provider *
playlist_plugin_open_uri(const struct playlist_plugin *plugin, const char *uri,
- GMutex *mutex, GCond *cond)
+ Mutex &mutex, Cond &cond)
{
return plugin->open_uri(uri, mutex, cond);
}
diff --git a/src/PlaylistPrint.cxx b/src/PlaylistPrint.cxx
index ffecc813..e79e8773 100644
--- a/src/PlaylistPrint.cxx
+++ b/src/PlaylistPrint.cxx
@@ -174,17 +174,14 @@ playlist_provider_print(Client *client, const char *uri,
bool
playlist_file_print(Client *client, const char *uri, bool detail)
{
- GMutex *mutex = g_mutex_new();
- GCond *cond = g_cond_new();
+ Mutex mutex;
+ Cond cond;
struct input_stream *is;
struct playlist_provider *playlist =
playlist_open_any(uri, mutex, cond, &is);
- if (playlist == NULL) {
- g_cond_free(cond);
- g_mutex_free(mutex);
+ if (playlist == NULL)
return false;
- }
playlist_provider_print(client, uri, playlist, detail);
playlist_plugin_close(playlist);
@@ -192,8 +189,5 @@ playlist_file_print(Client *client, const char *uri, bool detail)
if (is != NULL)
input_stream_close(is);
- g_cond_free(cond);
- g_mutex_free(mutex);
-
return true;
}
diff --git a/src/PlaylistQueue.cxx b/src/PlaylistQueue.cxx
index 39732676..c52f49a9 100644
--- a/src/PlaylistQueue.cxx
+++ b/src/PlaylistQueue.cxx
@@ -71,17 +71,14 @@ playlist_open_into_queue(const char *uri,
struct playlist *dest, struct player_control *pc,
bool secure)
{
- GMutex *mutex = g_mutex_new();
- GCond *cond = g_cond_new();
+ Mutex mutex;
+ Cond cond;
struct input_stream *is;
struct playlist_provider *playlist =
playlist_open_any(uri, mutex, cond, &is);
- if (playlist == NULL) {
- g_cond_free(cond);
- g_mutex_free(mutex);
+ if (playlist == NULL)
return PLAYLIST_RESULT_NO_SUCH_LIST;
- }
enum playlist_result result =
playlist_load_into_queue(uri, playlist, start_index, end_index,
@@ -91,8 +88,5 @@ playlist_open_into_queue(const char *uri,
if (is != NULL)
input_stream_close(is);
- g_cond_free(cond);
- g_mutex_free(mutex);
-
return result;
}
diff --git a/src/PlaylistRegistry.cxx b/src/PlaylistRegistry.cxx
index 551f7ef3..6dc94034 100644
--- a/src/PlaylistRegistry.cxx
+++ b/src/PlaylistRegistry.cxx
@@ -125,7 +125,7 @@ playlist_list_global_finish(void)
}
static struct playlist_provider *
-playlist_list_open_uri_scheme(const char *uri, GMutex *mutex, GCond *cond,
+playlist_list_open_uri_scheme(const char *uri, Mutex &mutex, Cond &cond,
bool *tried)
{
char *scheme;
@@ -159,7 +159,7 @@ playlist_list_open_uri_scheme(const char *uri, GMutex *mutex, GCond *cond,
}
static struct playlist_provider *
-playlist_list_open_uri_suffix(const char *uri, GMutex *mutex, GCond *cond,
+playlist_list_open_uri_suffix(const char *uri, Mutex &mutex, Cond &cond,
const bool *tried)
{
const char *suffix;
@@ -188,7 +188,7 @@ playlist_list_open_uri_suffix(const char *uri, GMutex *mutex, GCond *cond,
}
struct playlist_provider *
-playlist_list_open_uri(const char *uri, GMutex *mutex, GCond *cond)
+playlist_list_open_uri(const char *uri, Mutex &mutex, Cond &cond)
{
struct playlist_provider *playlist;
/** this array tracks which plugins have already been tried by
@@ -317,7 +317,7 @@ playlist_suffix_supported(const char *suffix)
}
struct playlist_provider *
-playlist_list_open_path(const char *path_fs, GMutex *mutex, GCond *cond,
+playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond,
struct input_stream **is_r)
{
GError *error = NULL;
diff --git a/src/PlaylistRegistry.hxx b/src/PlaylistRegistry.hxx
index 5116b508..a9fc56dc 100644
--- a/src/PlaylistRegistry.hxx
+++ b/src/PlaylistRegistry.hxx
@@ -20,6 +20,9 @@
#ifndef MPD_PLAYLIST_REGISTRY_HXX
#define MPD_PLAYLIST_REGISTRY_HXX
+#include "thread/Mutex.hxx"
+#include "thread/Cond.hxx"
+
#include <glib.h>
#include <stdbool.h>
@@ -51,7 +54,7 @@ playlist_list_global_finish(void);
* Opens a playlist by its URI.
*/
struct playlist_provider *
-playlist_list_open_uri(const char *uri, GMutex *mutex, GCond *cond);
+playlist_list_open_uri(const char *uri, Mutex &mutex, Cond &cond);
/**
* Opens a playlist from an input stream.
@@ -79,7 +82,7 @@ playlist_suffix_supported(const char *suffix);
* @return a playlist, or NULL on error
*/
struct playlist_provider *
-playlist_list_open_path(const char *path_fs, GMutex *mutex, GCond *cond,
+playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond,
struct input_stream **is_r);
#endif
diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx
index 120aaf53..ce678fe0 100644
--- a/src/SongUpdate.cxx
+++ b/src/SongUpdate.cxx
@@ -117,13 +117,8 @@ song_file_update(struct song *song)
song->mtime = st.st_mtime;
- GMutex *mutex = NULL;
- GCond *cond;
-#if !GCC_CHECK_VERSION(4, 2)
- /* work around "may be used uninitialized in this function"
- false positive */
- cond = NULL;
-#endif
+ Mutex mutex;
+ Cond cond;
do {
/* load file tag */
@@ -140,8 +135,6 @@ song_file_update(struct song *song)
/* open the input_stream (if not already
open) */
if (is == NULL) {
- mutex = g_mutex_new();
- cond = g_cond_new();
is = input_stream_open(path_fs.c_str(),
mutex, cond,
NULL);
@@ -168,11 +161,6 @@ song_file_update(struct song *song)
if (is != NULL)
input_stream_close(is);
- if (mutex != NULL) {
- g_cond_free(cond);
- g_mutex_free(mutex);
- }
-
if (song->tag != NULL && tag_is_empty(song->tag))
tag_scan_fallback(path_fs.c_str(), &full_tag_handler,
song->tag);
diff --git a/src/TagFile.cxx b/src/TagFile.cxx
index edb1f267..f2a88abd 100644
--- a/src/TagFile.cxx
+++ b/src/TagFile.cxx
@@ -50,8 +50,8 @@ tag_file_scan(const char *path_fs,
return false;
struct input_stream *is = NULL;
- GMutex *mutex = NULL;
- GCond *cond = NULL;
+ Mutex mutex;
+ Cond cond;
do {
/* load file tag */
@@ -63,12 +63,9 @@ tag_file_scan(const char *path_fs,
if (plugin->scan_stream != NULL) {
/* open the input_stream (if not already
open) */
- if (is == NULL) {
- mutex = g_mutex_new();
- cond = g_cond_new();
+ if (is == nullptr)
is = input_stream_open(path_fs, mutex, cond,
NULL);
- }
/* now try the stream_tag() method */
if (is != NULL) {
@@ -84,11 +81,8 @@ tag_file_scan(const char *path_fs,
plugin = decoder_plugin_from_suffix(suffix, plugin);
} while (plugin != NULL);
- if (is != NULL) {
+ if (is != NULL)
input_stream_close(is);
- g_cond_free(cond);
- g_mutex_free(mutex);
- }
return plugin != NULL;
}
diff --git a/src/archive/Bzip2ArchivePlugin.cxx b/src/archive/Bzip2ArchivePlugin.cxx
index c8d8f397..35373ed1 100644
--- a/src/archive/Bzip2ArchivePlugin.cxx
+++ b/src/archive/Bzip2ArchivePlugin.cxx
@@ -132,10 +132,9 @@ bz2_open(const char *pathname, GError **error_r)
int len;
//open archive
- static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
- context->istream = input_stream_open(pathname,
- g_static_mutex_get_mutex(&mutex),
- NULL,
+ static Mutex mutex;
+ static Cond cond;
+ context->istream = input_stream_open(pathname, mutex, cond,
error_r);
if (context->istream == NULL) {
delete context;
@@ -186,7 +185,7 @@ bz2_close(struct archive_file *file)
static struct input_stream *
bz2_open_stream(struct archive_file *file, const char *path,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r)
{
struct bz2_archive_file *context = (struct bz2_archive_file *) file;
diff --git a/src/archive/Iso9660ArchivePlugin.cxx b/src/archive/Iso9660ArchivePlugin.cxx
index d081fe33..3330e04c 100644
--- a/src/archive/Iso9660ArchivePlugin.cxx
+++ b/src/archive/Iso9660ArchivePlugin.cxx
@@ -176,7 +176,7 @@ struct iso9660_input_stream {
static struct input_stream *
iso9660_archive_open_stream(struct archive_file *file, const char *pathname,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r)
{
struct iso9660_archive_file *context =
diff --git a/src/archive/ZzipArchivePlugin.cxx b/src/archive/ZzipArchivePlugin.cxx
index 28c3f46a..9e5ba393 100644
--- a/src/archive/ZzipArchivePlugin.cxx
+++ b/src/archive/ZzipArchivePlugin.cxx
@@ -143,7 +143,7 @@ struct zzip_input_stream {
static struct input_stream *
zzip_archive_open_stream(struct archive_file *file,
const char *pathname,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r)
{
struct zzip_archive *context = (struct zzip_archive *) file;
diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx
index aeecf641..d2a1355a 100644
--- a/src/decoder/WavpackDecoderPlugin.cxx
+++ b/src/decoder/WavpackDecoderPlugin.cxx
@@ -464,7 +464,7 @@ wavpack_input_init(struct wavpack_input *isp, struct decoder *decoder,
static struct input_stream *
wavpack_open_wvc(struct decoder *decoder, const char *uri,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
struct wavpack_input *wpi)
{
struct input_stream *is_wvc;
@@ -517,7 +517,7 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is)
struct wavpack_input isp, isp_wvc;
bool can_seek = is->seekable;
- is_wvc = wavpack_open_wvc(decoder, is->uri, is->mutex, is->cond,
+ is_wvc = wavpack_open_wvc(decoder, is->uri, *is->mutex, *is->cond,
&isp_wvc);
if (is_wvc != NULL) {
open_flags |= OPEN_WVC;
diff --git a/src/input/ArchiveInputPlugin.cxx b/src/input/ArchiveInputPlugin.cxx
index dd4956f7..01a85452 100644
--- a/src/input/ArchiveInputPlugin.cxx
+++ b/src/input/ArchiveInputPlugin.cxx
@@ -36,7 +36,7 @@
*/
static struct input_stream *
input_archive_open(const char *pathname,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r)
{
const struct archive_plugin *arplug;
diff --git a/src/input/CdioParanoiaInputPlugin.cxx b/src/input/CdioParanoiaInputPlugin.cxx
index 19001fbe..129eb75b 100644
--- a/src/input/CdioParanoiaInputPlugin.cxx
+++ b/src/input/CdioParanoiaInputPlugin.cxx
@@ -54,7 +54,7 @@ struct CdioParanoiaInputStream {
char buffer[CDIO_CD_FRAMESIZE_RAW];
int buffer_lsn;
- CdioParanoiaInputStream(const char *uri, GMutex *mutex, GCond *cond,
+ CdioParanoiaInputStream(const char *uri, Mutex &mutex, Cond &cond,
int _trackno)
:drv(nullptr), cdio(nullptr), para(nullptr),
trackno(_trackno)
@@ -157,7 +157,7 @@ cdio_detect_device(void)
static struct input_stream *
input_cdio_open(const char *uri,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r)
{
struct cdio_uri parsed_uri;
diff --git a/src/input/CurlInputPlugin.cxx b/src/input/CurlInputPlugin.cxx
index a2ad20b1..8ed25f9a 100644
--- a/src/input/CurlInputPlugin.cxx
+++ b/src/input/CurlInputPlugin.cxx
@@ -165,7 +165,7 @@ struct input_curl {
GError *postponed_error;
- input_curl(const char *url, GMutex *mutex, GCond *cond)
+ input_curl(const char *url, Mutex &mutex, Cond &cond)
:range(nullptr), request_headers(nullptr),
paused(false),
meta_name(nullptr),
@@ -462,11 +462,12 @@ input_curl_abort_all_requests(GError *error)
input_curl_easy_free(c);
- g_mutex_lock(c->base.mutex);
+ const ScopeLock protect(*c->base.mutex);
+
c->postponed_error = g_error_copy(error);
c->base.ready = true;
- g_cond_broadcast(c->base.cond);
- g_mutex_unlock(c->base.mutex);
+
+ c->base.cond->broadcast();
}
g_error_free(error);
@@ -486,7 +487,7 @@ input_curl_request_done(struct input_curl *c, CURLcode result, long status)
assert(c->easy == NULL);
assert(c->postponed_error == NULL);
- g_mutex_lock(c->base.mutex);
+ const ScopeLock protect(*c->base.mutex);
if (result != CURLE_OK) {
c->postponed_error = g_error_new(curl_quark(), result,
@@ -499,8 +500,8 @@ input_curl_request_done(struct input_curl *c, CURLcode result, long status)
}
c->base.ready = true;
- g_cond_broadcast(c->base.cond);
- g_mutex_unlock(c->base.mutex);
+
+ c->base.cond->broadcast();
}
static void
@@ -736,7 +737,7 @@ static bool
fill_buffer(struct input_curl *c, GError **error_r)
{
while (c->easy != NULL && c->buffers.empty())
- g_cond_wait(c->base.cond, c->base.mutex);
+ c->base.cond->wait(*c->base.mutex);
if (c->postponed_error != NULL) {
g_propagate_error(error_r, c->postponed_error);
@@ -856,9 +857,9 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size,
is->offset += (goffset)nbytes;
if (c->paused && curl_total_buffer_size(c) < CURL_RESUME_AT) {
- g_mutex_unlock(c->base.mutex);
+ c->base.mutex->unlock();
io_thread_call(input_curl_resume, c);
- g_mutex_lock(c->base.mutex);
+ c->base.mutex->lock();
}
return nbytes;
@@ -975,20 +976,17 @@ input_curl_writefunction(void *ptr, size_t size, size_t nmemb, void *stream)
if (size == 0)
return 0;
- g_mutex_lock(c->base.mutex);
+ const ScopeLock protect(*c->base.mutex);
if (curl_total_buffer_size(c) + size >= CURL_MAX_BUFFERED) {
c->paused = true;
- g_mutex_unlock(c->base.mutex);
return CURL_WRITEFUNC_PAUSE;
}
c->buffers.emplace_back(ptr, size);
c->base.ready = true;
- g_cond_broadcast(c->base.cond);
- g_mutex_unlock(c->base.mutex);
-
+ c->base.cond->broadcast();
return size;
}
@@ -1112,7 +1110,7 @@ input_curl_seek(struct input_stream *is, goffset offset, int whence,
/* close the old connection and open a new one */
- g_mutex_unlock(c->base.mutex);
+ c->base.mutex->unlock();
input_curl_easy_free_indirect(c);
c->buffers.clear();
@@ -1141,10 +1139,10 @@ input_curl_seek(struct input_stream *is, goffset offset, int whence,
if (!input_curl_easy_add_indirect(c, error_r))
return false;
- g_mutex_lock(c->base.mutex);
+ c->base.mutex->lock();
while (!c->base.ready)
- g_cond_wait(c->base.cond, c->base.mutex);
+ c->base.cond->wait(*c->base.mutex);
if (c->postponed_error != NULL) {
g_propagate_error(error_r, c->postponed_error);
@@ -1156,12 +1154,9 @@ input_curl_seek(struct input_stream *is, goffset offset, int whence,
}
static struct input_stream *
-input_curl_open(const char *url, GMutex *mutex, GCond *cond,
+input_curl_open(const char *url, Mutex &mutex, Cond &cond,
GError **error_r)
{
- assert(mutex != NULL);
- assert(cond != NULL);
-
if (strncmp(url, "http://", 7) != 0)
return NULL;
diff --git a/src/input/DespotifyInputPlugin.cxx b/src/input/DespotifyInputPlugin.cxx
index e17bbb66..46960b1f 100644
--- a/src/input/DespotifyInputPlugin.cxx
+++ b/src/input/DespotifyInputPlugin.cxx
@@ -102,7 +102,7 @@ static void callback(G_GNUC_UNUSED struct despotify_session* ds,
static struct input_stream *
input_despotify_open(const char *url,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
G_GNUC_UNUSED GError **error_r)
{
struct input_despotify *ctx;
diff --git a/src/input/FfmpegInputPlugin.cxx b/src/input/FfmpegInputPlugin.cxx
index 1893a01e..d9e22386 100644
--- a/src/input/FfmpegInputPlugin.cxx
+++ b/src/input/FfmpegInputPlugin.cxx
@@ -82,7 +82,7 @@ input_ffmpeg_init(G_GNUC_UNUSED const struct config_param *param,
static struct input_stream *
input_ffmpeg_open(const char *uri,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r)
{
struct input_ffmpeg *i;
diff --git a/src/input/FileInputPlugin.cxx b/src/input/FileInputPlugin.cxx
index 2d0bfcbb..7681ee0c 100644
--- a/src/input/FileInputPlugin.cxx
+++ b/src/input/FileInputPlugin.cxx
@@ -41,7 +41,7 @@ struct FileInputStream {
int fd;
FileInputStream(const char *path, int _fd, off_t size,
- GMutex *mutex, GCond *cond)
+ Mutex &mutex, Cond &cond)
:fd(_fd) {
input_stream_init(&base, &input_plugin_file, path,
mutex, cond);
@@ -59,7 +59,7 @@ struct FileInputStream {
static struct input_stream *
input_file_open(const char *filename,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r)
{
int fd, ret;
diff --git a/src/input/MmsInputPlugin.cxx b/src/input/MmsInputPlugin.cxx
index 93452170..be583e28 100644
--- a/src/input/MmsInputPlugin.cxx
+++ b/src/input/MmsInputPlugin.cxx
@@ -40,7 +40,7 @@ struct MmsInputStream {
bool eof;
MmsInputStream(const char *uri,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
mmsx_t *_mms)
:mms(_mms), eof(false) {
input_stream_init(&base, &input_plugin_mms, uri, mutex, cond);
@@ -66,7 +66,7 @@ mms_quark(void)
static struct input_stream *
input_mms_open(const char *url,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r)
{
if (!g_str_has_prefix(url, "mms://") &&
diff --git a/src/input/RewindInputPlugin.cxx b/src/input/RewindInputPlugin.cxx
index d77bb120..bc428e7a 100644
--- a/src/input/RewindInputPlugin.cxx
+++ b/src/input/RewindInputPlugin.cxx
@@ -63,7 +63,7 @@ struct RewindInputStream {
RewindInputStream(input_stream *_input)
:input(_input), tail(0) {
input_stream_init(&base, &rewind_input_plugin, input->uri,
- input->mutex, input->cond);
+ *input->mutex, *input->cond);
}
~RewindInputStream() {
diff --git a/src/input/SoupInputPlugin.cxx b/src/input/SoupInputPlugin.cxx
index be489262..ebc2601d 100644
--- a/src/input/SoupInputPlugin.cxx
+++ b/src/input/SoupInputPlugin.cxx
@@ -165,7 +165,7 @@ input_soup_session_callback(G_GNUC_UNUSED SoupSession *session,
assert(msg == s->msg);
assert(!s->completed);
- g_mutex_lock(s->base.mutex);
+ const ScopeLock protect(*s->base.mutex);
if (!s->base.ready)
input_soup_copy_error(s, msg);
@@ -174,8 +174,7 @@ input_soup_session_callback(G_GNUC_UNUSED SoupSession *session,
s->alive = false;
s->completed = true;
- g_cond_broadcast(s->base.cond);
- g_mutex_unlock(s->base.mutex);
+ s->base.cond->broadcast();
}
static void
@@ -183,10 +182,10 @@ input_soup_got_headers(SoupMessage *msg, gpointer user_data)
{
struct input_soup *s = (struct input_soup *)user_data;
- g_mutex_lock(s->base.mutex);
+ s->base.mutex->lock();
if (!input_soup_copy_error(s, msg)) {
- g_mutex_unlock(s->base.mutex);
+ s->base.mutex->unlock();
soup_session_cancel_message(soup_session, msg,
SOUP_STATUS_CANCELLED);
@@ -194,8 +193,8 @@ input_soup_got_headers(SoupMessage *msg, gpointer user_data)
}
s->base.ready = true;
- g_cond_broadcast(s->base.cond);
- g_mutex_unlock(s->base.mutex);
+ s->base.cond->broadcast();
+ s->base.mutex->unlock();
soup_message_body_set_accumulate(msg->response_body, false);
}
@@ -207,7 +206,7 @@ input_soup_got_chunk(SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
assert(msg == s->msg);
- g_mutex_lock(s->base.mutex);
+ const ScopeLock protect(*s->base.mutex);
g_queue_push_tail(s->buffers, soup_buffer_copy(chunk));
s->total_buffered += chunk->length;
@@ -217,8 +216,8 @@ input_soup_got_chunk(SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
soup_session_pause_message(soup_session, msg);
}
- g_cond_broadcast(s->base.cond);
- g_mutex_unlock(s->base.mutex);
+ s->base.cond->broadcast();
+ s->base.mutex->unlock();
}
static void
@@ -228,14 +227,14 @@ input_soup_got_body(G_GNUC_UNUSED SoupMessage *msg, gpointer user_data)
assert(msg == s->msg);
- g_mutex_lock(s->base.mutex);
+ const ScopeLock protect(*s->base.mutex);
s->base.ready = true;
s->eof = true;
s->alive = false;
- g_cond_broadcast(s->base.cond);
- g_mutex_unlock(s->base.mutex);
+ s->base.cond->broadcast();
+ s->base.mutex->unlock();
}
static bool
@@ -253,7 +252,7 @@ input_soup_wait_data(struct input_soup *s)
assert(s->current_consumed == 0);
- g_cond_wait(s->base.cond, s->base.mutex);
+ s->base.cond->wait(*s->base.mutex);
}
}
@@ -270,7 +269,7 @@ input_soup_queue(gpointer data)
static struct input_stream *
input_soup_open(const char *uri,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
G_GNUC_UNUSED GError **error_r)
{
if (strncmp(uri, "http://", 7) != 0)
@@ -338,22 +337,22 @@ input_soup_close(struct input_stream *is)
{
struct input_soup *s = (struct input_soup *)is;
- g_mutex_lock(s->base.mutex);
+ s->base.mutex->lock();
if (!s->completed) {
/* the messages's session callback hasn't been invoked
yet; cancel it and wait for completion */
- g_mutex_unlock(s->base.mutex);
+ s->base.mutex->unlock();
io_thread_call(input_soup_cancel, s);
- g_mutex_lock(s->base.mutex);
+ s->base.mutex->lock();
while (!s->completed)
- g_cond_wait(s->base.cond, s->base.mutex);
+ s->base.cond->wait(*s->base.mutex);
}
- g_mutex_unlock(s->base.mutex);
+ s->base.mutex->unlock();
SoupBuffer *buffer;
while ((buffer = (SoupBuffer *)g_queue_pop_head(s->buffers)) != NULL)
diff --git a/src/input_stream.h b/src/input_stream.h
index 0d32c074..24dda1ee 100644
--- a/src/input_stream.h
+++ b/src/input_stream.h
@@ -33,7 +33,9 @@ struct input_stream;
#ifdef __cplusplus
extern "C" {
-#endif
+
+#include "thread/Mutex.hxx"
+#include "thread/Cond.hxx"
/**
* Opens a new input stream. You may not access it until the "ready"
@@ -46,13 +48,15 @@ extern "C" {
* notifications
* @return an #input_stream object on success, NULL on error
*/
-gcc_nonnull(1, 2)
+gcc_nonnull(1)
G_GNUC_MALLOC
struct input_stream *
input_stream_open(const char *uri,
- GMutex *mutex, GCond *cond,
+ Mutex &mutex, Cond &cond,
GError **error_r);
+#endif
+
/**
* Close the input stream and free resources.
*
diff --git a/src/playlist/DespotifyPlaylistPlugin.cxx b/src/playlist/DespotifyPlaylistPlugin.cxx
index 7f647d58..00b697e3 100644
--- a/src/playlist/DespotifyPlaylistPlugin.cxx
+++ b/src/playlist/DespotifyPlaylistPlugin.cxx
@@ -113,8 +113,8 @@ despotify_playlist_finish(void)
static struct playlist_provider *
-despotify_playlist_open_uri(const char *url, G_GNUC_UNUSED GMutex *mutex,
- G_GNUC_UNUSED GCond *cond)
+despotify_playlist_open_uri(const char *url,
+ gcc_unused Mutex &mutex, gcc_unused Cond &cond)
{
struct despotify_playlist *ctx;
struct despotify_session *session;
diff --git a/src/playlist/EmbeddedCuePlaylistPlugin.cxx b/src/playlist/EmbeddedCuePlaylistPlugin.cxx
index f420aebf..04cb12ec 100644
--- a/src/playlist/EmbeddedCuePlaylistPlugin.cxx
+++ b/src/playlist/EmbeddedCuePlaylistPlugin.cxx
@@ -85,8 +85,8 @@ static const struct tag_handler embcue_tag_handler = {
static struct playlist_provider *
embcue_playlist_open_uri(const char *uri,
- G_GNUC_UNUSED GMutex *mutex,
- G_GNUC_UNUSED GCond *cond)
+ gcc_unused Mutex &mutex,
+ gcc_unused Cond &cond)
{
if (!g_path_is_absolute(uri))
/* only local files supported */
diff --git a/src/playlist/LastFMPlaylistPlugin.cxx b/src/playlist/LastFMPlaylistPlugin.cxx
index 3898ce31..49638840 100644
--- a/src/playlist/LastFMPlaylistPlugin.cxx
+++ b/src/playlist/LastFMPlaylistPlugin.cxx
@@ -79,7 +79,7 @@ lastfm_finish(void)
* @return data fetched, or NULL on error. Must be freed with g_free.
*/
static char *
-lastfm_get(const char *url, GMutex *mutex, GCond *cond)
+lastfm_get(const char *url, Mutex &mutex, Cond &cond)
{
struct input_stream *input_stream;
GError *error = NULL;
@@ -96,7 +96,7 @@ lastfm_get(const char *url, GMutex *mutex, GCond *cond)
return NULL;
}
- g_mutex_lock(mutex);
+ mutex.lock();
input_stream_wait_ready(input_stream);
@@ -113,7 +113,7 @@ lastfm_get(const char *url, GMutex *mutex, GCond *cond)
break;
/* I/O error */
- g_mutex_unlock(mutex);
+ mutex.unlock();
input_stream_close(input_stream);
return NULL;
}
@@ -121,7 +121,7 @@ lastfm_get(const char *url, GMutex *mutex, GCond *cond)
length += nbytes;
} while (length < sizeof(buffer));
- g_mutex_unlock(mutex);
+ mutex.unlock();
input_stream_close(input_stream);
return g_strndup(buffer, length);
@@ -154,7 +154,7 @@ lastfm_find(const char *response, const char *name)
}
static struct playlist_provider *
-lastfm_open_uri(const char *uri, GMutex *mutex, GCond *cond)
+lastfm_open_uri(const char *uri, Mutex &mutex, Cond &cond)
{
struct lastfm_playlist *playlist;
GError *error = NULL;
@@ -235,7 +235,7 @@ lastfm_open_uri(const char *uri, GMutex *mutex, GCond *cond)
return NULL;
}
- g_mutex_lock(mutex);
+ mutex.lock();
input_stream_wait_ready(playlist->is);
@@ -243,7 +243,7 @@ lastfm_open_uri(const char *uri, GMutex *mutex, GCond *cond)
:-( */
input_stream_override_mime_type(playlist->is, "application/xspf+xml");
- g_mutex_unlock(mutex);
+ mutex.unlock();
/* parse the XSPF playlist */
diff --git a/src/playlist/SoundCloudPlaylistPlugin.cxx b/src/playlist/SoundCloudPlaylistPlugin.cxx
index fd2a99c6..eefa23dd 100644
--- a/src/playlist/SoundCloudPlaylistPlugin.cxx
+++ b/src/playlist/SoundCloudPlaylistPlugin.cxx
@@ -247,7 +247,8 @@ static yajl_callbacks parse_callbacks = {
* @return -1 on error, 0 on success.
*/
static int
-soundcloud_parse_json(const char *url, yajl_handle hand, GMutex* mutex, GCond* cond)
+soundcloud_parse_json(const char *url, yajl_handle hand,
+ Mutex &mutex, Cond &cond)
{
struct input_stream *input_stream;
GError *error = NULL;
@@ -264,7 +265,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand, GMutex* mutex, GCond* c
return -1;
}
- g_mutex_lock(mutex);
+ mutex.lock();
input_stream_wait_ready(input_stream);
yajl_status stat;
@@ -280,7 +281,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand, GMutex* mutex, GCond* c
if (input_stream_eof(input_stream)) {
done = true;
} else {
- g_mutex_unlock(mutex);
+ mutex.unlock();
input_stream_close(input_stream);
return -1;
}
@@ -308,7 +309,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand, GMutex* mutex, GCond* c
}
}
- g_mutex_unlock(mutex);
+ mutex.unlock();
input_stream_close(input_stream);
return 0;
@@ -323,7 +324,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand, GMutex* mutex, GCond* c
*/
static struct playlist_provider *
-soundcloud_open_uri(const char *uri, GMutex *mutex, GCond *cond)
+soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond)
{
struct soundcloud_playlist *playlist = NULL;
diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx
index b3cc8c26..175a407e 100644
--- a/test/dump_playlist.cxx
+++ b/test/dump_playlist.cxx
@@ -186,8 +186,8 @@ int main(int argc, char **argv)
/* open the playlist */
- GMutex *mutex = g_mutex_new();
- GCond *cond = g_cond_new();
+ Mutex mutex;
+ Cond cond;
playlist = playlist_list_open_uri(uri, mutex, cond);
if (playlist == NULL) {
@@ -243,9 +243,6 @@ int main(int argc, char **argv)
if (is != NULL)
input_stream_close(is);
- g_cond_free(cond);
- g_mutex_free(mutex);
-
decoder_plugin_deinit_all();
playlist_list_global_finish();
input_stream_global_finish();
diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx
index dc3f9d6a..93b0d018 100644
--- a/test/dump_text_file.cxx
+++ b/test/dump_text_file.cxx
@@ -135,8 +135,8 @@ int main(int argc, char **argv)
/* open the stream and dump it */
- GMutex *mutex = g_mutex_new();
- GCond *cond = g_cond_new();
+ Mutex mutex;
+ Cond cond;
is = input_stream_open(argv[1], mutex, cond, &error);
if (is != NULL) {
@@ -151,9 +151,6 @@ int main(int argc, char **argv)
ret = 2;
}
- g_cond_free(cond);
- g_mutex_free(mutex);
-
/* deinitialize everything */
input_stream_global_finish();
diff --git a/test/read_tags.cxx b/test/read_tags.cxx
index a634d72b..ddd278ff 100644
--- a/test/read_tags.cxx
+++ b/test/read_tags.cxx
@@ -186,8 +186,8 @@ int main(int argc, char **argv)
bool success = decoder_plugin_scan_file(plugin, path,
&print_handler, NULL);
if (!success && plugin->scan_stream != NULL) {
- GMutex *mutex = g_mutex_new();
- GCond *cond = g_cond_new();
+ Mutex mutex;
+ Cond cond;
struct input_stream *is =
input_stream_open(path, mutex, cond, &error);
@@ -199,15 +199,15 @@ int main(int argc, char **argv)
return 1;
}
- g_mutex_lock(mutex);
+ mutex.lock();
while (!is->ready) {
- g_cond_wait(cond, mutex);
+ cond.wait(mutex);
input_stream_update(is);
}
if (!input_stream_check(is, &error)) {
- g_mutex_unlock(mutex);
+ mutex.unlock();
g_printerr("Failed to read %s: %s\n",
path, error->message);
@@ -216,14 +216,11 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- g_mutex_unlock(mutex);
+ mutex.unlock();
success = decoder_plugin_scan_stream(plugin, is,
&print_handler, NULL);
input_stream_close(is);
-
- g_cond_free(cond);
- g_mutex_free(mutex);
}
decoder_plugin_deinit_all();
diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx
index b3e90844..288b83f9 100644
--- a/test/run_decoder.cxx
+++ b/test/run_decoder.cxx
@@ -188,8 +188,8 @@ int main(int argc, char **argv)
decoder_plugin_file_decode(decoder.plugin, &decoder,
decoder.uri);
} else if (decoder.plugin->stream_decode != NULL) {
- GMutex *mutex = g_mutex_new();
- GCond *cond = g_cond_new();
+ Mutex mutex;
+ Cond cond;
struct input_stream *is =
input_stream_open(decoder.uri, mutex, cond, &error);
@@ -206,9 +206,6 @@ int main(int argc, char **argv)
decoder_plugin_stream_decode(decoder.plugin, &decoder, is);
input_stream_close(is);
-
- g_cond_free(cond);
- g_mutex_free(mutex);
} else {
g_printerr("Decoder plugin is not usable\n");
return 1;
diff --git a/test/run_input.cxx b/test/run_input.cxx
index b215eefe..db3e4dc8 100644
--- a/test/run_input.cxx
+++ b/test/run_input.cxx
@@ -149,8 +149,8 @@ int main(int argc, char **argv)
/* open the stream and dump it */
- GMutex *mutex = g_mutex_new();
- GCond *cond = g_cond_new();
+ Mutex mutex;
+ Cond cond;
is = input_stream_open(argv[1], mutex, cond, &error);
if (is != NULL) {
@@ -165,9 +165,6 @@ int main(int argc, char **argv)
ret = 2;
}
- g_cond_free(cond);
- g_mutex_free(mutex);
-
/* deinitialize everything */
input_stream_global_finish();