From: Ognyan Tonchev Date: Fri, 31 Jan 2014 14:02:22 +0000 (+0100) Subject: thread-pool: Unref reused threads in gst_rtsp_thread_stop() X-Git-Tag: 1.6.0~275 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=274d4b017fe4967b616e67f8dfe40fb30bfb053e;p=platform%2Fupstream%2Fgst-rtsp-server.git thread-pool: Unref reused threads in gst_rtsp_thread_stop() Fixes https://bugzilla.gnome.org/show_bug.cgi?id=723519 --- diff --git a/gst/rtsp-server/rtsp-thread-pool.c b/gst/rtsp-server/rtsp-thread-pool.c index 0a12fd1..789d8ff 100644 --- a/gst/rtsp-server/rtsp-thread-pool.c +++ b/gst/rtsp-server/rtsp-thread-pool.c @@ -133,12 +133,17 @@ gboolean gst_rtsp_thread_reuse (GstRTSPThread * thread) { GstRTSPThreadImpl *impl = (GstRTSPThreadImpl *) thread; + gboolean res; g_return_val_if_fail (GST_IS_RTSP_THREAD (thread), FALSE); GST_DEBUG ("reuse thread %p", thread); - return g_atomic_int_add (&impl->reused, 1) > 0; + res = g_atomic_int_add (&impl->reused, 1) > 0; + if (res) + gst_rtsp_thread_ref (thread); + + return res; } static gboolean @@ -174,7 +179,8 @@ gst_rtsp_thread_stop (GstRTSPThread * thread) thread, (GDestroyNotify) gst_rtsp_thread_unref); g_source_attach (source, thread->context); g_source_unref (source); - } + } else + gst_rtsp_thread_unref (thread); } #define GST_RTSP_THREAD_POOL_GET_PRIVATE(obj) \ @@ -458,7 +464,6 @@ default_get_thread (GstRTSPThreadPool * pool, * stops. */ goto retry; } - gst_rtsp_thread_ref (thread); } else { /* make more threads */ GST_DEBUG_OBJECT (pool, "make new client thread"); diff --git a/tests/check/gst/threadpool.c b/tests/check/gst/threadpool.c index 735584a..4c6ca79 100644 --- a/tests/check/gst/threadpool.c +++ b/tests/check/gst/threadpool.c @@ -34,6 +34,8 @@ GST_START_TEST (test_pool_get_thread) thread = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, NULL); fail_unless (thread != NULL); + /* one ref is hold by the pool */ + fail_unless (GST_MINI_OBJECT_REFCOUNT (thread) == 2); gst_rtsp_thread_stop (thread); g_object_unref (pool); @@ -62,6 +64,8 @@ GST_START_TEST (test_pool_get_thread_reuse) fail_unless (thread2 != NULL); fail_unless (thread == thread2); + /* one ref is hold by the pool */ + fail_unless (GST_MINI_OBJECT_REFCOUNT (thread) == 3); gst_rtsp_thread_stop (thread); gst_rtsp_thread_stop (thread2);