srt: Use simpler list operations for callers

Avoid `g_list_append` and `g_list_remove` (which have to scan the list)
and replace them with `g_list_prepend` and `g_list_delete_link`.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3329>
This commit is contained in:
Jan Alexander Steffens (heftig) 2022-07-29 11:53:18 +02:00 committed by Tim-Philipp Müller
parent 68cd5e1de1
commit 253a5cc125

View file

@ -973,7 +973,7 @@ thread_func (gpointer data)
caller->sock);
g_mutex_lock (&srtobject->sock_lock);
srtobject->callers = g_list_append (srtobject->callers, caller);
srtobject->callers = g_list_prepend (srtobject->callers, caller);
g_cond_signal (&srtobject->sock_cond);
g_mutex_unlock (&srtobject->sock_lock);
@ -1661,18 +1661,17 @@ gst_srt_object_write_to_callers (GstSRTObject * srtobject,
GstBufferList * headers,
const GstMapInfo * mapinfo, GCancellable * cancellable)
{
GList *callers;
GList *item, *next;
g_mutex_lock (&srtobject->sock_lock);
callers = srtobject->callers;
while (callers != NULL) {
for (item = srtobject->callers, next = NULL; item; item = next) {
SRTCaller *caller = item->data;
gssize len = 0;
const guint8 *msg = mapinfo->data;
gint sent;
gint payload_size, optlen = sizeof (payload_size);
SRTCaller *caller = callers->data;
callers = callers->next;
next = item->next;
if (g_cancellable_is_cancelled (cancellable)) {
goto cancelled;
@ -1714,7 +1713,7 @@ gst_srt_object_write_to_callers (GstSRTObject * srtobject,
continue;
err:
srtobject->callers = g_list_remove (srtobject->callers, caller);
srtobject->callers = g_list_delete_link (srtobject->callers, item);
srt_caller_signal_removed (caller, srtobject);
srt_caller_free (caller);
}