aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-14 20:22:32 +0200
committerMax Kellermann <max@duempel.org>2012-08-14 20:22:32 +0200
commit31b380b2664e74d47f6862ecf44d62b0a82eddf2 (patch)
tree659d4095ef459f8c72ae5e928103b7b861e46561
parenta869dfea852e0961992b1563b2e14257e7ba3e03 (diff)
downloadmpd-31b380b2664e74d47f6862ecf44d62b0a82eddf2.tar.gz
mpd-31b380b2664e74d47f6862ecf44d62b0a82eddf2.tar.xz
mpd-31b380b2664e74d47f6862ecf44d62b0a82eddf2.zip
output/httpd: move code to _has_clients()
Diffstat (limited to '')
-rw-r--r--src/output/httpd_output_plugin.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/output/httpd_output_plugin.c b/src/output/httpd_output_plugin.c
index e7344320c..f7c6127c8 100644
--- a/src/output/httpd_output_plugin.c
+++ b/src/output/httpd_output_plugin.c
@@ -53,6 +53,31 @@ httpd_output_quark(void)
return g_quark_from_static_string("httpd_output");
}
+/**
+ * Check whether there is at least one client.
+ *
+ * Caller must lock the mutex.
+ */
+G_GNUC_PURE
+static bool
+httpd_output_has_clients(const struct httpd_output *httpd)
+{
+ return httpd->clients != NULL;
+}
+
+/**
+ * Check whether there is at least one client.
+ */
+G_GNUC_PURE
+static bool
+httpd_output_lock_has_clients(const struct httpd_output *httpd)
+{
+ g_mutex_lock(httpd->mutex);
+ bool result = httpd_output_has_clients(httpd);
+ g_mutex_unlock(httpd->mutex);
+ return result;
+}
+
static void
httpd_listen_in_event(int fd, const struct sockaddr *address,
size_t address_length, int uid, void *ctx);
@@ -475,13 +500,8 @@ httpd_output_play(struct audio_output *ao, const void *chunk, size_t size,
GError **error)
{
struct httpd_output *httpd = (struct httpd_output *)ao;
- bool has_clients;
-
- g_mutex_lock(httpd->mutex);
- has_clients = httpd->clients != NULL;
- g_mutex_unlock(httpd->mutex);
- if (has_clients) {
+ if (httpd_output_lock_has_clients(httpd)) {
bool success;
success = httpd_output_encode_and_play(httpd, chunk, size,
@@ -502,11 +522,7 @@ httpd_output_pause(struct audio_output *ao)
{
struct httpd_output *httpd = (struct httpd_output *)ao;
- g_mutex_lock(httpd->mutex);
- bool has_clients = httpd->clients != NULL;
- g_mutex_unlock(httpd->mutex);
-
- if (has_clients) {
+ if (httpd_output_lock_has_clients(httpd)) {
static const char silence[1020];
return httpd_output_play(ao, silence, sizeof(silence),
NULL) > 0;