gst/gstthread.c: Make sure no iteration happens while performing the state change...
authorWim Taymans <wim.taymans@gmail.com>
Thu, 7 Oct 2004 18:34:57 +0000 (18:34 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Thu, 7 Oct 2004 18:34:57 +0000 (18:34 +0000)
Original commit message from CVS:
* gst/gstthread.c: (gst_thread_change_state),
(gst_thread_child_state_change):
Make sure no iteration happens while performing
the state change as it could mess up the internal
consistency of the thread state.

ChangeLog
gst/gstthread.c

index 3b85b80..bddb5e3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2004-10-07  Wim Taymans  <wim at fluendo dot com>
 
+       * gst/gstthread.c: (gst_thread_change_state),
+       (gst_thread_child_state_change):
+       Make sure no iteration happens while performing
+       the state change as it could mess up the internal
+       consistency of the thread state.
+
+2004-10-07  Wim Taymans  <wim at fluendo dot com>
+
        * gst/gstthread.c: (gst_thread_dispose), (gst_thread_sync),
        (gst_thread_change_state), (gst_thread_child_state_change):
        Do not try to grab the iterate lock in the state change method
index 48578c4..29e36de 100644 (file)
@@ -445,8 +445,6 @@ gst_thread_change_state (GstElement * element)
       gst_element_state_get_name (GST_STATE (element)),
       gst_element_state_get_name (GST_STATE_PENDING (element)));
 
-  transition = GST_STATE_TRANSITION (element);
-
   thread = GST_THREAD (element);
 
   /* boolean to check if we called the state change in the same thread as
@@ -458,12 +456,15 @@ gst_thread_change_state (GstElement * element)
 
   gst_thread_sync (thread, is_self);
 
-  /* FIXME: (or GStreamers ideas about "threading"): the element variables are
-     commonly accessed by multiple threads at the same time (see bug #111146
-     for an example) */
-  if (transition != GST_STATE_TRANSITION (element)) {
-    g_warning ("inconsistent state information, fix threading please");
-  }
+  /* no iteration is allowed during this state change because an iteration
+   * can cause another state change conflicting with this one */
+  /* do not try to grab the lock if this method is called from the
+   * same thread as the iterate thread, the lock might be held and we 
+   * might deadlock */
+  if (!is_self)
+    g_mutex_lock (thread->iterate_lock);
+
+  transition = GST_STATE_TRANSITION (element);
 
   switch (transition) {
     case GST_STATE_NULL_TO_READY:
@@ -560,11 +561,6 @@ gst_thread_change_state (GstElement * element)
   GST_LOG_OBJECT (thread, "unlocking lock");
   g_mutex_unlock (thread->lock);
 
-  /* do not try to grab the lock if this method is called from the
-   * same thread as the iterate thread, the lock might be held and we 
-   * might deadlock */
-  if (!is_self)
-    g_mutex_lock (thread->iterate_lock);
   if (GST_ELEMENT_CLASS (parent_class)->change_state) {
     ret = GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT (thread));
   } else {
@@ -583,6 +579,9 @@ error_out:
 
   g_mutex_unlock (thread->lock);
 
+  if (!is_self)
+    g_mutex_unlock (thread->iterate_lock);
+
   return GST_STATE_FAILURE;
 }