summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@blame.services>2024-03-01 15:28:48 +0100
committerDave Davenport <qball@blame.services>2024-03-01 15:28:48 +0100
commit8061e4e7c2856c4e37e91072c0462ef9cd2e2db4 (patch)
treeee3fd5eb515343acb067d5dd3e7ea51152dc61b3
parent42d6bb9af4aafa8d7147191fcc887d15c0ab46a4 (diff)
Add an item-free method to the thread-pool
-rw-r--r--include/rofi-types.h1
-rw-r--r--source/rofi-icon-fetcher.c5
-rw-r--r--source/view.c15
3 files changed, 18 insertions, 3 deletions
diff --git a/include/rofi-types.h b/include/rofi-types.h
index 4fdb3e37..9ca29f56 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);
+ void (*free)(void *);
int priority;
} thread_state;
diff --git a/source/rofi-icon-fetcher.c b/source/rofi-icon-fetcher.c
index e3d6f4dd..397e06fd 100644
--- a/source/rofi-icon-fetcher.c
+++ b/source/rofi-icon-fetcher.c
@@ -86,6 +86,8 @@ typedef struct {
IconFetcherNameEntry *entry;
} IconFetcherEntry;
+// Free method.
+static void rofi_icon_fetch_entry_free(gpointer data);
/**
* The icon fetcher internal state.
*/
@@ -361,7 +363,7 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
icon_path, sentry->wsize, sentry->hsize, TRUE, &error);
if (error != NULL) {
g_warning("Failed to load image: |%s| %d %d %s (%p)", icon_path,
- sentry->wsize, sentry->hsize, error->message, (void*)pb);
+ sentry->wsize, sentry->hsize, error->message, (void *)pb);
g_error_free(error);
if (pb) {
g_object_unref(pb);
@@ -411,6 +413,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.free = rofi_icon_fetch_entry_free;
sentry->state.priority = G_PRIORITY_LOW;
g_thread_pool_push(tpool, sentry, NULL);
diff --git a/source/view.c b/source/view.c
index 81787a1d..3e463a67 100644
--- a/source/view.c
+++ b/source/view.c
@@ -1460,6 +1460,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.free = NULL;
states[i].st.priority = G_PRIORITY_HIGH;
if (i > 0) {
g_thread_pool_push(tpool, &states[i], NULL);
@@ -2650,6 +2651,15 @@ static int rofi_thread_workers_sort(gconstpointer a, gconstpointer b,
return tsa->priority - tsb->priority;
}
+static void rofi_thread_pool_state_free(gpointer data) {
+ if (data) {
+ thread_state *ts = (thread_state *)data;
+ if (ts->free) {
+ ts->free(data);
+ }
+ }
+}
+
void rofi_view_workers_initialize(void) {
TICK_N("Setup Threadpool, start");
if (config.threads == 0) {
@@ -2661,8 +2671,9 @@ void rofi_view_workers_initialize(void) {
}
// Create thread pool
GError *error = NULL;
- tpool = g_thread_pool_new(rofi_view_call_thread, NULL, config.threads, FALSE,
- &error);
+ tpool = g_thread_pool_new_full(rofi_view_call_thread, NULL,
+ rofi_thread_pool_state_free, config.threads,
+ FALSE, &error);
if (error == NULL) {
// Idle threads should stick around for a max of 60 seconds.
g_thread_pool_set_max_idle_time(60000);