diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 5e783e8a0..880dab614 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -827,6 +827,7 @@ g_thread_pool_stop_unused_threads g_thread_pool_set_sort_function g_thread_pool_set_max_idle_time g_thread_pool_get_max_idle_time +g_thread_pool_move_to_front
diff --git a/glib/gthreadpool.c b/glib/gthreadpool.c index dad424dca..725f62733 100644 --- a/glib/gthreadpool.c +++ b/glib/gthreadpool.c @@ -962,6 +962,36 @@ g_thread_pool_set_sort_function (GThreadPool *pool, g_async_queue_unlock (real->queue); } +/** + * g_thread_pool_move_to_front: + * @pool: a #GThreadPool + * @data: an unprocessed item in the pool + * + * Moves the item to the front of the queue of unprocessed + * items, so that it will be processed next. + * + * Returns: %TRUE if the item was found and moved + * + * Since: 2.46 + */ +gboolean +g_thread_pool_move_to_front (GThreadPool *pool, + gpointer data) +{ + GRealThreadPool *real = (GRealThreadPool*) pool; + gboolean found; + + g_async_queue_lock (real->queue); + + found = g_async_queue_remove_unlocked (real->queue, data); + if (found) + g_async_queue_push_front_unlocked (real->queue, data); + + g_async_queue_unlock (real->queue); + + return found; +} + /** * g_thread_pool_set_max_idle_time: * @interval: the maximum @interval (in milliseconds) diff --git a/glib/gthreadpool.h b/glib/gthreadpool.h index b46987d76..95c10a0fd 100644 --- a/glib/gthreadpool.h +++ b/glib/gthreadpool.h @@ -65,6 +65,10 @@ GLIB_AVAILABLE_IN_ALL void g_thread_pool_set_sort_function (GThreadPool *pool, GCompareDataFunc func, gpointer user_data); +GLIB_AVAILABLE_IN_2_46 +gboolean g_thread_pool_move_to_front (GThreadPool *pool, + gpointer data); + GLIB_AVAILABLE_IN_ALL gboolean g_thread_pool_set_max_threads (GThreadPool *pool, gint max_threads,