thread-pool: Unref source after mainloop has quit to avoid races in GLib

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=723741
This commit is contained in:
Ognyan Tonchev 2014-02-06 09:03:50 +01:00 committed by Wim Taymans
parent 9048d87ff4
commit b1845b0864

View file

@ -56,6 +56,7 @@ typedef struct _GstRTSPThreadImpl
GstRTSPThread thread;
gint reused;
GSource *source;
} GstRTSPThreadImpl;
GST_DEFINE_MINI_OBJECT_TYPE (GstRTSPThread, gst_rtsp_thread);
@ -67,6 +68,7 @@ _gst_rtsp_thread_free (GstRTSPThreadImpl * impl)
{
GST_DEBUG ("free thread %p", impl);
g_source_unref (impl->source);
g_main_loop_unref (impl->thread.loop);
g_main_context_unref (impl->thread.context);
g_slice_free1 (sizeof (GstRTSPThreadImpl), impl);
@ -171,14 +173,11 @@ gst_rtsp_thread_stop (GstRTSPThread * thread)
GST_DEBUG ("stop thread %p", thread);
if (g_atomic_int_dec_and_test (&impl->reused)) {
GSource *source;
GST_DEBUG ("add idle source to quit mainloop of thread %p", thread);
source = g_idle_source_new ();
g_source_set_callback (source, (GSourceFunc) do_quit,
impl->source = g_idle_source_new ();
g_source_set_callback (impl->source, (GSourceFunc) do_quit,
thread, (GDestroyNotify) gst_rtsp_thread_unref);
g_source_attach (source, thread->context);
g_source_unref (source);
g_source_attach (impl->source, thread->context);
} else
gst_rtsp_thread_unref (thread);
}