summaryrefslogtreecommitdiff
path: root/src/job-manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/job-manager.c')
-rw-r--r--src/job-manager.c63
1 files changed, 44 insertions, 19 deletions
diff --git a/src/job-manager.c b/src/job-manager.c
index 8485acb..1cd4519 100644
--- a/src/job-manager.c
+++ b/src/job-manager.c
@@ -40,10 +40,15 @@
typedef struct {
TGallerySetup *setup;
TAlbum *items;
+ GList *job_items;
const gchar *dst_dir;
gboolean force_update;
} TJob;
+typedef struct {
+ TIndexItem *item;
+ gboolean gen_done;
+} TJobItem;
@@ -95,7 +100,7 @@ mirror_files (TGallerySetup *setup, gchar **files, const gchar *src_tree, const
-G_LOCK_DEFINE (items);
+G_LOCK_DEFINE (job_items);
G_LOCK_DEFINE (items_print);
/* run in a cycle, returns when all completed */
@@ -109,32 +114,34 @@ thread_func (gpointer data)
int total, index, real_index;
TJob *job = data;
gboolean updated;
+ GList *l;
+ TJobItem *job_item;
do {
item = NULL;
total = 0;
real_index = -1;
index = -1;
- G_LOCK (items);
- if (job->items->items->len > 0) {
- for (i = 0; i < job->items->items->len; i++) {
- TIndexItem *item_tmp = g_ptr_array_index (job->items->items, i);
- if (item_tmp == NULL) {
- log_error ("run_job: error getting item %d\n", i);
- continue;
- }
- if (item_tmp->type == INDEX_ITEM_TYPE_PICTURE) {
+ i = 0;
+
+ /* Find unprocessed item */
+ G_LOCK (job_items);
+ 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 (item_tmp->gen_done == FALSE && item == NULL) {
- item_tmp->gen_done = TRUE;
- item = item_tmp;
+ if (job_item->gen_done == FALSE && item == NULL) {
+ job_item->gen_done = TRUE;
+ item = job_item->item;
index = total;
real_index = i;
}
}
}
}
- G_UNLOCK (items);
+ G_UNLOCK (job_items);
/* actually do some work */
if (item != NULL) {
@@ -151,11 +158,7 @@ thread_func (gpointer data)
s1 = g_strconcat (job->setup->real_templates_dir, "/", job->setup->template_photo, NULL);
s2 = g_strconcat (job->items->base_dir, "/", (item->path == NULL && item->preview) ? item->preview : item->path, NULL);
s3 = g_strconcat (job->dst_dir, "/", imgname, GET_EXT (job->setup->index_file_name), NULL);
- /* We need to lock job->items as we're doing *lots* of accesses to it */
- /* There were some replace_table failures due to that */
- G_LOCK (items);
write_html_image (job->setup, s1, s2, s3, item, job->items);
- G_UNLOCK (items);
g_free (s1);
g_free (s2);
g_free (s3);
@@ -201,6 +204,8 @@ build_tree (TGallerySetup *setup,
GThread *thread;
GList *thread_list;
gboolean force_update;
+ TJobItem *job_item;
+ GList *job_items;
printf ("Processing directory \"%s\"\n", src_tree);
stats_dirs_inc ();
@@ -297,11 +302,28 @@ build_tree (TGallerySetup *setup,
return FALSE;
}
}
-
+
+ /* Create references to the items for the job manager to store actual job state in */
+ job_items = NULL;
+ if (items->items->len > 0) {
+ for (i = 0; i < items->items->len; i++) {
+ item = g_ptr_array_index (items->items, i);
+ if (item == NULL) {
+ 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);
+ }
+ }
+
/* 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;
@@ -333,6 +355,9 @@ build_tree (TGallerySetup *setup,
#endif
g_free (job);
+ /* Cleanup generator objects */
+ g_list_foreach (job_items, (GFunc) g_free, NULL);
+ g_list_free (job_items);
/* Generate album page */
if (force_update) {