Never destroy the current cothread.
authorWim Taymans <wim.taymans@gmail.com>
Sat, 22 Dec 2001 23:19:17 +0000 (23:19 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Sat, 22 Dec 2001 23:19:17 +0000 (23:19 +0000)
Original commit message from CVS:
Never destroy the current cothread.
Don't try to signal the scheduler if we don't have one

gst/cothreads.c
gst/gstelement.c
gst/gstelement.h
gst/gsttypefind.c

index f9b668e..f88eaef 100644 (file)
@@ -162,7 +162,8 @@ cothread_create (cothread_context *ctx)
   for (slot = 1; slot < ctx->nthreads; slot++) {
     if (ctx->threads[slot] == NULL)
       break;
-    else if (ctx->threads[slot]->flags & COTHREAD_DESTROYED) {
+    else if (ctx->threads[slot]->flags & COTHREAD_DESTROYED &&
+                   slot != ctx->current) {
       cothread_destroy (ctx->threads[slot]);
       break;
     }
@@ -217,7 +218,7 @@ cothread_free (cothread_state *thread)
 {
   g_return_if_fail (thread != NULL);
 
-  GST_INFO (GST_CAT_COTHREADS, "flag cothread for destruction");
+  GST_INFO (GST_CAT_COTHREADS, "flag cothread %d for destruction", thread->threadnum);
 
   /* we simply flag the cothread for destruction here */
   thread->flags |= COTHREAD_DESTROYED;
@@ -230,10 +231,11 @@ cothread_destroy (cothread_state *thread)
 
   g_return_if_fail (thread != NULL);
 
-  GST_INFO (GST_CAT_COTHREADS, "destroy cothread");
+  GST_INFO (GST_CAT_COTHREADS, "destroy cothread %d %p %p", thread->threadnum, thread, ctx->current);
 
   ctx = thread->ctx;
 #ifndef COTHREAD_ATOMIC
+  g_mutex_unlock (thread->lock);
   g_mutex_free (thread->lock);
 #endif
   //munmap ((void *) thread, COTHREAD_STACKSIZE);
index fd0b3c2..862891c 100644 (file)
@@ -1282,6 +1282,22 @@ gst_element_restore_thyself (xmlNodePtr self, GstObject *parent)
 }
 #endif /* GST_DISABLE_LOADSAVE */
 
+void
+gst_element_yield (GstElement *element)
+{
+  if (GST_ELEMENT_SCHED (element)) {
+    gst_scheduler_yield (GST_ELEMENT_SCHED (element), element);
+  }
+}
+
+void
+gst_element_interrupt (GstElement *element)
+{
+  if (GST_ELEMENT_SCHED (element)) {
+    gst_scheduler_interrupt (GST_ELEMENT_SCHED (element), element);
+  }
+}
+
 /**
  * gst_element_set_sched:
  * @element: Element to set manager of.
index 08e7d26..cf8642f 100644 (file)
@@ -183,8 +183,8 @@ const gchar*            gst_element_get_name            (GstElement *element);
 void                    gst_element_set_parent          (GstElement *element, GstObject *parent);
 GstObject*              gst_element_get_parent          (GstElement *element);
 
-#define                        gst_element_yield(element)      gst_scheduler_yield(GST_ELEMENT_SCHED(element),element)
-#define                        gst_element_interrupt(element)  gst_scheduler_interrupt(GST_ELEMENT_SCHED(element),element)
+void                   gst_element_yield               (GstElement *element);
+void                   gst_element_interrupt           (GstElement *element);
 void                   gst_element_set_sched           (GstElement *element, GstScheduler *sched);
 GstScheduler*          gst_element_get_sched           (GstElement *element);
 
index dda6135..250a898 100644 (file)
@@ -189,20 +189,19 @@ gst_typefind_chain (GstPad *pad, GstBuffer *buf)
 
        gst_pad_set_caps (pad, caps);
 
-{ /* FIXME: this should all be in an _emit() wrapper eventually */
-        int oldstate = GST_STATE(typefind);
-       gst_object_ref (GST_OBJECT (typefind));
-        g_signal_emit (G_OBJECT (typefind), gst_typefind_signals[HAVE_TYPE], 0,
+       {
+          int oldstate = GST_STATE(typefind);
+         gst_object_ref (GST_OBJECT (typefind));
+          g_signal_emit (G_OBJECT (typefind), gst_typefind_signals[HAVE_TYPE], 0,
                              typefind->caps);
-        if (GST_STATE(typefind) != oldstate) {
+          if (GST_STATE(typefind) != oldstate) {
+            GST_DEBUG(0, "state changed during signal, aborting\n");
+           gst_element_yield (GST_ELEMENT (typefind));
+          }
          gst_object_unref (GST_OBJECT (typefind));
-          GST_DEBUG(0, "state changed during signal, aborting\n");
-         gst_element_yield (typefind);
-        }
-       gst_object_unref (GST_OBJECT (typefind));
-}
 
-        goto end;
+          goto end;
+       }
       }
       factories = g_slist_next (factories);
     }