summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-09-23 00:33:29 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-09-23 00:33:29 +0200
commitdbd6c19704aae916ad948861ae0b83cafa479810 (patch)
treee957b9a6e85c9377cd11c60412d89c100fbd6655
parent257d7e6501c919e7847e9abd5f39f40338b621d9 (diff)
downloadcataract-dbd6c19704aae916ad948861ae0b83cafa479810.tar.xz
Optimize job manager index counting, filter out non-processable items
-rw-r--r--src/job-manager.c67
1 files changed, 33 insertions, 34 deletions
diff --git a/src/job-manager.c b/src/job-manager.c
index 1cd4519..453bb19 100644
--- a/src/job-manager.c
+++ b/src/job-manager.c
@@ -43,11 +43,14 @@ typedef struct {
GList *job_items;
const gchar *dst_dir;
gboolean force_update;
+ int total_items;
} TJob;
typedef struct {
TIndexItem *item;
gboolean gen_done;
+ int index; /* processed image index */
+ int real_index; /* absolute index in the list */
} TJobItem;
@@ -109,9 +112,7 @@ thread_func (gpointer data)
{
TIndexItem *item;
gchar *imgname;
- int i;
gchar *s1, *s2, *s3;
- int total, index, real_index;
TJob *job = data;
gboolean updated;
GList *l;
@@ -119,38 +120,29 @@ thread_func (gpointer data)
do {
item = NULL;
- total = 0;
- real_index = -1;
- index = -1;
- i = 0;
+ job_item = NULL;
/* Find unprocessed item */
G_LOCK (job_items);
- if (job->job_items != NULL) {
+ if (job->job_items != NULL)
for (l = job->job_items; l != NULL; l = g_list_next (l)) {
job_item = l->data;
- i++;
- if (job_item->item != NULL && job_item->item->type == INDEX_ITEM_TYPE_PICTURE) {
- total++;
- if (job_item->gen_done == FALSE && item == NULL) {
- job_item->gen_done = TRUE;
- item = job_item->item;
- index = total;
- real_index = i;
- }
+ if (job_item->gen_done == FALSE) {
+ job_item->gen_done = TRUE;
+ item = job_item->item;
+ break;
}
}
- }
G_UNLOCK (job_items);
/* actually do some work */
- if (item != NULL) {
+ if (item != NULL && job_item != NULL) {
imgname = g_path_get_basename ((item->path == NULL && item->preview) ? item->preview : item->path);
- updated = generate_image (job->setup, job->items, item, real_index, job->dst_dir, ! job->force_update);
-
+ updated = generate_image (job->setup, job->items, item, job_item->real_index, job->dst_dir, ! job->force_update);
+
if (updated && job->setup->verbose) {
G_LOCK (items_print);
- g_print (" [%d/%d] Processing item \"%s\"\n", index, total, imgname);
+ g_print (" [%d/%d] Processing item \"%s\"\n", job_item->index, job->total_items, imgname);
G_UNLOCK (items_print);
}
@@ -302,8 +294,16 @@ build_tree (TGallerySetup *setup,
return FALSE;
}
}
-
- /* Create references to the items for the job manager to store actual job state in */
+
+ /* Prepare job manager structures */
+ job = g_malloc0 (sizeof (TJob));
+ job->items = items;
+ job->setup = setup;
+ job->dst_dir = dst_dir;
+ job->force_update = force_update;
+ job->total_items = 0;
+
+ /* Create references to the items for job manager to store actual job state in */
job_items = NULL;
if (items->items->len > 0) {
for (i = 0; i < items->items->len; i++) {
@@ -312,21 +312,20 @@ build_tree (TGallerySetup *setup,
log_error ("run_job: error getting item %d\n", i);
continue;
}
- job_item = g_malloc0 (sizeof (TJobItem));
- job_item->item = item;
- job_item->gen_done = FALSE;
- job_items = g_list_append (job_items, job_item);
+ if (item->type == INDEX_ITEM_TYPE_PICTURE) {
+ job->total_items++;
+ job_item = g_malloc0 (sizeof (TJobItem));
+ job_item->item = item;
+ job_item->gen_done = FALSE;
+ job_item->index = job->total_items;
+ job_item->real_index = i;
+ job_items = g_list_append (job_items, job_item);
+ }
}
}
+ job->job_items = job_items;
/* Generate images + particular html pages */
- job = g_new0 (TJob, 1);
- job->items = items;
- job->setup = setup;
- job->job_items = job_items;
- job->dst_dir = dst_dir;
- job->force_update = force_update;
-
#ifdef G_THREADS_ENABLED
thread_list = NULL;