2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstthread.c: Threaded container object
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 /* #define GST_DEBUG_ENABLED */
26 #include "gst_private.h"
29 #include "gstthread.h"
30 #include "gstscheduler.h"
33 #define STACK_SIZE 0x200000
35 #define g_thread_equal(a,b) ((a) == (b))
37 GstElementDetails gst_thread_details = {
41 "Container that creates/manages a thread",
43 "Erik Walthinsen <omega@cse.ogi.edu>",
48 /* Thread signals and args */
69 static void gst_thread_class_init (GstThreadClass *klass);
70 static void gst_thread_init (GstThread *thread);
72 static void gst_thread_dispose (GObject *object);
74 static void gst_thread_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
75 static void gst_thread_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
78 GstElementStateReturn gst_thread_change_state (GstElement *element);
80 #ifndef GST_DISABLE_LOADSAVE
81 static xmlNodePtr gst_thread_save_thyself (GstObject *object,
83 static void gst_thread_restore_thyself (GstObject *object,
87 static void* gst_thread_main_loop (void *arg);
89 #define GST_TYPE_THREAD_SCHEDPOLICY (gst_thread_schedpolicy_get_type())
91 gst_thread_schedpolicy_get_type(void) {
92 static GType thread_schedpolicy_type = 0;
93 static GEnumValue thread_schedpolicy[] = {
94 {G_THREAD_PRIORITY_LOW, "LOW", "Low Priority Scheduling"},
95 {G_THREAD_PRIORITY_NORMAL, "NORMAL", "Normal Scheduling"},
96 {G_THREAD_PRIORITY_HIGH, "HIGH", "High Priority Scheduling"},
97 {G_THREAD_PRIORITY_URGENT, "URGENT", "Urgent Scheduling"},
100 if (!thread_schedpolicy_type) {
101 thread_schedpolicy_type = g_enum_register_static("GstThreadSchedPolicy", thread_schedpolicy);
103 return thread_schedpolicy_type;
106 static GstBinClass *parent_class = NULL;
107 static guint gst_thread_signals[LAST_SIGNAL] = { 0 };
110 gst_thread_get_type(void) {
111 static GType thread_type = 0;
114 static const GTypeInfo thread_info = {
115 sizeof (GstThreadClass), NULL, NULL,
116 (GClassInitFunc) gst_thread_class_init, NULL, NULL,
119 (GInstanceInitFunc) gst_thread_init,
122 thread_type = g_type_register_static (GST_TYPE_BIN, "GstThread",
129 gst_thread_class_init (GstThreadClass *klass)
131 GObjectClass *gobject_class;
132 GstObjectClass *gstobject_class;
133 GstElementClass *gstelement_class;
134 GstBinClass *gstbin_class;
136 gobject_class = (GObjectClass*)klass;
137 gstobject_class = (GstObjectClass*)klass;
138 gstelement_class = (GstElementClass*)klass;
139 gstbin_class = (GstBinClass*)klass;
141 parent_class = g_type_class_ref (GST_TYPE_BIN);
143 g_object_class_install_property(G_OBJECT_CLASS (klass), ARG_SCHEDPOLICY,
144 g_param_spec_enum("schedpolicy", "Scheduling Policy", "The scheduling policy of the thread",
145 GST_TYPE_THREAD_SCHEDPOLICY, G_THREAD_PRIORITY_NORMAL, G_PARAM_READWRITE));
146 g_object_class_install_property(G_OBJECT_CLASS (klass), ARG_PRIORITY,
147 g_param_spec_int("priority", "Scheduling Priority", "The scheduling priority of the thread",
148 0, 99, 0, G_PARAM_READWRITE));
150 gst_thread_signals[SHUTDOWN] =
151 g_signal_new ("shutdown", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
152 G_STRUCT_OFFSET (GstThreadClass, shutdown), NULL, NULL,
153 gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
155 gobject_class->dispose = gst_thread_dispose;
157 #ifndef GST_DISABLE_LOADSAVE
158 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_thread_save_thyself);
159 gstobject_class->restore_thyself = GST_DEBUG_FUNCPTR (gst_thread_restore_thyself);
162 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_thread_change_state);
164 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_thread_set_property);
165 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_thread_get_property);
170 gst_thread_init (GstThread *thread)
172 GstScheduler *scheduler;
174 GST_DEBUG (GST_CAT_THREAD, "initializing thread");
176 /* threads are managing bins and iterate themselves */
177 /* CR1: the GstBin code checks these flags */
178 GST_FLAG_SET (thread, GST_BIN_FLAG_MANAGER);
179 GST_FLAG_SET (thread, GST_BIN_SELF_SCHEDULABLE);
181 scheduler = gst_scheduler_factory_make (NULL, GST_ELEMENT (thread));
182 g_assert (scheduler);
184 thread->lock = g_mutex_new ();
185 thread->cond = g_cond_new ();
187 thread->ppid = getpid ();
188 thread->thread_id = (GThread *) NULL; /* set in NULL -> READY */
189 thread->sched_policy = G_THREAD_PRIORITY_NORMAL;
190 thread->priority = 0;
191 thread->stack = NULL;
195 gst_thread_dispose (GObject *object)
197 GstThread *thread = GST_THREAD (object);
199 GST_DEBUG (GST_CAT_REFCOUNTING, "dispose");
201 g_mutex_lock (thread->lock);
202 if (GST_STATE (thread) != GST_STATE_NULL) {
203 GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
205 g_mutex_unlock (thread->lock);
207 gst_element_set_state (GST_ELEMENT (thread), GST_STATE_NULL);
209 g_mutex_free (thread->lock);
210 g_cond_free (thread->cond);
212 G_OBJECT_CLASS (parent_class)->dispose (object);
214 if (GST_ELEMENT_SCHED (thread)) {
215 gst_object_unref (GST_OBJECT (GST_ELEMENT_SCHED (thread)));
220 gst_thread_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
224 /* it's not null if we got it, but it might not be ours */
225 g_return_if_fail (GST_IS_THREAD (object));
227 thread = GST_THREAD (object);
230 case ARG_SCHEDPOLICY:
231 thread->sched_policy = g_value_get_enum (value);
234 thread->priority = g_value_get_int (value);
237 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
243 gst_thread_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
247 /* it's not null if we got it, but it might not be ours */
248 g_return_if_fail (GST_IS_THREAD (object));
250 thread = GST_THREAD (object);
253 case ARG_SCHEDPOLICY:
254 g_value_set_enum (value, thread->sched_policy);
257 g_value_set_int (value, thread->priority);
260 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
268 * @name: the name of the thread
270 * Create a new thread with the given name.
272 * Returns: The new thread
275 gst_thread_new (const gchar *name)
277 return gst_element_factory_make ("thread", name);
280 /* these two macros are used for debug/info from the state_change function */
282 #define THR_INFO(format,args...) \
283 GST_INFO_ELEMENT(GST_CAT_THREAD, thread, "sync(" GST_DEBUG_THREAD_FORMAT "): " format , \
284 GST_DEBUG_THREAD_ARGS(thread->pid) , ## args )
286 #define THR_DEBUG(format,args...) \
287 GST_DEBUG_ELEMENT(GST_CAT_THREAD, thread, "sync(" GST_DEBUG_THREAD_FORMAT "): " format , \
288 GST_DEBUG_THREAD_ARGS(thread->pid) , ## args )
290 /* these two macros are used for debug/info from the gst_thread_main_loop
294 #define THR_INFO_MAIN(format,args...) \
295 GST_INFO_ELEMENT(GST_CAT_THREAD, thread, "sync-main(" GST_DEBUG_THREAD_FORMAT "): " format , \
296 GST_DEBUG_THREAD_ARGS(thread->ppid) , ## args )
298 #define THR_DEBUG_MAIN(format,args...) \
299 GST_DEBUG_ELEMENT(GST_CAT_THREAD, thread, "sync-main(" GST_DEBUG_THREAD_FORMAT "): " format , \
300 GST_DEBUG_THREAD_ARGS(thread->ppid) , ## args )
302 static GstElementStateReturn
303 gst_thread_update_state (GstThread *thread)
305 GST_DEBUG_ELEMENT (GST_CAT_THREAD, thread, "updating state of thread");
306 /* check for state change */
307 if (GST_STATE_PENDING (thread) != GST_STATE_VOID_PENDING) {
308 /* punt and change state on all the children */
309 if (GST_ELEMENT_CLASS (parent_class)->change_state)
310 return GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT (thread));
313 /* FIXME: in the case of no change_state function in the parent's class,
314 * shouldn't we actually change the thread's state ? */
315 g_warning ("thread's parent doesn't have change_state, returning success");
316 return GST_STATE_SUCCESS;
320 static GstElementStateReturn
321 gst_thread_change_state (GstElement *element)
324 gboolean stateset = GST_STATE_SUCCESS;
326 GThread *self = g_thread_self ();
327 GError *error = NULL;
329 g_return_val_if_fail (GST_IS_THREAD (element), GST_STATE_FAILURE);
330 g_return_val_if_fail (gst_has_threads (), GST_STATE_FAILURE);
332 thread = GST_THREAD (element);
334 transition = GST_STATE_TRANSITION (element);
336 THR_INFO ("changing state from %s to %s",
337 gst_element_state_get_name (GST_STATE (element)),
338 gst_element_state_get_name (GST_STATE_PENDING (element)));
340 if (g_thread_equal (self, thread->thread_id)) {
341 GST_DEBUG (GST_CAT_THREAD,
342 "no sync(" GST_DEBUG_THREAD_FORMAT "): "
343 "setting own thread's state to spinning",
344 GST_DEBUG_THREAD_ARGS (thread->pid));
345 return gst_thread_update_state (thread);
348 switch (transition) {
349 case GST_STATE_NULL_TO_READY:
350 /* set the state to idle */
351 GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
353 THR_DEBUG ("creating thread \"%s\"", GST_ELEMENT_NAME (element));
355 /* this bit of code handles creation of GThreads
356 * this is therefor tricky code
357 * compare it with the block of code that handles the destruction
358 * in GST_STATE_READY_TO_NULL below
360 g_mutex_lock (thread->lock);
362 /* create a new GThread
363 * use the specified attributes
364 * make it execute gst_thread_main_loop (thread)
366 GST_DEBUG (GST_CAT_THREAD, "going to g_thread_create_full...");
367 thread->thread_id = g_thread_create_full(gst_thread_main_loop,
368 thread, STACK_SIZE, TRUE, TRUE, G_THREAD_PRIORITY_NORMAL,
371 if (!thread->thread_id){
372 GST_DEBUG (GST_CAT_THREAD, "g_thread_create_full failed");
373 g_mutex_unlock (thread->lock);
374 GST_DEBUG (GST_CAT_THREAD, "could not create thread \"%s\"",
375 GST_ELEMENT_NAME (element));
377 return GST_STATE_FAILURE;
379 GST_DEBUG (GST_CAT_THREAD, "GThread created");
381 /* wait for it to 'spin up' */
382 THR_DEBUG ("waiting for child thread spinup");
383 g_cond_wait (thread->cond, thread->lock);
384 THR_DEBUG ("thread claims to be up");
385 g_mutex_unlock (thread->lock);
387 case GST_STATE_READY_TO_PAUSED:
388 THR_INFO ("readying thread");
389 g_mutex_lock (thread->lock);
390 THR_DEBUG ("signaling");
391 g_cond_signal (thread->cond);
392 THR_DEBUG ("waiting for ack");
393 g_cond_wait (thread->cond, thread->lock);
394 THR_DEBUG ("got ack");
395 g_mutex_unlock (thread->lock);
397 case GST_STATE_PAUSED_TO_PLAYING:
399 /* fixme: recurse into sub-bins */
400 const GList *elements = gst_bin_get_list (GST_BIN (thread));
402 gst_element_enable_threadsafe_properties ((GstElement*)elements->data);
403 elements = g_list_next (elements);
406 THR_DEBUG ("telling thread to start spinning");
407 g_mutex_lock (thread->lock);
408 THR_DEBUG ("signaling");
409 g_cond_signal (thread->cond);
410 THR_DEBUG ("waiting for ack");
411 g_cond_wait (thread->cond, thread->lock);
412 THR_DEBUG ("got ack");
413 g_mutex_unlock (thread->lock);
415 /* we're actually doing async notification, the state could
416 * have changed already (eg. EOS) here. commented out as
417 * it needs more thinking... */
418 /* stateset = GST_STATE_ASYNC; */
421 case GST_STATE_PLAYING_TO_PAUSED:
423 const GList *elements = (GList *) gst_bin_get_list (GST_BIN (thread));
425 THR_INFO ("pausing thread");
427 /* the following code ensures that the bottom half of thread will run
428 * to perform each elements' change_state() (by calling gstbin.c::
430 * + the pending state was already set by gstelement.c::set_state()
431 * + unlock all elements so the bottom half can start the state change.
433 g_mutex_lock (thread->lock);
435 GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
438 GstElement *element = GST_ELEMENT (elements->data);
442 THR_DEBUG (" waking element \"%s\"", GST_ELEMENT_NAME (element));
443 elements = g_list_next (elements);
445 if (!gst_element_release_locks (element)) {
446 g_warning ("element %s could not release locks",
447 GST_ELEMENT_NAME (element));
450 pads = GST_ELEMENT_PADS (element);
453 GstRealPad *peer = NULL;
454 GstElement *peerelement;
456 if (GST_PAD_PEER (pads->data))
457 peer = GST_REAL_PAD (GST_PAD_PEER (pads->data));
459 pads = g_list_next (pads);
464 peerelement = GST_PAD_PARENT (peer);
466 continue; /* deal with case where there's no peer */
468 if (!GST_FLAG_IS_SET (peerelement, GST_ELEMENT_DECOUPLED)) {
469 GST_DEBUG (GST_CAT_THREAD, "peer element isn't DECOUPLED");
473 if (GST_ELEMENT_SCHED (peerelement) != GST_ELEMENT_SCHED (thread)) {
474 THR_DEBUG (" element \"%s\" has pad cross sched boundary", GST_ELEMENT_NAME (element));
475 THR_DEBUG (" waking element \"%s\"", GST_ELEMENT_NAME (peerelement));
476 if (!gst_element_release_locks (peerelement)) {
477 g_warning ("element %s could not release locks", GST_ELEMENT_NAME (peerelement));
483 THR_DEBUG ("telling thread to pause, signaling");
484 g_cond_signal (thread->cond);
485 THR_DEBUG ("waiting for ack");
486 g_cond_wait (thread->cond, thread->lock);
487 THR_DEBUG ("got ack");
488 g_mutex_unlock (thread->lock);
490 elements = gst_bin_get_list (GST_BIN (thread));
492 gst_element_disable_threadsafe_properties ((GstElement*)elements->data);
493 elements = g_list_next (elements);
497 case GST_STATE_READY_TO_NULL:
498 THR_DEBUG ("telling thread to pause (null) - and joining");
499 /* MattH FIXME revisit */
500 g_mutex_lock (thread->lock);
501 THR_DEBUG ("signaling");
502 g_cond_signal (thread->cond);
503 THR_DEBUG ("waiting for ack");
504 g_cond_wait (thread->cond, thread->lock);
505 THR_DEBUG ("got ack");
508 /* this block of code is very tricky
509 * basically, we try to clean up the whole thread and
510 * everything related to it in the right order without
511 * triggering segfaults
512 * compare this block to the block
515 GST_DEBUG (GST_CAT_THREAD, "joining GThread %p", thread->thread_id);
516 g_thread_join (thread->thread_id);
518 thread->thread_id = NULL;
519 thread->stack = NULL;
521 THR_DEBUG ("unlocking mutex");
522 g_mutex_unlock (thread->lock);
524 GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING);
525 GST_FLAG_UNSET (thread, GST_THREAD_STATE_STARTED);
526 GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
529 case GST_STATE_PAUSED_TO_READY:
530 THR_DEBUG ("telling thread to stop spinning");
531 g_mutex_lock (thread->lock);
532 THR_DEBUG ("signaling");
533 g_cond_signal (thread->cond);
534 THR_DEBUG ("waiting for ack");
535 g_cond_wait (thread->cond, thread->lock);
536 THR_DEBUG ("got ack");
537 g_mutex_unlock (thread->lock);
541 GST_DEBUG_ELEMENT (GST_CAT_THREAD, element, "UNHANDLED STATE CHANGE! %x", transition);
549 * gst_thread_main_loop:
550 * @arg: the thread to start
552 * The main loop of the thread. The thread will iterate
553 * while the state is GST_THREAD_STATE_SPINNING.
556 gst_thread_main_loop (void *arg)
558 GstThread *thread = NULL;
561 gpointer stack_pointer;
564 GST_DEBUG (GST_CAT_THREAD, "gst_thread_main_loop started");
565 thread = GST_THREAD (arg);
566 g_mutex_lock (thread->lock);
568 /* set up the element's scheduler */
569 gst_scheduler_setup (GST_ELEMENT_SCHED (thread));
570 GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING);
572 thread->pid = getpid();
573 THR_INFO_MAIN ("thread is running");
575 page_size = sysconf(_SC_PAGESIZE);
576 stack_pointer = (gpointer) &stack_pointer;
578 if(((gulong)stack_pointer & (page_size-1)) < (page_size>>1)){
579 /* stack grows up, I think */
580 /* FIXME this is probably not true for the main thread */
581 stack_offset = (gulong)stack_pointer & (page_size - 1);
583 /* stack grows down, I think */
584 stack_offset = STACK_SIZE - ((gulong)stack_pointer & (page_size - 1));
586 /* note the subtlety with pointer arithmetic */
587 thread->stack = stack_pointer - stack_offset;
588 thread->stack_size = STACK_SIZE;
590 /* first we need to change the state of all the children */
591 if (GST_ELEMENT_CLASS (parent_class)->change_state) {
592 stateset = GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT(thread));
594 if (stateset != GST_STATE_SUCCESS) {
595 THR_DEBUG_MAIN ("state change of children failed");
599 THR_DEBUG_MAIN ("indicating spinup");
600 g_cond_signal (thread->cond);
601 /* don't unlock the mutex because we hold it into the top of the while loop */
602 THR_DEBUG_MAIN ("thread has indicated spinup to parent process");
604 /***** THREAD IS NOW IN READY STATE *****/
606 /* CR1: most of this code is handshaking */
607 /* do this while the thread lives */
608 while (!GST_FLAG_IS_SET (thread, GST_THREAD_STATE_REAPING)) {
609 /* NOTE we hold the thread lock at this point */
610 /* what we do depends on what state we're in */
611 switch (GST_STATE (thread)) {
612 /* NOTE: cannot be in NULL, we're not running in that state at all */
613 case GST_STATE_READY:
614 /* wait to be set to either the NULL or PAUSED states */
615 THR_DEBUG_MAIN ("thread in %s state, waiting for either %s or %s",
616 gst_element_state_get_name (GST_STATE_READY),
617 gst_element_state_get_name (GST_STATE_NULL),
618 gst_element_state_get_name (GST_STATE_PAUSED));
619 g_cond_wait (thread->cond, thread->lock);
621 /* this must have happened by a state change in the thread context */
622 if (GST_STATE_PENDING (thread) != GST_STATE_NULL &&
623 GST_STATE_PENDING (thread) != GST_STATE_PAUSED) {
624 g_cond_signal (thread->cond);
628 /* been signaled, we need to state transition now and signal back */
629 gst_thread_update_state (thread);
630 /* now we decide what to do next */
631 if (GST_STATE (thread) == GST_STATE_NULL) {
632 /* REAPING must be set, we can simply break this iteration */
633 THR_DEBUG_MAIN ("set GST_THREAD_STATE_REAPING");
634 GST_FLAG_SET (thread, GST_THREAD_STATE_REAPING);
636 THR_DEBUG_MAIN ("done with state transition, "
637 "signaling back to parent process");
638 g_cond_signal (thread->cond);
641 case GST_STATE_PAUSED:
642 /* wait to be set to either the READY or PLAYING states */
643 THR_DEBUG_MAIN ("thread in %s state, waiting for either %s or %s",
644 gst_element_state_get_name (GST_STATE_PAUSED),
645 gst_element_state_get_name (GST_STATE_READY),
646 gst_element_state_get_name (GST_STATE_PLAYING));
647 g_cond_wait (thread->cond, thread->lock);
649 /* this must have happened by a state change in the thread context */
650 if (GST_STATE_PENDING (thread) != GST_STATE_READY &&
651 GST_STATE_PENDING (thread) != GST_STATE_PLAYING) {
652 g_cond_signal (thread->cond);
656 /* been signaled, we need to state transition now and signal back */
657 gst_thread_update_state (thread);
659 /* now we decide what to do next */
660 if (GST_STATE (thread) != GST_STATE_PLAYING) {
661 /* either READY or the state change failed for some reason */
662 g_cond_signal (thread->cond);
666 GST_FLAG_SET (thread, GST_THREAD_STATE_SPINNING);
667 /* PLAYING is coming up, so we can now start spinning */
668 while (GST_FLAG_IS_SET (thread, GST_THREAD_STATE_SPINNING)) {
671 g_cond_signal (thread->cond);
672 g_mutex_unlock (thread->lock);
673 status = gst_bin_iterate (GST_BIN (thread));
674 g_mutex_lock (thread->lock);
675 /* g_cond_signal(thread->cond); */
677 if (!status || GST_STATE_PENDING (thread) != GST_STATE_VOID_PENDING)
678 GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
680 /* looks like we were stopped because of a statechange */
681 if (GST_STATE_PENDING (thread) != GST_STATE_VOID_PENDING) {
682 gst_thread_update_state (thread);
684 /* once we're here, SPINNING has stopped, we should signal that we're done */
685 THR_DEBUG_MAIN ("SPINNING stopped, signaling back to parent process");
686 g_cond_signal (thread->cond);
687 /* now we can wait for PAUSED */
690 case GST_STATE_PLAYING:
691 /* wait to be set to PAUSED */
692 THR_DEBUG_MAIN ("thread in %s state, waiting for %s",
693 gst_element_state_get_name (GST_STATE_PLAYING),
694 gst_element_state_get_name (GST_STATE_PAUSED));
695 g_cond_wait (thread->cond,thread->lock);
697 /* been signaled, we need to state transition now and signal back */
698 gst_thread_update_state (thread);
699 g_cond_signal (thread->cond);
700 /* now we decide what to do next */
701 /* there's only PAUSED, we we just wait for it */
704 THR_DEBUG_MAIN ("thread in %s state, preparing to die",
705 gst_element_state_get_name (GST_STATE_NULL));
706 GST_FLAG_SET (thread, GST_THREAD_STATE_REAPING);
709 g_assert_not_reached ();
714 /* THREAD HAS STOPPED RUNNING */
716 /* we need to destroy the scheduler here because it has mapped it's
717 * stack into the threads stack space */
718 gst_scheduler_reset (GST_ELEMENT_SCHED (thread));
720 /* since we don't unlock at the end of the while loop, do it here */
721 g_mutex_unlock (thread->lock);
723 GST_INFO (GST_CAT_THREAD, "gstthread: thread \"%s\" is stopped",
724 GST_ELEMENT_NAME (thread));
726 g_signal_emit (G_OBJECT (thread), gst_thread_signals[SHUTDOWN], 0);
731 #ifndef GST_DISABLE_LOADSAVE
733 gst_thread_save_thyself (GstObject *object,
736 if (GST_OBJECT_CLASS (parent_class)->save_thyself)
737 GST_OBJECT_CLASS (parent_class)->save_thyself (object, self);
742 gst_thread_restore_thyself (GstObject *object,
745 GST_DEBUG (GST_CAT_THREAD,"gstthread: restore");
747 if (GST_OBJECT_CLASS (parent_class)->restore_thyself)
748 GST_OBJECT_CLASS (parent_class)->restore_thyself (object, self);
750 #endif /* GST_DISABLE_LOADSAVE */