GThreadPool: Add some queue manipulation api

GTask has a need for an api that boosts an unprocessed
item to the front of the queue, so add one.

https://bugzilla.gnome.org/show_bug.cgi?id=751160
This commit is contained in:
Matthias Clasen 2015-06-29 08:19:31 -07:00
parent 26d8792710
commit 9486f697bb
3 changed files with 35 additions and 0 deletions

View File

@ -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
</SECTION>
<SECTION>

View File

@ -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)

View File

@ -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,