DecoderControl, InputStream: use Mutex/Cond instead of GMutex/GCond
This commit is contained in:
parent
257a0dee75
commit
6f3d70b5e2
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 =
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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://") &&
|
||||
|
@ -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() {
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user