X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=shell%2Fev-job-queue.c;h=8280aab4b88939ffa3521b99a04cdeed92ab464c;hb=f343927df4325959193353c52cff1ea4b20b2286;hp=d2733d6f28575051856ccad08db634470c67d592;hpb=ca679febd93eef2a4a6afd99cbd7aee8ab537443;p=evince.git diff --git a/shell/ev-job-queue.c b/shell/ev-job-queue.c index d2733d6f..8280aab4 100644 --- a/shell/ev-job-queue.c +++ b/shell/ev-job-queue.c @@ -1,3 +1,4 @@ +#include #include "ev-job-queue.h" /* Like glib calling convention, all functions with _locked in their name assume @@ -13,6 +14,7 @@ static GQueue *render_queue_low = NULL; static GQueue *thumbnail_queue_high = NULL; static GQueue *thumbnail_queue_low = NULL; static GQueue *load_queue = NULL; +static GQueue *save_queue = NULL; static GQueue *fonts_queue = NULL; static GQueue *print_queue = NULL; @@ -52,6 +54,14 @@ add_job_to_async_queue (GQueue *queue, EvJob *job) g_queue_push_tail (queue, job); } +/** + * add_job_to_queue_locked: + * @queue: a #GQueue where the #EvJob will be added. + * @job: an #EvJob to be added to the specified #GQueue. + * + * Add the #EvJob to the specified #GQueue and woke up the ev_render_thread who + * is waiting for render_cond. + */ static void add_job_to_queue_locked (GQueue *queue, EvJob *job) @@ -61,6 +71,14 @@ add_job_to_queue_locked (GQueue *queue, g_cond_broadcast (render_cond); } +/** + * notify_finished: + * @job: the object that signal will be reseted. + * + * It does emit the job finished signal and returns %FALSE. + * + * Returns: %FALSE. + */ static gboolean notify_finished (GObject *job) { @@ -69,6 +87,13 @@ notify_finished (GObject *job) return FALSE; } +/** + * job_finished_cb: + * @job: the #EvJob that has been handled. + * + * It does finish the job last work and look if there is any more job to be + * handled. + */ static void job_finished_cb (EvJob *job) { @@ -77,6 +102,14 @@ job_finished_cb (EvJob *job) ev_job_queue_run_next (); } +/** + * handle_job: + * @job: the #EvJob to be handled. + * + * First, it does check if the job is async and then it does attend it if + * possible giving a failed assertion otherwise. If the job isn't async it does + * attend it and notify that the job has been finished. + */ static void handle_job (EvJob *job) { @@ -98,6 +131,8 @@ handle_job (EvJob *job) ev_job_links_run (EV_JOB_LINKS (job)); else if (EV_IS_JOB_LOAD (job)) ev_job_load_run (EV_JOB_LOAD (job)); + else if (EV_IS_JOB_SAVE (job)) + ev_job_save_run (EV_JOB_SAVE (job)); else if (EV_IS_JOB_RENDER (job)) ev_job_render_run (EV_JOB_RENDER (job)); else if (EV_IS_JOB_FONTS (job)) @@ -114,6 +149,24 @@ handle_job (EvJob *job) } } +/** + * search_for_jobs_unlocked: + * + * Check if there is any job at the synchronized queues and return any existing + * job in them taking in account the next priority: + * + * render_queue_high > + * thumbnail_queue_high > + * render_queue_low > + * links_queue > + * load_queue > + * thumbnail_queue_low > + * fonts_queue > + * print_queue > + * + * Returns: an available #EvJob in the queues taking in account stablished queue + * priorities. + */ static EvJob * search_for_jobs_unlocked (void) { @@ -139,6 +192,10 @@ search_for_jobs_unlocked (void) if (job) return job; + job = (EvJob *) g_queue_pop_head (save_queue); + if (job) + return job; + job = (EvJob *) g_queue_pop_head (thumbnail_queue_low); if (job) return job; @@ -154,6 +211,15 @@ search_for_jobs_unlocked (void) return NULL; } +/** + * no_jobs_available_unlocked: + * + * Looks if there is any job at render, links, load, thumbnail. fonts and print + * queues. + * + * Returns: %TRUE if the render, links, load, thumbnail, fonts and print queues + * are empty, %FALSE in other case. + */ static gboolean no_jobs_available_unlocked (void) { @@ -161,6 +227,7 @@ no_jobs_available_unlocked (void) && g_queue_is_empty (render_queue_low) && g_queue_is_empty (links_queue) && g_queue_is_empty (load_queue) + && g_queue_is_empty (save_queue) && g_queue_is_empty (thumbnail_queue_high) && g_queue_is_empty (thumbnail_queue_low) && g_queue_is_empty (fonts_queue) @@ -168,6 +235,16 @@ no_jobs_available_unlocked (void) } /* the thread mainloop function */ +/** + * ev_render_thread: + * @data: data passed to the thread. + * + * The thread mainloop function. It does wait for any available job in synced + * queues to handle it. + * + * Returns: the return value of the thread, which will be returned by + * g_thread_join(). + */ static gpointer ev_render_thread (gpointer data) { @@ -192,6 +269,12 @@ ev_render_thread (gpointer data) } +/** + * ev_job_queue_run_next: + * + * It does look for any job on the render high priority queue first and after + * in the render low priority one, and then it does handle it. + */ static void ev_job_queue_run_next (void) { @@ -211,6 +294,12 @@ ev_job_queue_run_next (void) } /* Public Functions */ +/** + * ev_job_queue_init: + * + * Creates a new cond, new mutex, a thread for evince job handling and inits + * every queue. + */ void ev_job_queue_init (void) { @@ -221,6 +310,7 @@ ev_job_queue_init (void) links_queue = g_queue_new (); load_queue = g_queue_new (); + save_queue = g_queue_new (); render_queue_high = g_queue_new (); render_queue_low = g_queue_new (); async_render_queue_high = g_queue_new (); @@ -259,6 +349,9 @@ find_queue (EvJob *job, } else if (EV_IS_JOB_LOAD (job)) { /* the priority doesn't effect load */ return load_queue; + } else if (EV_IS_JOB_SAVE (job)) { + /* the priority doesn't effect save */ + return save_queue; } else if (EV_IS_JOB_LINKS (job)) { /* the priority doesn't effect links */ return links_queue; @@ -405,6 +498,8 @@ ev_job_queue_remove_job (EvJob *job) retval = remove_job_from_queue_locked (links_queue, job); } else if (EV_IS_JOB_LOAD (job)) { retval = remove_job_from_queue_locked (load_queue, job); + } else if (EV_IS_JOB_SAVE (job)) { + retval = remove_job_from_queue_locked (save_queue, job); } else if (EV_IS_JOB_FONTS (job)) { retval = remove_job_from_queue_locked (fonts_queue, job); } else if (EV_IS_JOB_PRINT (job)) {