fetcher: Add a priority value to async requests

This commit is contained in:
Matthew Barnes 2015-01-08 13:19:48 -05:00
parent a9532bc34f
commit 5c26e392ec
4 changed files with 28 additions and 3 deletions

View File

@ -42,6 +42,7 @@ typedef struct {
guint refcount; guint refcount;
OstreeFetcher *self; OstreeFetcher *self;
SoupURI *uri; SoupURI *uri;
int priority;
OstreeFetcherState state; OstreeFetcherState state;
@ -60,6 +61,18 @@ typedef struct {
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
} OstreeFetcherPendingURI; } 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 static void
pending_uri_free (OstreeFetcherPendingURI *pending) pending_uri_free (OstreeFetcherPendingURI *pending)
{ {
@ -507,6 +520,7 @@ ostree_fetcher_request_uri_internal (OstreeFetcher *self,
SoupURI *uri, SoupURI *uri,
gboolean is_stream, gboolean is_stream,
guint64 max_size, guint64 max_size,
int priority,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data, gpointer user_data,
@ -521,6 +535,7 @@ ostree_fetcher_request_uri_internal (OstreeFetcher *self,
pending->self = g_object_ref (self); pending->self = g_object_ref (self);
pending->uri = soup_uri_copy (uri); pending->uri = soup_uri_copy (uri);
pending->priority = priority;
pending->max_size = max_size; pending->max_size = max_size;
pending->is_stream = is_stream; pending->is_stream = is_stream;
pending->cancellable = cancellable ? g_object_ref (cancellable) : NULL; pending->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
@ -566,7 +581,7 @@ ostree_fetcher_request_uri_internal (OstreeFetcher *self,
} }
pending->out_tmpfile = out_tmpfile; 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); ostree_fetcher_process_pending_queue (self);
} }
@ -587,11 +602,12 @@ void
_ostree_fetcher_request_uri_with_partial_async (OstreeFetcher *self, _ostree_fetcher_request_uri_with_partial_async (OstreeFetcher *self,
SoupURI *uri, SoupURI *uri,
guint64 max_size, guint64 max_size,
int priority,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) 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, callback, user_data,
_ostree_fetcher_request_uri_with_partial_async); _ostree_fetcher_request_uri_with_partial_async);
} }
@ -618,11 +634,12 @@ static void
ostree_fetcher_stream_uri_async (OstreeFetcher *self, ostree_fetcher_stream_uri_async (OstreeFetcher *self,
SoupURI *uri, SoupURI *uri,
guint64 max_size, guint64 max_size,
int priority,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) 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, callback, user_data,
ostree_fetcher_stream_uri_async); ostree_fetcher_stream_uri_async);
} }
@ -716,6 +733,7 @@ _ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher,
ostree_fetcher_stream_uri_async (fetcher, uri, ostree_fetcher_stream_uri_async (fetcher, uri,
max_size, max_size,
OSTREE_FETCHER_DEFAULT_PRIORITY,
cancellable, cancellable,
fetch_uri_sync_on_complete, &data); fetch_uri_sync_on_complete, &data);

View File

@ -36,6 +36,9 @@ G_BEGIN_DECLS
#define OSTREE_IS_FETCHER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_FETCHER)) #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)) #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 OstreeFetcherClass OstreeFetcherClass;
typedef struct OstreeFetcher OstreeFetcher; 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, void _ostree_fetcher_request_uri_with_partial_async (OstreeFetcher *self,
SoupURI *uri, SoupURI *uri,
guint64 max_size, guint64 max_size,
int priority,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);

View File

@ -518,6 +518,7 @@ try_next_url (OstreeMetalinkRequest *self)
_ostree_fetcher_request_uri_with_partial_async (self->metalink->fetcher, next, _ostree_fetcher_request_uri_with_partial_async (self->metalink->fetcher, next,
self->metalink->max_size, self->metalink->max_size,
OSTREE_FETCHER_DEFAULT_PRIORITY,
g_task_get_cancellable (self->task), g_task_get_cancellable (self->task),
on_fetched_url, self->task); on_fetched_url, self->task);
} }

View File

@ -1123,6 +1123,7 @@ enqueue_one_object_request (OtPullData *pull_data,
_ostree_fetcher_request_uri_with_partial_async (pull_data->fetcher, obj_uri, _ostree_fetcher_request_uri_with_partial_async (pull_data->fetcher, obj_uri,
expected_max_size, expected_max_size,
OSTREE_FETCHER_DEFAULT_PRIORITY,
pull_data->cancellable, pull_data->cancellable,
is_meta ? meta_fetch_on_complete : content_fetch_on_complete, fetch_data); is_meta ? meta_fetch_on_complete : content_fetch_on_complete, fetch_data);
soup_uri_free (obj_uri); 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); 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_request_uri_with_partial_async (pull_data->fetcher, target_uri, size,
OSTREE_FETCHER_DEFAULT_PRIORITY,
pull_data->cancellable, pull_data->cancellable,
static_deltapart_fetch_on_complete, static_deltapart_fetch_on_complete,
fetch_data); fetch_data);