aboutsummaryrefslogtreecommitdiff
path: root/src/input/CurlInputPlugin.cxx
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 /src/input/CurlInputPlugin.cxx
parent257a0dee758049586efbf0dc3f0339b0cef03456 (diff)
DecoderControl, InputStream: use Mutex/Cond instead of GMutex/GCond
Diffstat (limited to 'src/input/CurlInputPlugin.cxx')
-rw-r--r--src/input/CurlInputPlugin.cxx39
1 files changed, 17 insertions, 22 deletions
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;