Author: post
Date: 2010-12-30 18:06:45 +0100 (Thu, 30 Dec 2010)
New Revision: 3747
Modified:
trunk/librawstudio/rs-io.c
trunk/librawstudio/rs-io.h
Log:
Add function to retrieve number of jobs left.
Modified: trunk/librawstudio/rs-io.c
===================================================================
--- trunk/librawstudio/rs-io.c 2010-12-30 17:05:28 UTC (rev 3746)
+++ trunk/librawstudio/rs-io.c 2010-12-30 17:06:45 UTC (rev 3747)
@@ -23,6 +23,8 @@
static GAsyncQueue *queue = NULL;
static GStaticRecMutex io_lock = G_STATIC_REC_MUTEX_INIT;
static gboolean pause_queue = FALSE;
+static gint queue_active_count = 0;
+static GStaticMutex count_lock = G_STATIC_MUTEX_INIT;
static gint
@@ -51,14 +53,26 @@
g_usleep(1000);
else
{
- job = g_async_queue_pop(queue);
+ g_static_mutex_lock(&count_lock);
+ job = g_async_queue_try_pop(queue);
+ if (job)
+ queue_active_count++;
+ g_static_mutex_unlock(&count_lock);
/* If we somehow got NULL, continue. I'm not sure this
will ever happen, but this is better than random segfaults :) */
- if (!job)
- continue;
-
- rs_io_job_execute(job);
- rs_io_job_do_callback(job);
+ if (job)
+ {
+ rs_io_job_execute(job);
+ rs_io_job_do_callback(job);
+ g_static_mutex_lock(&count_lock);
+ queue_active_count--;
+ g_static_mutex_unlock(&count_lock);
+ }
+ else
+ {
+ /* Sleep 1 ms */
+ g_usleep(1000);
+ }
}
}
@@ -299,3 +313,15 @@
{
pause_queue = FALSE;
}
+
+/**
+ * Returns the number of jobs left
+ */
+gint
+rs_io_get_jobs_left()
+{
+ g_static_mutex_lock(&count_lock);
+ gint left = g_async_queue_length(queue) + queue_active_count;
+ g_static_mutex_unlock(&count_lock);
+ return left;
+}
\ No newline at end of file
Modified: trunk/librawstudio/rs-io.h
===================================================================
--- trunk/librawstudio/rs-io.h 2010-12-30 17:05:28 UTC (rev 3746)
+++ trunk/librawstudio/rs-io.h 2010-12-30 17:06:45 UTC (rev 3747)
@@ -121,4 +121,10 @@
void
rs_io_unlock();
+/**
+ * Returns the number of jobs left
+ */
+gint
+rs_io_get_jobs_left();
+
#endif /* RS_IO_H */
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit