]> www.fi.muni.cz Git - evince.git/commitdiff
libview: add a method to get the job currently running in the worker thread
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sat, 4 Dec 2010 14:41:35 +0000 (15:41 +0100)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Sat, 4 Dec 2010 14:56:50 +0000 (15:56 +0100)
When a job is cancelled while it's running, the cancelled signal might be
emitted before the job finishes, and since the finished signal is not
emitted for cancelled jobs, it's not possible to know when the job has
finished. With this method we can see whether the job is still running
and wait until it finishes.

libview/ev-job-scheduler.c
libview/ev-job-scheduler.h

index 2537c321869e24f649d53cd52c144360210e08f9..85e5adda30ce5f5d295dc40c60322298b689bddf 100644 (file)
@@ -30,6 +30,8 @@ typedef struct _EvSchedulerJob {
 G_LOCK_DEFINE_STATIC(job_list);
 static GSList *job_list = NULL;
 
+static volatile EvJob *running_job = NULL;
+
 static gpointer ev_job_thread_proxy               (gpointer        data);
 static void     ev_scheduler_thread_job_cancelled (EvSchedulerJob *job,
                                                   GCancellable   *cancellable);
@@ -179,9 +181,13 @@ ev_job_thread (EvJob *job)
        do {
                if (g_cancellable_is_cancelled (job->cancellable))
                        result = FALSE;
-               else
+               else {
+                        g_atomic_pointer_set (&running_job, job);
                        result = ev_job_run (job);
+                }
        } while (result);
+
+        g_atomic_pointer_set (&running_job, NULL);
 }
 
 static gboolean
@@ -303,3 +309,8 @@ ev_job_scheduler_update_job (EvJob         *job,
        }
 }
 
+EvJob *
+ev_job_scheduler_get_running_thread_job (void)
+{
+        return g_atomic_pointer_get (&running_job);
+}
index 9c7a0d83fdfa68bcffb0a066b36c69f6711544a9..0e08b96c5b523c0ee049c8a86d5666448df210ef 100644 (file)
@@ -38,10 +38,11 @@ typedef enum {
        EV_JOB_N_PRIORITIES
 } EvJobPriority;
 
-void ev_job_scheduler_push_job   (EvJob        *job,
-                                 EvJobPriority priority);
-void ev_job_scheduler_update_job (EvJob        *job,
-                                 EvJobPriority priority);
+void   ev_job_scheduler_push_job               (EvJob        *job,
+                                                EvJobPriority priority);
+void   ev_job_scheduler_update_job             (EvJob        *job,
+                                                EvJobPriority priority);
+EvJob *ev_job_scheduler_get_running_thread_job (void);
 
 G_END_DECLS