mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-10 12:40:10 +00:00
paralleltask: Let callers limit parallelism
Add a max_tasks argument to gdk_parallel_task_run. This will help reduce setup overhead in small cases. For now, all callers pass G_MAXUINT.
This commit is contained in:
parent
9da684c914
commit
3f798a2017
@ -2267,7 +2267,7 @@ gdk_memory_convert (guchar *dest_data,
|
||||
return;
|
||||
}
|
||||
|
||||
gdk_parallel_task_run (gdk_memory_convert_generic, &mc);
|
||||
gdk_parallel_task_run (gdk_memory_convert_generic, &mc, G_MAXUINT);
|
||||
}
|
||||
|
||||
typedef struct _MemoryConvertColorState MemoryConvertColorState;
|
||||
@ -2512,17 +2512,17 @@ gdk_memory_convert_color_state (guchar *data,
|
||||
src_color_state == GDK_COLOR_STATE_SRGB &&
|
||||
dest_color_state == GDK_COLOR_STATE_SRGB_LINEAR)
|
||||
{
|
||||
gdk_parallel_task_run (gdk_memory_convert_color_state_srgb_to_srgb_linear, &mc);
|
||||
gdk_parallel_task_run (gdk_memory_convert_color_state_srgb_to_srgb_linear, &mc, G_MAXUINT);
|
||||
}
|
||||
else if (format == GDK_MEMORY_B8G8R8A8_PREMULTIPLIED &&
|
||||
src_color_state == GDK_COLOR_STATE_SRGB_LINEAR &&
|
||||
dest_color_state == GDK_COLOR_STATE_SRGB)
|
||||
{
|
||||
gdk_parallel_task_run (gdk_memory_convert_color_state_srgb_linear_to_srgb, &mc);
|
||||
gdk_parallel_task_run (gdk_memory_convert_color_state_srgb_linear_to_srgb, &mc, G_MAXUINT);
|
||||
}
|
||||
else
|
||||
{
|
||||
gdk_parallel_task_run (gdk_memory_convert_color_state_generic, &mc);
|
||||
gdk_parallel_task_run (gdk_memory_convert_color_state_generic, &mc, G_MAXUINT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2684,13 +2684,13 @@ gdk_memory_mipmap (guchar *dest,
|
||||
if (dest_format == src_format)
|
||||
{
|
||||
if (linear)
|
||||
gdk_parallel_task_run (gdk_memory_mipmap_same_format_linear, &mipmap);
|
||||
gdk_parallel_task_run (gdk_memory_mipmap_same_format_linear, &mipmap, G_MAXUINT);
|
||||
else
|
||||
gdk_parallel_task_run (gdk_memory_mipmap_same_format_nearest, &mipmap);
|
||||
gdk_parallel_task_run (gdk_memory_mipmap_same_format_nearest, &mipmap, G_MAXUINT);
|
||||
}
|
||||
else
|
||||
{
|
||||
gdk_parallel_task_run (gdk_memory_mipmap_generic, &mipmap);
|
||||
gdk_parallel_task_run (gdk_memory_mipmap_generic, &mipmap, G_MAXUINT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,13 +46,15 @@ gdk_parallel_task_thread_func (gpointer data,
|
||||
* gdk_parallel_task_run:
|
||||
* @task_func: the function to spawn
|
||||
* @task_data: data to pass to the function
|
||||
* @max_tasks: maximum number of tasks to spawn
|
||||
*
|
||||
* Spawns the given function in many threads.
|
||||
* Once all functions have exited, this function returns.
|
||||
**/
|
||||
void
|
||||
gdk_parallel_task_run (GdkTaskFunc task_func,
|
||||
gpointer task_data)
|
||||
gpointer task_data,
|
||||
guint max_tasks)
|
||||
{
|
||||
static GThreadPool *pool;
|
||||
TaskData task = {
|
||||
@ -61,7 +63,7 @@ gdk_parallel_task_run (GdkTaskFunc task_func,
|
||||
};
|
||||
int i, n_tasks;
|
||||
|
||||
if (!gdk_has_feature (GDK_FEATURE_THREADS))
|
||||
if (max_tasks == 1 || !gdk_has_feature (GDK_FEATURE_THREADS))
|
||||
{
|
||||
task_func (task_data);
|
||||
return;
|
||||
@ -79,7 +81,7 @@ gdk_parallel_task_run (GdkTaskFunc task_func,
|
||||
g_once_init_leave (&pool, the_pool);
|
||||
}
|
||||
|
||||
n_tasks = g_get_num_processors ();
|
||||
n_tasks = MIN (max_tasks, g_get_num_processors ());
|
||||
task.n_running_tasks = n_tasks;
|
||||
/* Start with 1 because we run 1 task ourselves */
|
||||
for (i = 1; i < n_tasks; i++)
|
||||
|
@ -26,7 +26,8 @@ G_BEGIN_DECLS
|
||||
typedef void (* GdkTaskFunc) (gpointer user_data);
|
||||
|
||||
void gdk_parallel_task_run (GdkTaskFunc task_func,
|
||||
gpointer task_data);
|
||||
gpointer task_data,
|
||||
guint max_tasks);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user