From 29aeb95a28d518944f1eb268f93a96cbb9dff7f2 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sat, 28 Mar 2009 22:00:06 +0100 Subject: Multithreading support Also made progress output a little bit nicer default = 1 thread at once, for safety reasons I've encountered critical issues with ImageMagick compiled with OpenMP support. Hope that package maintainers are clever. ShittyMagickWandGenesis(), ShittyMagickWandTerminus() :-) --- src/cgg.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/cgg.c') diff --git a/src/cgg.c b/src/cgg.c index ea48d52..92debc8 100644 --- a/src/cgg.c +++ b/src/cgg.c @@ -22,13 +22,16 @@ #include #include +#include #include +#include + #include #include "setup.h" -#include "generators.h" +#include "job-manager.h" @@ -39,17 +42,19 @@ * parse_cmd: parse commandline and fill global variable parameters */ gboolean -parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean *verbose) +parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean *verbose, int *jobs) { static gboolean _verbose = FALSE; static gchar *_source_dir = NULL; static gchar *_dst_dir = NULL; + static int _jobs = 1; static GOptionEntry entries[] = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &_verbose, "Be verbose", NULL }, { "source", 's', 0, G_OPTION_ARG_STRING, &_source_dir, "Specifies path to source structure", NULL }, { "output", 'o', 0, G_OPTION_ARG_STRING, &_dst_dir, "Generate files to the specified directory instead of current", NULL }, + { "jobs", 'j', 0, G_OPTION_ARG_INT, &_jobs, "Allow N jobs at once (default=1)", NULL }, { NULL } }; @@ -86,6 +91,7 @@ parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean * *source_dir = _source_dir; *dst_dir = _dst_dir; *verbose = _verbose; + *jobs = _jobs; return TRUE; } @@ -98,6 +104,7 @@ main(int argc, char* argv[]) char *source_dir; char *dst_dir; gboolean verbose; + int jobs; TGallerySetup *setup; /* @@ -107,13 +114,19 @@ main(int argc, char* argv[]) */ LIBXML_TEST_VERSION; + g_thread_init (NULL); + + /* Initialize ImageMagick at this point, for multithreading safety */ + MagickWandGenesis(); + + source_dir = NULL; dst_dir = NULL; setup = malloc(sizeof(TGallerySetup)); /* Parse commandline */ - if (! parse_cmd (argc, argv, &source_dir, &dst_dir, &verbose)) + if (! parse_cmd (argc, argv, &source_dir, &dst_dir, &verbose, &jobs)) return -1; if ((! source_dir) || (access (source_dir, R_OK))) { @@ -140,8 +153,10 @@ main(int argc, char* argv[]) /* Start building the gallery tree */ setup->verbose = verbose; - build_tree (setup, source_dir, dst_dir, NULL); + build_tree (setup, source_dir, dst_dir, NULL, -1, jobs); + + MagickWandTerminus(); /* Cleanup function for the XML library. */ xmlCleanupParser(); -- cgit v1.2.3