[ostree] fetcher: Add a priority value to async requests
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] fetcher: Add a priority value to async requests
- Date: Mon, 12 Jan 2015 16:27:55 +0000 (UTC)
commit 5c26e392ec135b2d95caf011a3ab45b5d9c97cf1
Author: Matthew Barnes <mbarnes redhat com>
Date: Thu Jan 8 13:19:48 2015 -0500
fetcher: Add a priority value to async requests
src/libostree/ostree-fetcher.c | 24 +++++++++++++++++++++---
src/libostree/ostree-fetcher.h | 4 ++++
src/libostree/ostree-metalink.c | 1 +
src/libostree/ostree-repo-pull.c | 2 ++
4 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/src/libostree/ostree-fetcher.c b/src/libostree/ostree-fetcher.c
index 34a9dce..851237a 100644
--- a/src/libostree/ostree-fetcher.c
+++ b/src/libostree/ostree-fetcher.c
@@ -42,6 +42,7 @@ typedef struct {
guint refcount;
OstreeFetcher *self;
SoupURI *uri;
+ int priority;
OstreeFetcherState state;
@@ -60,6 +61,18 @@ typedef struct {
GSimpleAsyncResult *result;
} OstreeFetcherPendingURI;
+static int
+pending_uri_compare (gconstpointer a,
+ gconstpointer b,
+ gpointer unused)
+{
+ const OstreeFetcherPendingURI *pending_a = a;
+ const OstreeFetcherPendingURI *pending_b = b;
+
+ return (pending_a->priority == pending_b->priority) ? 0 :
+ (pending_a->priority < pending_b->priority) ? -1 : 1;
+}
+
static void
pending_uri_free (OstreeFetcherPendingURI *pending)
{
@@ -507,6 +520,7 @@ ostree_fetcher_request_uri_internal (OstreeFetcher *self,
SoupURI *uri,
gboolean is_stream,
guint64 max_size,
+ int priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
@@ -521,6 +535,7 @@ ostree_fetcher_request_uri_internal (OstreeFetcher *self,
pending->self = g_object_ref (self);
pending->uri = soup_uri_copy (uri);
+ pending->priority = priority;
pending->max_size = max_size;
pending->is_stream = is_stream;
pending->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
@@ -566,7 +581,7 @@ ostree_fetcher_request_uri_internal (OstreeFetcher *self,
}
pending->out_tmpfile = out_tmpfile;
- g_queue_push_tail (&self->pending_queue, pending);
+ g_queue_insert_sorted (&self->pending_queue, pending, pending_uri_compare, NULL);
ostree_fetcher_process_pending_queue (self);
}
@@ -587,11 +602,12 @@ void
_ostree_fetcher_request_uri_with_partial_async (OstreeFetcher *self,
SoupURI *uri,
guint64 max_size,
+ int priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- ostree_fetcher_request_uri_internal (self, uri, FALSE, max_size, cancellable,
+ ostree_fetcher_request_uri_internal (self, uri, FALSE, max_size, priority, cancellable,
callback, user_data,
_ostree_fetcher_request_uri_with_partial_async);
}
@@ -618,11 +634,12 @@ static void
ostree_fetcher_stream_uri_async (OstreeFetcher *self,
SoupURI *uri,
guint64 max_size,
+ int priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- ostree_fetcher_request_uri_internal (self, uri, TRUE, max_size, cancellable,
+ ostree_fetcher_request_uri_internal (self, uri, TRUE, max_size, priority, cancellable,
callback, user_data,
ostree_fetcher_stream_uri_async);
}
@@ -716,6 +733,7 @@ _ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher,
ostree_fetcher_stream_uri_async (fetcher, uri,
max_size,
+ OSTREE_FETCHER_DEFAULT_PRIORITY,
cancellable,
fetch_uri_sync_on_complete, &data);
diff --git a/src/libostree/ostree-fetcher.h b/src/libostree/ostree-fetcher.h
index 1a6c95b..c81e51a 100644
--- a/src/libostree/ostree-fetcher.h
+++ b/src/libostree/ostree-fetcher.h
@@ -36,6 +36,9 @@ G_BEGIN_DECLS
#define OSTREE_IS_FETCHER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_FETCHER))
#define OSTREE_FETCHER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_FETCHER,
OstreeFetcherClass))
+/* Lower values have higher priority */
+#define OSTREE_FETCHER_DEFAULT_PRIORITY 0
+
typedef struct OstreeFetcherClass OstreeFetcherClass;
typedef struct OstreeFetcher OstreeFetcher;
@@ -68,6 +71,7 @@ guint64 _ostree_fetcher_bytes_transferred (OstreeFetcher *self);
void _ostree_fetcher_request_uri_with_partial_async (OstreeFetcher *self,
SoupURI *uri,
guint64 max_size,
+ int priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
diff --git a/src/libostree/ostree-metalink.c b/src/libostree/ostree-metalink.c
index 5244e91..82091ee 100644
--- a/src/libostree/ostree-metalink.c
+++ b/src/libostree/ostree-metalink.c
@@ -518,6 +518,7 @@ try_next_url (OstreeMetalinkRequest *self)
_ostree_fetcher_request_uri_with_partial_async (self->metalink->fetcher, next,
self->metalink->max_size,
+ OSTREE_FETCHER_DEFAULT_PRIORITY,
g_task_get_cancellable (self->task),
on_fetched_url, self->task);
}
diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c
index a6160d3..296d23e 100644
--- a/src/libostree/ostree-repo-pull.c
+++ b/src/libostree/ostree-repo-pull.c
@@ -1123,6 +1123,7 @@ enqueue_one_object_request (OtPullData *pull_data,
_ostree_fetcher_request_uri_with_partial_async (pull_data->fetcher, obj_uri,
expected_max_size,
+ OSTREE_FETCHER_DEFAULT_PRIORITY,
pull_data->cancellable,
is_meta ? meta_fetch_on_complete :
content_fetch_on_complete, fetch_data);
soup_uri_free (obj_uri);
@@ -1451,6 +1452,7 @@ process_one_static_delta (OtPullData *pull_data,
target_uri = suburi_new (pull_data->base_uri, deltapart_path, NULL);
_ostree_fetcher_request_uri_with_partial_async (pull_data->fetcher, target_uri, size,
+ OSTREE_FETCHER_DEFAULT_PRIORITY,
pull_data->cancellable,
static_deltapart_fetch_on_complete,
fetch_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]