summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQball Cow <qball@blame.services>2024-02-11 13:59:11 +0100
committerQball Cow <qball@blame.services>2024-02-11 14:00:03 +0100
commit13c2a617666d5ee054fee2bba6abc3ce6a557570 (patch)
tree84ccfd80e96645fa716439a79299fe9e3a0f2df2
parent3dc3e2d6164ab4a8720d044575a09d43f06eab0d (diff)
[ThreadPool] Sort items in the queue based on priority
-rw-r--r--include/rofi-types.h1
-rw-r--r--source/rofi-icon-fetcher.c2
-rw-r--r--source/view.c11
3 files changed, 14 insertions, 0 deletions
diff --git a/include/rofi-types.h b/include/rofi-types.h
index 4fc878d4..4fdb3e37 100644
--- a/include/rofi-types.h
+++ b/include/rofi-types.h
@@ -370,6 +370,7 @@ typedef struct rofi_int_matcher_t {
*/
typedef struct _thread_state {
void (*callback)(struct _thread_state *t, gpointer data);
+ int priority;
} thread_state;
extern GThreadPool *tpool;
diff --git a/source/rofi-icon-fetcher.c b/source/rofi-icon-fetcher.c
index c65463ae..c2bb0f1f 100644
--- a/source/rofi-icon-fetcher.c
+++ b/source/rofi-icon-fetcher.c
@@ -411,6 +411,7 @@ uint32_t rofi_icon_fetcher_query_advanced(const char *name, const int wsize,
// Push into fetching queue.
sentry->state.callback = rofi_icon_fetcher_worker;
+ sentry->state.priority = G_PRIORITY_LOW;
g_thread_pool_push(tpool, sentry, NULL);
return sentry->uid;
@@ -447,6 +448,7 @@ uint32_t rofi_icon_fetcher_query(const char *name, const int size) {
// Push into fetching queue.
sentry->state.callback = rofi_icon_fetcher_worker;
+ sentry->state.priority = G_PRIORITY_LOW;
g_thread_pool_push(tpool, sentry, NULL);
return sentry->uid;
diff --git a/source/view.c b/source/view.c
index 4b32cb8e..29ca2307 100644
--- a/source/view.c
+++ b/source/view.c
@@ -1444,6 +1444,7 @@ static gboolean rofi_view_refilter_real(RofiViewState *state) {
states[i].plen = plen;
states[i].pattern = pattern;
states[i].st.callback = filter_elements;
+ states[i].st.priority = G_PRIORITY_HIGH;
if (i > 0) {
g_thread_pool_push(tpool, &states[i], NULL);
}
@@ -2624,6 +2625,15 @@ void rofi_view_cleanup() {
input_history_save();
}
+
+static int rofi_thread_workers_sort(gconstpointer a,gconstpointer b, gpointer data G_GNUC_UNUSED)
+{
+ thread_state *tsa = (thread_state *)a;
+ thread_state *tsb = (thread_state *)b;
+ // lower number is lower priority.. a is sorted above is a > b.
+ return tsa->priority-tsb->priority;
+}
+
void rofi_view_workers_initialize(void) {
TICK_N("Setup Threadpool, start");
if (config.threads == 0) {
@@ -2649,6 +2659,7 @@ void rofi_view_workers_initialize(void) {
g_error_free(error);
exit(EXIT_FAILURE);
}
+ g_thread_pool_set_sort_function(tpool, rofi_thread_workers_sort, NULL);
TICK_N("Setup Threadpool, done");
}
void rofi_view_workers_finalize(void) {