summaryrefslogtreecommitdiff
path: root/src/cgg.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-03-28 22:00:06 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-03-28 22:00:06 +0100
commit29aeb95a28d518944f1eb268f93a96cbb9dff7f2 (patch)
tree154c8870d72229a95f0ab0bd93f8c4d3048b9f91 /src/cgg.c
parentd9ff1192a7b5eb7defca68e90e06c68e9b986c94 (diff)
downloadcataract-29aeb95a28d518944f1eb268f93a96cbb9dff7f2.tar.xz
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() :-)
Diffstat (limited to 'src/cgg.c')
-rw-r--r--src/cgg.c23
1 files changed, 19 insertions, 4 deletions
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 <unistd.h>
#include <glib.h>
+#include <glib/gthread.h>
#include <libxml/xmlmemory.h>
+#include <wand/magick-wand.h>
+
#include <config.h>
#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();