thread: Allow passing a NULL callback vfunc

This is useful when one just wants to free something, which can be done
using the passed destroy notify function.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
This commit is contained in:
Jonas Ådahl 2022-12-21 18:01:23 +01:00
parent 0d5d1745ce
commit 6ed75c6253

View File

@ -913,6 +913,12 @@ meta_thread_unregister_callback_context (MetaThread *thread,
g_hash_table_remove (priv->callback_sources, main_context);
}
static void
no_op_callback (MetaThread *thread,
gpointer user_data)
{
}
void
meta_thread_queue_callback (MetaThread *thread,
GMainContext *main_context,
@ -935,7 +941,7 @@ meta_thread_queue_callback (MetaThread *thread,
callback_data = g_new0 (MetaThreadCallbackData, 1);
*callback_data = (MetaThreadCallbackData) {
.callback = callback,
.callback = callback ? callback : no_op_callback,
.user_data = user_data,
.user_data_destroy = user_data_destroy,
};