[gegl/threaded-base-classes: 13/13] factor out check if threading should be used
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/threaded-base-classes: 13/13] factor out check if threading should be used
- Date: Thu, 26 Jun 2014 22:46:06 +0000 (UTC)
commit e25e7d08cd89b6dabed523130705d32d85a8c0b8
Author: Øyvind Kolås <pippin gimp org>
Date: Fri Jun 27 00:41:20 2014 +0200
factor out check if threading should be used
Also opt out of multi-threading if the op has an opencl
implementation and opencl is enabled.
gegl/operation/gegl-operation-composer.c | 8 ++------
gegl/operation/gegl-operation-composer3.c | 4 ++--
gegl/operation/gegl-operation-filter.c | 8 ++------
gegl/operation/gegl-operation-source.c | 9 ++-------
gegl/operation/gegl-operation.c | 24 ++++++++++++++++++++++++
gegl/operation/gegl-operation.h | 4 ++++
6 files changed, 36 insertions(+), 21 deletions(-)
---
diff --git a/gegl/operation/gegl-operation-composer.c b/gegl/operation/gegl-operation-composer.c
index 6617842..1a1579f 100644
--- a/gegl/operation/gegl-operation-composer.c
+++ b/gegl/operation/gegl-operation-composer.c
@@ -137,7 +137,6 @@ gegl_operation_composer_process (GeglOperation *operation,
gint level)
{
GeglOperationComposerClass *klass = GEGL_OPERATION_COMPOSER_GET_CLASS (operation);
- GeglOperationClass *op_class = GEGL_OPERATION_CLASS (klass);
GeglBuffer *input;
GeglBuffer *aux;
GeglBuffer *output;
@@ -159,12 +158,9 @@ gegl_operation_composer_process (GeglOperation *operation,
if (input != NULL ||
aux != NULL)
{
- gint threads = gegl_config ()->threads;
-
- if (threads > 1 &&
- op_class->parallelize &&
- result->width * result->height > 64*64)
+ if (gegl_operation_use_threading (operation, result))
{
+ gint threads = gegl_config ()->threads;
GThreadPool *pool = thread_pool ();
ThreadData thread_data[GEGL_MAX_THREADS];
gint pending = threads;
diff --git a/gegl/operation/gegl-operation-composer3.c b/gegl/operation/gegl-operation-composer3.c
index b885661..523d265 100644
--- a/gegl/operation/gegl-operation-composer3.c
+++ b/gegl/operation/gegl-operation-composer3.c
@@ -195,9 +195,9 @@ gegl_operation_composer3_process (GeglOperation *operation,
aux != NULL ||
aux2 != NULL)
{
- gint threads = gegl_config ()->threads;
- if (threads > 1 && op_class->parallelize && result->width * result->height > 64*64)
+ if (gegl_operation_use_threading (operation, result))
{
+ gint threads = gegl_config ()->threads;
GThreadPool *pool = thread_pool ();
ThreadData thread_data[GEGL_MAX_THREADS];
gint pending = threads;
diff --git a/gegl/operation/gegl-operation-filter.c b/gegl/operation/gegl-operation-filter.c
index 680d02b..ede05b5 100644
--- a/gegl/operation/gegl-operation-filter.c
+++ b/gegl/operation/gegl-operation-filter.c
@@ -144,14 +144,11 @@ gegl_operation_filter_process (GeglOperation *operation,
gint level)
{
GeglOperationFilterClass *klass;
- GeglOperationClass *op_class;
GeglBuffer *input;
GeglBuffer *output;
gboolean success = FALSE;
- gint threads = gegl_config ()->threads;
klass = GEGL_OPERATION_FILTER_GET_CLASS (operation);
- op_class = GEGL_OPERATION_CLASS (klass);
g_assert (klass->process);
@@ -164,10 +161,9 @@ gegl_operation_filter_process (GeglOperation *operation,
input = gegl_operation_context_get_source (context, "input");
output = gegl_operation_context_get_target (context, "output");
- if (threads > 1 &&
- op_class->parallelize &&
- result->width * result->height > 64*64)
+ if (gegl_operation_use_threading (operation, result))
{
+ gint threads = gegl_config ()->threads;
GThreadPool *pool = thread_pool ();
ThreadData thread_data[GEGL_MAX_THREADS];
gint pending = threads;
diff --git a/gegl/operation/gegl-operation-source.c b/gegl/operation/gegl-operation-source.c
index 233601a..1997eac 100644
--- a/gegl/operation/gegl-operation-source.c
+++ b/gegl/operation/gegl-operation-source.c
@@ -120,12 +120,8 @@ gegl_operation_source_process (GeglOperation *operation,
gint level)
{
GeglOperationSourceClass *klass = GEGL_OPERATION_SOURCE_GET_CLASS (operation);
- GeglOperationClass *op_class;
GeglBuffer *output;
gboolean success = FALSE;
- gint threads = gegl_config ()->threads;
-
- op_class = GEGL_OPERATION_CLASS (klass);
if (strcmp (output_prop, "output"))
{
@@ -136,10 +132,9 @@ gegl_operation_source_process (GeglOperation *operation,
g_assert (klass->process);
output = gegl_operation_context_get_target (context, "output");
- if (threads > 1 &&
- op_class->parallelize &&
- result->width * result->height > 64*64)
+ if (gegl_operation_use_threading (operation, result))
{
+ gint threads = gegl_config ()->threads;
GThreadPool *pool = thread_pool ();
ThreadData thread_data[GEGL_MAX_THREADS];
gint pending = threads;
diff --git a/gegl/operation/gegl-operation.c b/gegl/operation/gegl-operation.c
index 06c6bc7..3a72c83 100644
--- a/gegl/operation/gegl-operation.c
+++ b/gegl/operation/gegl-operation.c
@@ -23,6 +23,7 @@
#include <string.h>
#include "gegl.h"
+#include "gegl-config.h"
#include "gegl-types-internal.h"
#include "gegl-operation.h"
#include "gegl-operation-context.h"
@@ -747,3 +748,26 @@ gegl_operation_get_source_format (GeglOperation *operation,
}
return NULL;
}
+
+gboolean
+gegl_operation_use_threading (GeglOperation *operation,
+ const GeglRectangle *roi)
+{
+ gint threads = gegl_config ()->threads;
+ if (threads == 1)
+ return FALSE;
+
+ {
+ GeglOperationClass *op_class;
+ op_class = GEGL_OPERATION_GET_CLASS (operation);
+
+ if (op_class->opencl_support && gegl_cl_is_accelerated ())
+ return FALSE;
+
+ if (op_class->parallelize &&
+ roi->width * roi->height > 64*64)
+ return TRUE;
+ }
+ return FALSE;
+}
+
diff --git a/gegl/operation/gegl-operation.h b/gegl/operation/gegl-operation.h
index 02c6f72..07e4207 100644
--- a/gegl/operation/gegl-operation.h
+++ b/gegl/operation/gegl-operation.h
@@ -246,6 +246,10 @@ void gegl_operation_set_key (const gchar *operation_type,
gboolean gegl_operation_use_opencl (const GeglOperation *operation);
+gboolean
+gegl_operation_use_threading (GeglOperation *operation,
+ const GeglRectangle *roi);
+
/* Invalidate a specific rectangle, indicating the any computation depending
* on this roi is now invalid.
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]