gwakeup: Reduce wake-ups to only first item in queue

We only need to wake up the other side of the GAsyncQueue if we transition
from 0 to 1 item in the queue. Otherwise, we can be certain that the other
side has received a wakeup and will eventually flush the queue.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4007>
This commit is contained in:
Christian Hergert 2024-09-05 15:06:53 -07:00 committed by Marge Bot
parent 18eb1be491
commit 1247452d19
2 changed files with 10 additions and 4 deletions

View File

@ -1000,8 +1000,11 @@ _clutter_event_push (const ClutterEvent *event,
event = copy; event = copy;
} }
g_async_queue_push (context->events_queue, (gpointer) event); g_async_queue_lock (context->events_queue);
g_async_queue_push_unlocked (context->events_queue, (gpointer) event);
if (g_async_queue_length_unlocked (context->events_queue) == 1)
g_main_context_wakeup (NULL); g_main_context_wakeup (NULL);
g_async_queue_unlock (context->events_queue);
} }
/** /**

View File

@ -599,8 +599,11 @@ meta_thread_impl_queue_task (MetaThreadImpl *thread_impl,
MetaThreadImplPrivate *priv = MetaThreadImplPrivate *priv =
meta_thread_impl_get_instance_private (thread_impl); meta_thread_impl_get_instance_private (thread_impl);
g_async_queue_push (priv->task_queue, task); g_async_queue_lock (priv->task_queue);
g_async_queue_push_unlocked (priv->task_queue, task);
if (g_async_queue_length_unlocked (priv->task_queue) == 1)
g_main_context_wakeup (priv->thread_context); g_main_context_wakeup (priv->thread_context);
g_async_queue_unlock (priv->task_queue);
} }
gboolean gboolean