thread-pool: Unref reused threads in gst_rtsp_thread_stop()
authorOgnyan Tonchev <ognyan@axis.com>
Fri, 31 Jan 2014 14:02:22 +0000 (15:02 +0100)
committerWim Taymans <wtaymans@redhat.com>
Tue, 4 Feb 2014 13:47:49 +0000 (14:47 +0100)
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=723519

gst/rtsp-server/rtsp-thread-pool.c
tests/check/gst/threadpool.c

index 0a12fd1..789d8ff 100644 (file)
@@ -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");
index 735584a..4c6ca79 100644 (file)
@@ -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);