This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated discards 274f579cdeaeeb021e9650e6022c01bb874f7fed (commit) via 99e04dcfb4af842f3a3be19e62fb52b9ce2ff725 (commit)
This update added new revisions after undoing existing revisions. That is to say, the old revision is not a strict subset of the new revision. This situation occurs when you --force push a change and generate a repository containing something like this:
* -- * -- B -- O -- O -- O (274f579cdeaeeb021e9650e6022c01bb874f7fed) N -- N -- N (99e04dcfb4af842f3a3be19e62fb52b9ce2ff725)
When this happens we assume that you've already had alert emails for all of the O revisions, and so we here report only the revisions in the N branch from the common base, B.
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/99e04dcfb4af842f3a3be19e62fb52b9ce2ff...
commit 99e04dcfb4af842f3a3be19e62fb52b9ce2ff725 Author: Cyril Hrubis metan@ucw.cz Date: Sun Jul 8 23:24:44 2012 +0200
filters,core: Update in the threads interface.
diff --git a/include/core/GP_ProgressCallback.h b/include/core/GP_ProgressCallback.h index 818bafa..e944154 100644 --- a/include/core/GP_ProgressCallback.h +++ b/include/core/GP_ProgressCallback.h @@ -24,10 +24,11 @@
Progress callback implementation.
- Progress callbacks serves two purposes + Progress callbacks serves following purposes:
- ability to visibly show algorithm progress - ability to correctly abort operation in the middle of processing + - ability to override default number of threads to use for the operation
*/
@@ -42,8 +43,20 @@ */ typedef struct GP_ProgressCallback { float percentage; + int (*callback)(struct GP_ProgressCallback *self); void *priv; + + /* + * Number of threads to use (if supported). This setting could be used + * to override the default number of threads as returned by + * GP_NrThreads(). + * + * 0 == use number returned from GP_NrThreads(). + * + * >= 1 use exactly n threads + */ + unsigned int threads; } GP_ProgressCallback;
static inline int GP_ProgressCallbackReport(GP_ProgressCallback *callback, diff --git a/include/core/GP_Threads.h b/include/core/GP_Threads.h index 948f278..6cc4be6 100644 --- a/include/core/GP_Threads.h +++ b/include/core/GP_Threads.h @@ -26,8 +26,8 @@
*/
-#ifndef GP_THREADS_H -#define GP_THREADS_H +#ifndef CORE_GP_THREADS_H +#define CORE_GP_THREADS_H
#include <pthread.h>
@@ -35,12 +35,31 @@ #include "GP_Types.h"
/* - * Returns an optimal number of threads for a given image size on a particular - * machine. Most of the time, if the image is not too small, this function - * returns number of processors as seen by the operating system. + * Sets default number of threads the library uses + * (changes the behavior of GP_NrThreads()). + * + * 0 == auto + * Most of the time, if the image is not too small, this makes + * the filter run number of processors (as seen by the operating system) + * threads. + * + * 1 == one thread + * Everything runs in exactly one thread. This is default value. + * + * >= 2 + * Runs exactly n threads unless the image is too small. + * + * This value may also be overriden by the GP_THREADS enviroment variable. + * + * Moreover the value may be changed for a single call by settings in progres + * callback structure. */ -unsigned int GP_NrThreads(GP_Size w, GP_Size h); +void GP_NrThreadsSet(unsigned int nr);
+/* + * Returns a number of threads to use. + */ +unsigned int GP_NrThreads(GP_Size w, GP_Size h, GP_ProgressCallback *callback);
/* * Multithreaded progress callback priv data guarded by a mutex. @@ -78,4 +97,4 @@ struct GP_ProgressCallbackMPPriv { */ int GP_ProgressCallbackMP(GP_ProgressCallback *self);
-#endif /* GP_THREADS_H */ +#endif /* CORE_GP_THREADS_H */ diff --git a/libs/core/GP_Threads.c b/libs/core/GP_Threads.c index 638f27b..ff59d75 100644 --- a/libs/core/GP_Threads.c +++ b/libs/core/GP_Threads.c @@ -21,26 +21,63 @@ *****************************************************************************/
#include <unistd.h> +#include <stdlib.h>
#include "GP_Common.h" #include "GP_Debug.h"
#include "GP_Threads.h"
-unsigned int GP_NrThreads(GP_Size w, GP_Size h) +static unsigned int nr_threads = 1; + +unsigned int GP_NrThreads(GP_Size w, GP_Size h, GP_ProgressCallback *callback) { - int count = sysconf(_SC_NPROCESSORS_ONLN); - int threads = GP_MIN(count, (int)(w * h / 1024) + 1); + int count, threads; + char *env; + + /* Try to override nr_threads from the callback first */ + if (callback != NULL && callback->threads) { + GP_DEBUG(1, "Overriding nr_threads from callback to %i", + callback->threads); + nr_threads = callback->threads; + } else { + /* Then try to override it from the enviroment variable */ + env = getenv("GP_THREADS"); + + if (env) { + nr_threads = atoi(env); + GP_DEBUG(1, "Using GP_THREADS=%u from enviroment " + "variable", nr_threads); + } + }
- if (count < -1) + if (nr_threads == 0) { + count = sysconf(_SC_NPROCESSORS_ONLN); + GP_DEBUG(1, "Found %i CPUs", count); + } else { + count = nr_threads; + GP_DEBUG(1, "Using nr_threads=%i", count); + } + + threads = GP_MIN(count, (int)(w * h / 1024) + 1); + + /* Call to the sysconf may return -1 if unsupported */ + if (threads < -1) threads = 1;
- GP_DEBUG(1, "Found %u CPUs size %ux%u runnig %u threads", + GP_DEBUG(1, "Max threads %i image size %ux%u runnig %u threads", count, w, h, threads);
return threads; }
+void GP_NrThreadsSet(unsigned int nr) +{ + nr_threads = nr; + + GP_DEBUG(1, "Setting default number of threads to %u", nr); +} + int GP_ProgressCallbackMP(GP_ProgressCallback *self) { struct GP_ProgressCallbackMPPriv *priv = self->priv; diff --git a/libs/filters/GP_LinearThreads.c b/libs/filters/GP_LinearThreads.c index 9a2aa43..2ab625e 100644 --- a/libs/filters/GP_LinearThreads.c +++ b/libs/filters/GP_LinearThreads.c @@ -60,11 +60,14 @@ static void *linear_convolution(void *arg)
int GP_FilterHConvolutionMP_Raw(const GP_ConvolutionParams *params) { - int i, t = GP_NrThreads(params->w_src, params->h_src); + int i, t = GP_NrThreads(params->w_src, params->h_src, params->callback);
if (t == 1) return GP_FilterHConvolution_Raw(params);
+ GP_ASSERT(params->src != params->dst, + "Multithreaded convolution can't work in-place"); + GP_PROGRESS_CALLBACK_MP(callback_mp, params->callback);
/* Run t threads */ @@ -105,11 +108,14 @@ int GP_FilterHConvolutionMP_Raw(const GP_ConvolutionParams *params)
int GP_FilterVConvolutionMP_Raw(const GP_ConvolutionParams *params) { - int i, t = GP_NrThreads(params->w_src, params->h_src); + int i, t = GP_NrThreads(params->w_src, params->h_src, params->callback);
if (t == 1) return GP_FilterVConvolution_Raw(params); + GP_ASSERT(params->src != params->dst, + "Multithreaded convolution can't work in-place"); + GP_PROGRESS_CALLBACK_MP(callback_mp, params->callback); /* Run t threads */ @@ -149,10 +155,13 @@ int GP_FilterVConvolutionMP_Raw(const GP_ConvolutionParams *params)
int GP_FilterConvolutionMP_Raw(const GP_ConvolutionParams *params) { - int i, t = GP_NrThreads(params->w_src, params->h_src); + int i, t = GP_NrThreads(params->w_src, params->h_src, params->callback);
if (t == 1) return GP_FilterConvolution_Raw(params); + + GP_ASSERT(params->src != params->dst, + "Multithreaded convolution can't work in-place");
GP_PROGRESS_CALLBACK_MP(callback_mp, params->callback);
-----------------------------------------------------------------------
Summary of changes: include/core/GP_Threads.h | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.