[glib] GThreadPool: Add some queue manipulation api
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GThreadPool: Add some queue manipulation api
- Date: Mon, 29 Jun 2015 15:21:25 +0000 (UTC)
commit 9486f697bb3ed3b02fa2c82f50662fde7d77267e
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jun 29 08:19:31 2015 -0700
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
docs/reference/glib/glib-sections.txt | 1 +
glib/gthreadpool.c | 30 ++++++++++++++++++++++++++++++
glib/gthreadpool.h | 4 ++++
3 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 5e783e8..880dab6 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
</SECTION>
<SECTION>
diff --git a/glib/gthreadpool.c b/glib/gthreadpool.c
index dad424d..725f627 100644
--- a/glib/gthreadpool.c
+++ b/glib/gthreadpool.c
@@ -963,6 +963,36 @@ g_thread_pool_set_sort_function (GThreadPool *pool,
}
/**
+ * 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)
* a thread can be idle
diff --git a/glib/gthreadpool.h b/glib/gthreadpool.h
index b46987d..95c10a0 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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]