app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimp-parallel.c
|
|
|
|
* Copyright (C) 2018 Ell
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gio/gio.h>
|
|
|
|
#include <gegl.h>
|
|
|
|
|
2018-05-29 09:42:03 -04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "config/gimpgeglconfig.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
|
|
|
#include "gimp-parallel.h"
|
2018-05-11 11:43:06 -04:00
|
|
|
#include "gimpasync.h"
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
#define GIMP_PARALLEL_MAX_THREADS 64
|
|
|
|
#define GIMP_PARALLEL_RUN_ASYNC_MAX_THREADS 1
|
|
|
|
#define GIMP_PARALLEL_DISTRIBUTE_MAX_THREADS GIMP_PARALLEL_MAX_THREADS
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GimpAsync *async;
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
gint priority;
|
2018-05-11 11:43:06 -04:00
|
|
|
GimpParallelRunAsyncFunc func;
|
|
|
|
gpointer user_data;
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
GDestroyNotify user_data_destroy_func;
|
2018-05-11 11:43:06 -04:00
|
|
|
} GimpParallelRunAsyncTask;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GThread *thread;
|
|
|
|
|
|
|
|
gboolean quit;
|
|
|
|
} GimpParallelRunAsyncThread;
|
|
|
|
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GimpParallelDistributeFunc func;
|
|
|
|
gint n;
|
|
|
|
gpointer user_data;
|
2018-05-11 11:43:06 -04:00
|
|
|
} GimpParallelDistributeTask;
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
GThread *thread;
|
|
|
|
GMutex mutex;
|
|
|
|
GCond cond;
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
gboolean quit;
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
GimpParallelDistributeTask *volatile task;
|
|
|
|
volatile gint i;
|
|
|
|
} GimpParallelDistributeThread;
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
static void gimp_parallel_notify_num_processors (GimpGeglConfig *config);
|
|
|
|
|
|
|
|
static void gimp_parallel_set_n_threads (gint n_threads);
|
|
|
|
|
|
|
|
static void gimp_parallel_run_async_set_n_threads (gint n_threads);
|
|
|
|
static gpointer gimp_parallel_run_async_thread_func (GimpParallelRunAsyncThread *thread);
|
|
|
|
static void gimp_parallel_run_async_execute_task (GimpParallelRunAsyncTask *task);
|
2018-05-27 12:55:16 -04:00
|
|
|
static void gimp_parallel_run_async_cancel (GimpAsync *async);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
static void gimp_parallel_distribute_set_n_threads (gint n_threads);
|
|
|
|
static gpointer gimp_parallel_distribute_thread_func (GimpParallelDistributeThread *thread);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* local variables */
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
static gint gimp_parallel_run_async_n_threads = 0;
|
|
|
|
static GimpParallelRunAsyncThread gimp_parallel_run_async_threads[GIMP_PARALLEL_RUN_ASYNC_MAX_THREADS];
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
static GMutex gimp_parallel_run_async_mutex;
|
|
|
|
static GCond gimp_parallel_run_async_cond;
|
|
|
|
static GQueue gimp_parallel_run_async_queue = G_QUEUE_INIT;
|
|
|
|
|
|
|
|
static gint gimp_parallel_distribute_n_threads = 1;
|
|
|
|
static GimpParallelDistributeThread gimp_parallel_distribute_threads[GIMP_PARALLEL_DISTRIBUTE_MAX_THREADS - 1];
|
|
|
|
|
|
|
|
static GMutex gimp_parallel_distribute_completion_mutex;
|
|
|
|
static GCond gimp_parallel_distribute_completion_cond;
|
|
|
|
static volatile gint gimp_parallel_distribute_completion_counter;
|
|
|
|
static volatile gint gimp_parallel_distribute_busy;
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_parallel_init (Gimp *gimp)
|
|
|
|
{
|
|
|
|
GimpGeglConfig *config;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
|
|
|
config = GIMP_GEGL_CONFIG (gimp->config);
|
|
|
|
|
|
|
|
g_signal_connect (config, "notify::num-processors",
|
|
|
|
G_CALLBACK (gimp_parallel_notify_num_processors),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_parallel_notify_num_processors (config);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_parallel_exit (Gimp *gimp)
|
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
GimpParallelRunAsyncTask *task;
|
|
|
|
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (gimp->config,
|
|
|
|
(gpointer) gimp_parallel_notify_num_processors,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* stop all threads */
|
2018-05-11 11:43:06 -04:00
|
|
|
gimp_parallel_set_n_threads (0);
|
|
|
|
|
|
|
|
/* finish remaining tasks */
|
2018-05-27 12:55:16 -04:00
|
|
|
while ((task = (GimpParallelRunAsyncTask *)
|
|
|
|
g_queue_pop_head (&gimp_parallel_run_async_queue)))
|
|
|
|
{
|
|
|
|
g_object_set_data (G_OBJECT (task->async),
|
|
|
|
"gimp-parallel-run-async-link", NULL);
|
|
|
|
|
|
|
|
gimp_parallel_run_async_execute_task (task);
|
|
|
|
}
|
2018-05-11 11:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpAsync *
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
gimp_parallel_run_async (GimpParallelRunAsyncFunc func,
|
2018-05-11 11:43:06 -04:00
|
|
|
gpointer user_data)
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
{
|
|
|
|
return gimp_parallel_run_async_full (0, func, user_data, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpAsync *
|
|
|
|
gimp_parallel_run_async_full (gint priority,
|
|
|
|
GimpParallelRunAsyncFunc func,
|
|
|
|
gpointer user_data,
|
|
|
|
GDestroyNotify user_data_destroy_func)
|
2018-05-11 11:43:06 -04:00
|
|
|
{
|
|
|
|
GimpAsync *async;
|
|
|
|
GimpParallelRunAsyncTask *task;
|
|
|
|
|
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
|
|
|
async = gimp_async_new ();
|
|
|
|
|
|
|
|
task = g_slice_new (GimpParallelRunAsyncTask);
|
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
task->async = GIMP_ASYNC (g_object_ref (async));
|
|
|
|
task->priority = priority;
|
|
|
|
task->func = func;
|
|
|
|
task->user_data = user_data;
|
|
|
|
task->user_data_destroy_func = user_data_destroy_func;
|
2018-05-11 11:43:06 -04:00
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
if (gimp_parallel_run_async_n_threads > 0)
|
2018-05-11 11:43:06 -04:00
|
|
|
{
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
GList *link;
|
|
|
|
GList *iter;
|
2018-05-29 09:42:03 -04:00
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
link = g_list_alloc ();
|
|
|
|
link->data = task;
|
2018-05-29 09:42:03 -04:00
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
g_object_set_data (G_OBJECT (async),
|
|
|
|
"gimp-parallel-run-async-link", link);
|
2018-05-29 09:42:03 -04:00
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
g_signal_connect_after (async, "cancel",
|
|
|
|
G_CALLBACK (gimp_parallel_run_async_cancel),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_mutex_lock (&gimp_parallel_run_async_mutex);
|
2018-05-27 12:55:16 -04:00
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
for (iter = g_queue_peek_tail_link (&gimp_parallel_run_async_queue);
|
|
|
|
iter;
|
|
|
|
iter = g_list_previous (iter))
|
|
|
|
{
|
|
|
|
GimpParallelRunAsyncTask *other_task =
|
|
|
|
(GimpParallelRunAsyncTask *) iter->data;
|
2018-05-27 12:55:16 -04:00
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
if (other_task->priority <= task->priority)
|
|
|
|
break;
|
|
|
|
}
|
2018-05-27 12:55:16 -04:00
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
if (iter)
|
|
|
|
{
|
|
|
|
link->prev = iter;
|
|
|
|
link->next = iter->next;
|
2018-05-27 12:55:16 -04:00
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
iter->next = link;
|
2018-05-11 11:43:06 -04:00
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
if (link->next)
|
|
|
|
link->next->prev = link;
|
|
|
|
else
|
|
|
|
gimp_parallel_run_async_queue.tail = link;
|
2018-05-11 11:43:06 -04:00
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
gimp_parallel_run_async_queue.length++;
|
2018-05-27 13:02:25 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
g_queue_push_head_link (&gimp_parallel_run_async_queue, link);
|
2018-05-27 13:02:25 -04:00
|
|
|
}
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
|
|
|
|
g_cond_signal (&gimp_parallel_run_async_cond);
|
|
|
|
|
|
|
|
g_mutex_unlock (&gimp_parallel_run_async_mutex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_parallel_run_async_execute_task (task);
|
2018-05-11 11:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return async;
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
}
|
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
GimpAsync *
|
|
|
|
gimp_parallel_run_async_independent (GimpParallelRunAsyncFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GimpAsync *async;
|
|
|
|
GimpParallelRunAsyncTask *task;
|
|
|
|
GThread *thread;
|
|
|
|
|
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
|
|
|
async = gimp_async_new ();
|
|
|
|
|
|
|
|
task = g_slice_new0 (GimpParallelRunAsyncTask);
|
|
|
|
|
|
|
|
task->async = GIMP_ASYNC (g_object_ref (async));
|
|
|
|
task->func = func;
|
|
|
|
task->user_data = user_data;
|
|
|
|
|
|
|
|
thread = g_thread_new (
|
|
|
|
"async-ind",
|
|
|
|
[] (gpointer data) -> gpointer
|
|
|
|
{
|
|
|
|
GimpParallelRunAsyncTask *task = (GimpParallelRunAsyncTask *) data;
|
|
|
|
|
|
|
|
/* lower the thread's priority */
|
|
|
|
#if defined (G_OS_WIN32)
|
|
|
|
SetThreadPriority (GetCurrentThread (), THREAD_MODE_BACKGROUND_BEGIN);
|
|
|
|
#elif defined (HAVE_UNISTD_H) && defined (__gnu_linux__)
|
|
|
|
nice (+10) != -1;
|
|
|
|
/* ^-- avoid "unused result" warning */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gimp_parallel_run_async_execute_task (task);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
},
|
|
|
|
task);
|
|
|
|
|
|
|
|
gimp_async_add_callback (async,
|
|
|
|
[] (GimpAsync *async,
|
|
|
|
gpointer thread)
|
|
|
|
{
|
|
|
|
g_thread_join ((GThread *) thread);
|
|
|
|
},
|
|
|
|
thread);
|
|
|
|
|
|
|
|
return async;
|
|
|
|
}
|
|
|
|
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
void
|
|
|
|
gimp_parallel_distribute (gint max_n,
|
|
|
|
GimpParallelDistributeFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
GimpParallelDistributeTask task;
|
|
|
|
gint i;
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
g_return_if_fail (func != NULL);
|
|
|
|
|
|
|
|
if (max_n == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (max_n < 0)
|
2018-05-11 11:43:06 -04:00
|
|
|
max_n = gimp_parallel_distribute_n_threads;
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
else
|
2018-05-11 11:43:06 -04:00
|
|
|
max_n = MIN (max_n, gimp_parallel_distribute_n_threads);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
if (max_n == 1 ||
|
2018-05-11 11:43:06 -04:00
|
|
|
! g_atomic_int_compare_and_exchange (&gimp_parallel_distribute_busy,
|
|
|
|
0, 1))
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
|
|
|
func (0, 1, user_data);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
task.n = max_n;
|
|
|
|
task.func = func;
|
|
|
|
task.user_data = user_data;
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
g_atomic_int_set (&gimp_parallel_distribute_completion_counter, task.n - 1);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
for (i = 0; i < task.n - 1; i++)
|
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
GimpParallelDistributeThread *thread =
|
|
|
|
&gimp_parallel_distribute_threads[i];
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
g_mutex_lock (&thread->mutex);
|
|
|
|
|
|
|
|
thread->task = &task;
|
|
|
|
thread->i = i;
|
|
|
|
|
|
|
|
g_cond_signal (&thread->cond);
|
|
|
|
|
|
|
|
g_mutex_unlock (&thread->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i, task.n, user_data);
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
if (g_atomic_int_get (&gimp_parallel_distribute_completion_counter))
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
g_mutex_lock (&gimp_parallel_distribute_completion_mutex);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
while (g_atomic_int_get (&gimp_parallel_distribute_completion_counter))
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
g_cond_wait (&gimp_parallel_distribute_completion_cond,
|
|
|
|
&gimp_parallel_distribute_completion_mutex);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
}
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
g_mutex_unlock (&gimp_parallel_distribute_completion_mutex);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
}
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
g_atomic_int_set (&gimp_parallel_distribute_busy, 0);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_parallel_distribute_range (gsize size,
|
|
|
|
gsize min_sub_size,
|
|
|
|
GimpParallelDistributeRangeFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gsize n = size;
|
|
|
|
|
|
|
|
g_return_if_fail (func != NULL);
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (min_sub_size > 1)
|
|
|
|
n /= min_sub_size;
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
n = CLAMP (n, 1, gimp_parallel_distribute_n_threads);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
gimp_parallel_distribute (n, [=] (gint i, gint n)
|
|
|
|
{
|
|
|
|
gsize offset;
|
|
|
|
gsize sub_size;
|
|
|
|
|
|
|
|
offset = (2 * i * size + n) / (2 * n);
|
|
|
|
sub_size = (2 * (i + 1) * size + n) / (2 * n) - offset;
|
|
|
|
|
|
|
|
func (offset, sub_size, user_data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_parallel_distribute_area (const GeglRectangle *area,
|
|
|
|
gsize min_sub_area,
|
|
|
|
GimpParallelDistributeAreaFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gsize n;
|
|
|
|
|
|
|
|
g_return_if_fail (area != NULL);
|
|
|
|
g_return_if_fail (func != NULL);
|
|
|
|
|
|
|
|
if (area->width <= 0 || area->height <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
n = (gsize) area->width * (gsize) area->height;
|
|
|
|
|
|
|
|
if (min_sub_area > 1)
|
|
|
|
n /= min_sub_area;
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
n = CLAMP (n, 1, gimp_parallel_distribute_n_threads);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
gimp_parallel_distribute (n, [=] (gint i, gint n)
|
|
|
|
{
|
|
|
|
GeglRectangle sub_area;
|
|
|
|
|
|
|
|
if (area->width <= area->height)
|
|
|
|
{
|
|
|
|
sub_area.x = area->x;
|
|
|
|
sub_area.width = area->width;
|
|
|
|
|
|
|
|
sub_area.y = (2 * i * area->height + n) / (2 * n);
|
|
|
|
sub_area.height = (2 * (i + 1) * area->height + n) / (2 * n);
|
|
|
|
|
|
|
|
sub_area.height -= sub_area.y;
|
|
|
|
sub_area.y += area->y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub_area.y = area->y;
|
|
|
|
sub_area.height = area->height;
|
|
|
|
|
|
|
|
sub_area.x = (2 * i * area->width + n) / (2 * n);
|
|
|
|
sub_area.width = (2 * (i + 1) * area->width + n) / (2 * n);
|
|
|
|
|
|
|
|
sub_area.width -= sub_area.x;
|
|
|
|
sub_area.x += area->x;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (&sub_area, user_data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_parallel_notify_num_processors (GimpGeglConfig *config)
|
|
|
|
{
|
|
|
|
gimp_parallel_set_n_threads (config->num_processors);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_parallel_set_n_threads (gint n_threads)
|
2018-05-11 11:43:06 -04:00
|
|
|
{
|
|
|
|
gimp_parallel_run_async_set_n_threads (n_threads);
|
|
|
|
gimp_parallel_distribute_set_n_threads (n_threads);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_parallel_run_async_set_n_threads (gint n_threads)
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
n_threads = CLAMP (n_threads, 0, GIMP_PARALLEL_RUN_ASYNC_MAX_THREADS);
|
|
|
|
|
|
|
|
if (n_threads > gimp_parallel_run_async_n_threads) /* need more threads */
|
|
|
|
{
|
|
|
|
for (i = gimp_parallel_run_async_n_threads; i < n_threads; i++)
|
|
|
|
{
|
|
|
|
GimpParallelRunAsyncThread *thread =
|
|
|
|
&gimp_parallel_run_async_threads[i];
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
thread->quit = FALSE;
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
thread->thread = g_thread_new (
|
|
|
|
"async",
|
|
|
|
(GThreadFunc) gimp_parallel_run_async_thread_func,
|
|
|
|
thread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (n_threads < gimp_parallel_run_async_n_threads) /* need less threads */
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
g_mutex_lock (&gimp_parallel_run_async_mutex);
|
|
|
|
|
|
|
|
for (i = n_threads; i < gimp_parallel_run_async_n_threads; i++)
|
|
|
|
{
|
|
|
|
GimpParallelRunAsyncThread *thread =
|
|
|
|
&gimp_parallel_run_async_threads[i];
|
|
|
|
|
|
|
|
thread->quit = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_cond_broadcast (&gimp_parallel_run_async_cond);
|
|
|
|
|
|
|
|
g_mutex_unlock (&gimp_parallel_run_async_mutex);
|
|
|
|
|
|
|
|
for (i = n_threads; i < gimp_parallel_run_async_n_threads; i++)
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
GimpParallelRunAsyncThread *thread =
|
|
|
|
&gimp_parallel_run_async_threads[i];
|
|
|
|
|
|
|
|
g_thread_join (thread->thread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_parallel_run_async_n_threads = n_threads;
|
|
|
|
}
|
2018-07-01 13:28:06 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
static gpointer
|
|
|
|
gimp_parallel_run_async_thread_func (GimpParallelRunAsyncThread *thread)
|
|
|
|
{
|
|
|
|
g_mutex_lock (&gimp_parallel_run_async_mutex);
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
GimpParallelRunAsyncTask *task;
|
|
|
|
|
2018-07-01 13:28:06 -04:00
|
|
|
while (! thread->quit &&
|
|
|
|
(task =
|
|
|
|
(GimpParallelRunAsyncTask *) g_queue_pop_head (
|
|
|
|
&gimp_parallel_run_async_queue)))
|
2018-05-11 11:43:06 -04:00
|
|
|
{
|
2018-05-27 12:55:16 -04:00
|
|
|
g_object_set_data (G_OBJECT (task->async),
|
|
|
|
"gimp-parallel-run-async-link", NULL);
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
g_mutex_unlock (&gimp_parallel_run_async_mutex);
|
|
|
|
|
|
|
|
gimp_parallel_run_async_execute_task (task);
|
|
|
|
|
|
|
|
g_mutex_lock (&gimp_parallel_run_async_mutex);
|
|
|
|
}
|
|
|
|
|
2018-07-01 13:28:06 -04:00
|
|
|
if (thread->quit)
|
|
|
|
break;
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
g_cond_wait (&gimp_parallel_run_async_cond,
|
|
|
|
&gimp_parallel_run_async_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&gimp_parallel_run_async_mutex);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_parallel_run_async_execute_task (GimpParallelRunAsyncTask *task)
|
|
|
|
{
|
|
|
|
task->func (task->async, task->user_data);
|
|
|
|
|
|
|
|
if (! gimp_async_is_stopped (task->async))
|
|
|
|
gimp_async_abort (task->async);
|
|
|
|
|
|
|
|
g_object_unref (task->async);
|
|
|
|
|
|
|
|
g_slice_free (GimpParallelRunAsyncTask, task);
|
|
|
|
}
|
|
|
|
|
2018-05-27 12:55:16 -04:00
|
|
|
static void
|
|
|
|
gimp_parallel_run_async_cancel (GimpAsync *async)
|
|
|
|
{
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
GList *link;
|
|
|
|
GimpParallelRunAsyncTask *task = NULL;
|
2018-05-27 12:55:16 -04:00
|
|
|
|
|
|
|
g_mutex_lock (&gimp_parallel_run_async_mutex);
|
|
|
|
|
|
|
|
link = (GList *) g_object_get_data (G_OBJECT (async),
|
|
|
|
"gimp-parallel-run-async-link");
|
|
|
|
|
|
|
|
if (link)
|
|
|
|
{
|
2018-05-27 13:53:02 -04:00
|
|
|
g_object_set_data (G_OBJECT (async),
|
|
|
|
"gimp-parallel-run-async-link", NULL);
|
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
task = (GimpParallelRunAsyncTask *) link->data;
|
2018-05-27 12:55:16 -04:00
|
|
|
|
|
|
|
g_queue_delete_link (&gimp_parallel_run_async_queue, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&gimp_parallel_run_async_mutex);
|
|
|
|
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
if (task)
|
2018-05-27 12:55:16 -04:00
|
|
|
{
|
app: add gimp_parallel_run_async_{full,independent}()
Remove the "independent" parameter of gimp_parallel_run_async(),
and have the function always execute the passed callback in the
shared async thread-pool.
Add a new gimp_parallel_run_async_full() function, taking, in
addition to a callback and a data pointer:
- A priority value, controlling the priority of the callback in
the async thread-pool queue. 0 is the default priority (used
by gimp_parallel_run_async()), negative values have higher
priority, and positive values have lower priority.
- A destructor function for the data pointer. This function is
called to free the user data in case the async operation is
canceled before execution of the callback function begins, and
the operation is dropped from the queue and aborted without
executing the callback. Note that if the callback *is*
executed, the destructor is *not* used -- it's the callback's
responsibility to free/recycle the user data.
Add a separate gimp_parallel_run_async_independent() function,
taking the same parameters, and executing the passed callback in
an independent thread, rather than the thread pool. This function
doesn't take a priority value or a destructor (and there's no
corresponding "_full()" variant that does), since they're pointless
for independent threads.
Adapt the rest of the code to the changes.
2018-07-01 09:57:46 -04:00
|
|
|
if (task->user_data && task->user_data_destroy_func)
|
|
|
|
task->user_data_destroy_func (task->user_data);
|
|
|
|
|
|
|
|
g_slice_free (GimpParallelRunAsyncTask, task);
|
|
|
|
|
2018-05-27 12:55:16 -04:00
|
|
|
gimp_async_abort (async);
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
static void
|
|
|
|
gimp_parallel_distribute_set_n_threads (gint n_threads)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (! g_atomic_int_compare_and_exchange (&gimp_parallel_distribute_busy,
|
|
|
|
0, 1))
|
|
|
|
{
|
|
|
|
g_return_if_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
n_threads = CLAMP (n_threads, 1, GIMP_PARALLEL_DISTRIBUTE_MAX_THREADS);
|
|
|
|
|
|
|
|
if (n_threads > gimp_parallel_distribute_n_threads) /* need more threads */
|
|
|
|
{
|
|
|
|
for (i = gimp_parallel_distribute_n_threads - 1; i < n_threads - 1; i++)
|
|
|
|
{
|
|
|
|
GimpParallelDistributeThread *thread =
|
|
|
|
&gimp_parallel_distribute_threads[i];
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
thread->quit = FALSE;
|
|
|
|
thread->task = NULL;
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
thread->thread = g_thread_new (
|
|
|
|
"worker",
|
|
|
|
(GThreadFunc) gimp_parallel_distribute_thread_func,
|
|
|
|
thread);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
}
|
|
|
|
}
|
2018-05-11 11:43:06 -04:00
|
|
|
else if (n_threads < gimp_parallel_distribute_n_threads) /* need less threads */
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
for (i = n_threads - 1; i < gimp_parallel_distribute_n_threads - 1; i++)
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
GimpParallelDistributeThread *thread =
|
|
|
|
&gimp_parallel_distribute_threads[i];
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
g_mutex_lock (&thread->mutex);
|
|
|
|
|
|
|
|
thread->quit = TRUE;
|
|
|
|
g_cond_signal (&thread->cond);
|
|
|
|
|
|
|
|
g_mutex_unlock (&thread->mutex);
|
|
|
|
}
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
for (i = n_threads - 1; i < gimp_parallel_distribute_n_threads - 1; i++)
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
GimpParallelDistributeThread *thread =
|
|
|
|
&gimp_parallel_distribute_threads[i];
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
|
|
|
g_thread_join (thread->thread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
gimp_parallel_distribute_n_threads = n_threads;
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
g_atomic_int_set (&gimp_parallel_distribute_busy, 0);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
2018-05-11 11:43:06 -04:00
|
|
|
gimp_parallel_distribute_thread_func (GimpParallelDistributeThread *thread)
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
|
|
|
g_mutex_lock (&thread->mutex);
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
if (thread->quit)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (thread->task)
|
|
|
|
{
|
|
|
|
thread->task->func (thread->i, thread->task->n,
|
|
|
|
thread->task->user_data);
|
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
if (g_atomic_int_dec_and_test (
|
|
|
|
&gimp_parallel_distribute_completion_counter))
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
{
|
2018-05-11 11:43:06 -04:00
|
|
|
g_mutex_lock (&gimp_parallel_distribute_completion_mutex);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
g_cond_signal (&gimp_parallel_distribute_completion_cond);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
|
2018-05-11 11:43:06 -04:00
|
|
|
g_mutex_unlock (&gimp_parallel_distribute_completion_mutex);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
thread->task = NULL;
|
|
|
|
}
|
2018-05-11 11:43:06 -04:00
|
|
|
|
|
|
|
g_cond_wait (&thread->cond, &thread->mutex);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-04 15:16:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&thread->mutex);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* extern "C" */
|