2005-03-21 17:34:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2005 Wim Taymans <wim@fluendo.com>
|
|
|
|
*
|
|
|
|
* gsttask.c: Streaming tasks
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gst_private.h"
|
|
|
|
|
|
|
|
#include "gstinfo.h"
|
|
|
|
#include "gsttask.h"
|
|
|
|
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
GST_DEBUG_CATEGORY (task_debug);
|
|
|
|
#define GST_CAT_DEFAULT (task_debug)
|
|
|
|
|
2005-03-21 17:34:02 +00:00
|
|
|
static void gst_task_class_init (GstTaskClass * klass);
|
|
|
|
static void gst_task_init (GstTask * task);
|
2005-07-18 12:49:53 +00:00
|
|
|
static void gst_task_finalize (GObject * object);
|
|
|
|
|
|
|
|
static void gst_task_func (GstTask * task, GstTaskClass * tclass);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
|
|
|
static GstObjectClass *parent_class = NULL;
|
|
|
|
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
static GStaticMutex pool_lock = G_STATIC_MUTEX_INIT;
|
|
|
|
|
2005-03-21 17:34:02 +00:00
|
|
|
GType
|
|
|
|
gst_task_get_type (void)
|
|
|
|
{
|
|
|
|
static GType _gst_task_type = 0;
|
|
|
|
|
|
|
|
if (!_gst_task_type) {
|
|
|
|
static const GTypeInfo task_info = {
|
|
|
|
sizeof (GstTaskClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_task_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstTask),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_task_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
_gst_task_type =
|
2005-07-18 12:49:53 +00:00
|
|
|
g_type_register_static (GST_TYPE_OBJECT, "GstTask", &task_info, 0);
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (task_debug, "task", 0, "Processing tasks");
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
return _gst_task_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_task_class_init (GstTaskClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_OBJECT);
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_task_finalize);
|
|
|
|
|
|
|
|
klass->pool = g_thread_pool_new (
|
|
|
|
(GFunc) gst_task_func, klass, -1, FALSE, NULL);
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_task_init (GstTask * task)
|
|
|
|
{
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
task->running = FALSE;
|
gst/: Implement gst_pad_pause/start/stop_task(), take STREAM lock in task function.
Original commit message from CVS:
* gst/base/gstadapter.c: (gst_adapter_peek), (gst_adapter_flush):
* gst/base/gstbasesink.c: (gst_basesink_preroll_queue_push),
(gst_basesink_finish_preroll), (gst_basesink_chain),
(gst_basesink_loop), (gst_basesink_activate),
(gst_basesink_change_state):
* gst/base/gstbasesrc.c: (gst_basesrc_do_seek),
(gst_basesrc_get_range), (gst_basesrc_loop),
(gst_basesrc_activate):
* gst/elements/gsttee.c: (gst_tee_sink_activate):
* gst/gstpad.c: (gst_pad_dispose), (gst_real_pad_class_init),
(gst_real_pad_init), (gst_real_pad_set_property),
(gst_real_pad_get_property), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_get_query_types), (gst_pad_unlink),
(gst_pad_link_prepare), (gst_pad_link), (gst_pad_get_real_parent),
(gst_real_pad_get_caps_unlocked), (gst_pad_peer_get_caps),
(gst_pad_accept_caps), (gst_pad_get_peer), (gst_pad_realize),
(gst_pad_event_default_dispatch), (gst_pad_event_default),
(gst_pad_dispatcher), (gst_pad_query), (gst_real_pad_dispose),
(gst_pad_save_thyself), (handle_pad_block), (gst_pad_chain),
(gst_pad_push), (gst_pad_get_range), (gst_pad_pull_range),
(gst_pad_send_event), (gst_pad_start_task), (gst_pad_pause_task),
(gst_pad_stop_task):
* gst/gstpad.h:
* gst/gstqueue.c: (gst_queue_handle_sink_event), (gst_queue_chain),
(gst_queue_loop), (gst_queue_src_activate):
* gst/gsttask.c: (gst_task_init), (gst_task_set_lock),
(gst_task_get_state):
* gst/gsttask.h:
* gst/schedulers/threadscheduler.c:
(gst_thread_scheduler_task_start), (gst_thread_scheduler_func):
Implement gst_pad_pause/start/stop_task(), take STREAM lock
in task function.
Remove ACTIVE pad flag, use FLUSHING everywhere
Added _pad_chain(), _pad_get_range() to call chain/getrange
functions.
Add locks around IS_FLUSHING when reading.
Take STREAM lock in chain(), get_range() functions so plugins
don't need to take it anymore.
2005-05-25 11:50:11 +00:00
|
|
|
task->lock = NULL;
|
2005-03-21 17:34:02 +00:00
|
|
|
task->cond = g_cond_new ();
|
|
|
|
task->state = GST_TASK_STOPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-07-18 12:49:53 +00:00
|
|
|
gst_task_finalize (GObject * object)
|
2005-03-21 17:34:02 +00:00
|
|
|
{
|
|
|
|
GstTask *task = GST_TASK (object);
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_DEBUG ("task %p finalize", task);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
|
|
|
g_cond_free (task->cond);
|
2005-07-18 12:49:53 +00:00
|
|
|
task->cond = NULL;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2005-08-25 10:01:47 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
static void
|
|
|
|
gst_task_func (GstTask * task, GstTaskClass * tclass)
|
|
|
|
{
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
GStaticRecMutex *lock;
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_DEBUG ("Entering task %p, thread %p", task, g_thread_self ());
|
|
|
|
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
/* we have to grab the lock to get the mutex. We also
|
|
|
|
* mark our state running so that nobody can mess with
|
|
|
|
* the mutex. */
|
|
|
|
GST_LOCK (task);
|
|
|
|
if (task->state == GST_TASK_STOPPED)
|
|
|
|
goto exit;
|
|
|
|
lock = GST_TASK_GET_LOCK (task);
|
|
|
|
task->running = TRUE;
|
|
|
|
GST_UNLOCK (task);
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
/* locking order is TASK_LOCK, LOCK */
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
g_static_rec_mutex_lock (lock);
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_LOCK (task);
|
|
|
|
while (G_LIKELY (task->state != GST_TASK_STOPPED)) {
|
|
|
|
while (G_UNLIKELY (task->state == GST_TASK_PAUSED)) {
|
|
|
|
gint t;
|
|
|
|
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
t = g_static_rec_mutex_unlock_full (lock);
|
2005-07-18 12:49:53 +00:00
|
|
|
if (t <= 0) {
|
|
|
|
g_warning ("wrong STREAM_LOCK count %d", t);
|
|
|
|
}
|
|
|
|
GST_TASK_SIGNAL (task);
|
|
|
|
GST_TASK_WAIT (task);
|
|
|
|
GST_UNLOCK (task);
|
|
|
|
/* locking order.. */
|
|
|
|
if (t > 0)
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
g_static_rec_mutex_lock_full (lock, t);
|
2005-07-18 12:49:53 +00:00
|
|
|
|
|
|
|
GST_LOCK (task);
|
|
|
|
if (task->state == GST_TASK_STOPPED)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
GST_UNLOCK (task);
|
|
|
|
|
|
|
|
task->func (task->data);
|
|
|
|
|
|
|
|
GST_LOCK (task);
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
GST_UNLOCK (task);
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
g_static_rec_mutex_unlock (lock);
|
|
|
|
|
|
|
|
/* now we allow messing with the lock again */
|
|
|
|
GST_LOCK (task);
|
|
|
|
task->running = FALSE;
|
|
|
|
exit:
|
|
|
|
GST_TASK_SIGNAL (task);
|
|
|
|
GST_UNLOCK (task);
|
2005-07-18 12:49:53 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("Exit task %p, thread %p", task, g_thread_self ());
|
|
|
|
|
|
|
|
gst_object_unref (task);
|
|
|
|
}
|
|
|
|
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
/**
|
|
|
|
* gst_task_cleanup_all:
|
|
|
|
*
|
|
|
|
* Wait for all tasks to be stopped. This is mainly used internally
|
|
|
|
* to ensure proper cleanup of internal datastructures in testsuites.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_task_cleanup_all (void)
|
|
|
|
{
|
|
|
|
GstTaskClass *klass;
|
|
|
|
|
|
|
|
if ((klass = g_type_class_peek (GST_TYPE_TASK))) {
|
|
|
|
g_static_mutex_lock (&pool_lock);
|
|
|
|
if (klass->pool) {
|
|
|
|
/* Shut down all the threads, we still process the ones scheduled
|
|
|
|
* because the unref happens in the thread function.
|
|
|
|
* Also wait for currently running ones to finish. */
|
|
|
|
g_thread_pool_free (klass->pool, FALSE, TRUE);
|
|
|
|
/* create new pool, so we can still do something after this
|
|
|
|
* call. */
|
|
|
|
klass->pool = g_thread_pool_new (
|
|
|
|
(GFunc) gst_task_func, klass, -1, FALSE, NULL);
|
|
|
|
}
|
|
|
|
g_static_mutex_unlock (&pool_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-21 17:34:02 +00:00
|
|
|
/**
|
|
|
|
* gst_task_create:
|
|
|
|
* @func: The #GstTaskFunction to use
|
|
|
|
* @data: User data to pass to @func
|
|
|
|
*
|
|
|
|
* Create a new Task that will repeadedly call the provided @func
|
|
|
|
* with @data as a parameter. Typically the task will run in
|
|
|
|
* a new thread.
|
|
|
|
*
|
|
|
|
* Returns: A new #GstTask.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
GstTask *
|
|
|
|
gst_task_create (GstTaskFunction func, gpointer data)
|
|
|
|
{
|
2005-07-18 12:49:53 +00:00
|
|
|
GstTask *task;
|
|
|
|
|
|
|
|
task = g_object_new (GST_TYPE_TASK, NULL);
|
|
|
|
task->func = func;
|
|
|
|
task->data = data;
|
|
|
|
|
|
|
|
GST_DEBUG ("Created task %p", task);
|
|
|
|
|
|
|
|
return task;
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
gst/: Implement gst_pad_pause/start/stop_task(), take STREAM lock in task function.
Original commit message from CVS:
* gst/base/gstadapter.c: (gst_adapter_peek), (gst_adapter_flush):
* gst/base/gstbasesink.c: (gst_basesink_preroll_queue_push),
(gst_basesink_finish_preroll), (gst_basesink_chain),
(gst_basesink_loop), (gst_basesink_activate),
(gst_basesink_change_state):
* gst/base/gstbasesrc.c: (gst_basesrc_do_seek),
(gst_basesrc_get_range), (gst_basesrc_loop),
(gst_basesrc_activate):
* gst/elements/gsttee.c: (gst_tee_sink_activate):
* gst/gstpad.c: (gst_pad_dispose), (gst_real_pad_class_init),
(gst_real_pad_init), (gst_real_pad_set_property),
(gst_real_pad_get_property), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_get_query_types), (gst_pad_unlink),
(gst_pad_link_prepare), (gst_pad_link), (gst_pad_get_real_parent),
(gst_real_pad_get_caps_unlocked), (gst_pad_peer_get_caps),
(gst_pad_accept_caps), (gst_pad_get_peer), (gst_pad_realize),
(gst_pad_event_default_dispatch), (gst_pad_event_default),
(gst_pad_dispatcher), (gst_pad_query), (gst_real_pad_dispose),
(gst_pad_save_thyself), (handle_pad_block), (gst_pad_chain),
(gst_pad_push), (gst_pad_get_range), (gst_pad_pull_range),
(gst_pad_send_event), (gst_pad_start_task), (gst_pad_pause_task),
(gst_pad_stop_task):
* gst/gstpad.h:
* gst/gstqueue.c: (gst_queue_handle_sink_event), (gst_queue_chain),
(gst_queue_loop), (gst_queue_src_activate):
* gst/gsttask.c: (gst_task_init), (gst_task_set_lock),
(gst_task_get_state):
* gst/gsttask.h:
* gst/schedulers/threadscheduler.c:
(gst_thread_scheduler_task_start), (gst_thread_scheduler_func):
Implement gst_pad_pause/start/stop_task(), take STREAM lock
in task function.
Remove ACTIVE pad flag, use FLUSHING everywhere
Added _pad_chain(), _pad_get_range() to call chain/getrange
functions.
Add locks around IS_FLUSHING when reading.
Take STREAM lock in chain(), get_range() functions so plugins
don't need to take it anymore.
2005-05-25 11:50:11 +00:00
|
|
|
/**
|
|
|
|
* gst_task_set_lock:
|
|
|
|
* @task: The #GstTask to use
|
|
|
|
* @mutex: The GMutex to use
|
|
|
|
*
|
|
|
|
* Set the mutex used by the task.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_task_set_lock (GstTask * task, GStaticRecMutex * mutex)
|
|
|
|
{
|
|
|
|
GST_LOCK (task);
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
if (task->running)
|
|
|
|
goto is_running;
|
|
|
|
GST_TASK_GET_LOCK (task) = mutex;
|
gst/: Implement gst_pad_pause/start/stop_task(), take STREAM lock in task function.
Original commit message from CVS:
* gst/base/gstadapter.c: (gst_adapter_peek), (gst_adapter_flush):
* gst/base/gstbasesink.c: (gst_basesink_preroll_queue_push),
(gst_basesink_finish_preroll), (gst_basesink_chain),
(gst_basesink_loop), (gst_basesink_activate),
(gst_basesink_change_state):
* gst/base/gstbasesrc.c: (gst_basesrc_do_seek),
(gst_basesrc_get_range), (gst_basesrc_loop),
(gst_basesrc_activate):
* gst/elements/gsttee.c: (gst_tee_sink_activate):
* gst/gstpad.c: (gst_pad_dispose), (gst_real_pad_class_init),
(gst_real_pad_init), (gst_real_pad_set_property),
(gst_real_pad_get_property), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_get_query_types), (gst_pad_unlink),
(gst_pad_link_prepare), (gst_pad_link), (gst_pad_get_real_parent),
(gst_real_pad_get_caps_unlocked), (gst_pad_peer_get_caps),
(gst_pad_accept_caps), (gst_pad_get_peer), (gst_pad_realize),
(gst_pad_event_default_dispatch), (gst_pad_event_default),
(gst_pad_dispatcher), (gst_pad_query), (gst_real_pad_dispose),
(gst_pad_save_thyself), (handle_pad_block), (gst_pad_chain),
(gst_pad_push), (gst_pad_get_range), (gst_pad_pull_range),
(gst_pad_send_event), (gst_pad_start_task), (gst_pad_pause_task),
(gst_pad_stop_task):
* gst/gstpad.h:
* gst/gstqueue.c: (gst_queue_handle_sink_event), (gst_queue_chain),
(gst_queue_loop), (gst_queue_src_activate):
* gst/gsttask.c: (gst_task_init), (gst_task_set_lock),
(gst_task_get_state):
* gst/gsttask.h:
* gst/schedulers/threadscheduler.c:
(gst_thread_scheduler_task_start), (gst_thread_scheduler_func):
Implement gst_pad_pause/start/stop_task(), take STREAM lock
in task function.
Remove ACTIVE pad flag, use FLUSHING everywhere
Added _pad_chain(), _pad_get_range() to call chain/getrange
functions.
Add locks around IS_FLUSHING when reading.
Take STREAM lock in chain(), get_range() functions so plugins
don't need to take it anymore.
2005-05-25 11:50:11 +00:00
|
|
|
GST_UNLOCK (task);
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
is_running:
|
|
|
|
{
|
|
|
|
g_warning ("cannot call set_lock on a running task");
|
|
|
|
GST_UNLOCK (task);
|
|
|
|
}
|
gst/: Implement gst_pad_pause/start/stop_task(), take STREAM lock in task function.
Original commit message from CVS:
* gst/base/gstadapter.c: (gst_adapter_peek), (gst_adapter_flush):
* gst/base/gstbasesink.c: (gst_basesink_preroll_queue_push),
(gst_basesink_finish_preroll), (gst_basesink_chain),
(gst_basesink_loop), (gst_basesink_activate),
(gst_basesink_change_state):
* gst/base/gstbasesrc.c: (gst_basesrc_do_seek),
(gst_basesrc_get_range), (gst_basesrc_loop),
(gst_basesrc_activate):
* gst/elements/gsttee.c: (gst_tee_sink_activate):
* gst/gstpad.c: (gst_pad_dispose), (gst_real_pad_class_init),
(gst_real_pad_init), (gst_real_pad_set_property),
(gst_real_pad_get_property), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_get_query_types), (gst_pad_unlink),
(gst_pad_link_prepare), (gst_pad_link), (gst_pad_get_real_parent),
(gst_real_pad_get_caps_unlocked), (gst_pad_peer_get_caps),
(gst_pad_accept_caps), (gst_pad_get_peer), (gst_pad_realize),
(gst_pad_event_default_dispatch), (gst_pad_event_default),
(gst_pad_dispatcher), (gst_pad_query), (gst_real_pad_dispose),
(gst_pad_save_thyself), (handle_pad_block), (gst_pad_chain),
(gst_pad_push), (gst_pad_get_range), (gst_pad_pull_range),
(gst_pad_send_event), (gst_pad_start_task), (gst_pad_pause_task),
(gst_pad_stop_task):
* gst/gstpad.h:
* gst/gstqueue.c: (gst_queue_handle_sink_event), (gst_queue_chain),
(gst_queue_loop), (gst_queue_src_activate):
* gst/gsttask.c: (gst_task_init), (gst_task_set_lock),
(gst_task_get_state):
* gst/gsttask.h:
* gst/schedulers/threadscheduler.c:
(gst_thread_scheduler_task_start), (gst_thread_scheduler_func):
Implement gst_pad_pause/start/stop_task(), take STREAM lock
in task function.
Remove ACTIVE pad flag, use FLUSHING everywhere
Added _pad_chain(), _pad_get_range() to call chain/getrange
functions.
Add locks around IS_FLUSHING when reading.
Take STREAM lock in chain(), get_range() functions so plugins
don't need to take it anymore.
2005-05-25 11:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-21 17:34:02 +00:00
|
|
|
/**
|
|
|
|
* gst_task_get_state:
|
|
|
|
* @task: The #GstTask to query
|
|
|
|
*
|
|
|
|
* Get the current state of the task.
|
|
|
|
*
|
|
|
|
* Returns: The #GstTaskState of the task
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
GstTaskState
|
|
|
|
gst_task_get_state (GstTask * task)
|
|
|
|
{
|
|
|
|
GstTaskState result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_TASK (task), GST_TASK_STOPPED);
|
|
|
|
|
|
|
|
GST_LOCK (task);
|
|
|
|
result = task->state;
|
|
|
|
GST_UNLOCK (task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_task_start:
|
|
|
|
* @task: The #GstTask to start
|
|
|
|
*
|
|
|
|
* Starts @task.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the task could be started.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_task_start (GstTask * task)
|
|
|
|
{
|
2005-07-18 12:49:53 +00:00
|
|
|
GstTaskState old;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_TASK (task), FALSE);
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_DEBUG_OBJECT (task, "Starting task %p", task);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_LOCK (task);
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
if (G_UNLIKELY (GST_TASK_GET_LOCK (task) == NULL))
|
|
|
|
goto no_lock;
|
2005-07-18 12:49:53 +00:00
|
|
|
|
|
|
|
old = task->state;
|
|
|
|
task->state = GST_TASK_STARTED;
|
|
|
|
switch (old) {
|
|
|
|
case GST_TASK_STOPPED:
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
{
|
|
|
|
GstTaskClass *tclass;
|
|
|
|
|
|
|
|
tclass = GST_TASK_GET_CLASS (task);
|
|
|
|
|
|
|
|
/* new task, push on threadpool. We ref before so
|
|
|
|
* that it remains alive while on the threadpool. */
|
2005-07-18 12:49:53 +00:00
|
|
|
gst_object_ref (task);
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
g_static_mutex_lock (&pool_lock);
|
2005-07-18 12:49:53 +00:00
|
|
|
g_thread_pool_push (tclass->pool, task, NULL);
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
g_static_mutex_unlock (&pool_lock);
|
2005-07-18 12:49:53 +00:00
|
|
|
break;
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
}
|
2005-07-18 12:49:53 +00:00
|
|
|
case GST_TASK_PAUSED:
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
/* PAUSE to PLAY, signal */
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_TASK_SIGNAL (task);
|
|
|
|
break;
|
|
|
|
case GST_TASK_STARTED:
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
/* was OK */
|
2005-07-18 12:49:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_UNLOCK (task);
|
|
|
|
|
|
|
|
return TRUE;
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_lock:
|
|
|
|
{
|
|
|
|
g_warning ("starting task without a lock");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_task_stop:
|
|
|
|
* @task: The #GstTask to stop
|
|
|
|
*
|
|
|
|
* Stops @task.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the task could be stopped.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_task_stop (GstTask * task)
|
|
|
|
{
|
|
|
|
GstTaskClass *tclass;
|
2005-07-18 12:49:53 +00:00
|
|
|
GstTaskState old;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_TASK (task), FALSE);
|
|
|
|
|
|
|
|
tclass = GST_TASK_GET_CLASS (task);
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_DEBUG_OBJECT (task, "Stopping task %p", task);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_LOCK (task);
|
|
|
|
old = task->state;
|
|
|
|
task->state = GST_TASK_STOPPED;
|
|
|
|
switch (old) {
|
|
|
|
case GST_TASK_STOPPED:
|
|
|
|
break;
|
|
|
|
case GST_TASK_PAUSED:
|
|
|
|
GST_TASK_SIGNAL (task);
|
|
|
|
break;
|
|
|
|
case GST_TASK_STARTED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_UNLOCK (task);
|
|
|
|
|
|
|
|
return TRUE;
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_task_pause:
|
|
|
|
* @task: The #GstTask to pause
|
|
|
|
*
|
|
|
|
* Pauses @task.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the task could be paused.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_task_pause (GstTask * task)
|
|
|
|
{
|
2005-07-18 12:49:53 +00:00
|
|
|
GstTaskState old;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_TASK (task), FALSE);
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_DEBUG_OBJECT (task, "Pausing task %p", task);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_LOCK (task);
|
|
|
|
old = task->state;
|
|
|
|
task->state = GST_TASK_PAUSED;
|
|
|
|
switch (old) {
|
|
|
|
case GST_TASK_STOPPED:
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
{
|
|
|
|
GstTaskClass *tclass;
|
|
|
|
|
|
|
|
tclass = GST_TASK_GET_CLASS (task);
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
gst_object_ref (task);
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
g_static_mutex_lock (&pool_lock);
|
2005-07-18 12:49:53 +00:00
|
|
|
g_thread_pool_push (tclass->pool, task, NULL);
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
g_static_mutex_unlock (&pool_lock);
|
2005-07-18 12:49:53 +00:00
|
|
|
break;
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
}
|
2005-07-18 12:49:53 +00:00
|
|
|
case GST_TASK_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_TASK_STARTED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_UNLOCK (task);
|
|
|
|
|
|
|
|
return TRUE;
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_task_join:
|
|
|
|
* @task: The #GstTask to join
|
|
|
|
*
|
|
|
|
* Joins @task. After this call, it is safe to unref the task
|
|
|
|
* and clean up the lock set with #gst_task_set_lock().
|
|
|
|
*
|
|
|
|
* The task will automatically be stopped with this call.
|
|
|
|
*
|
|
|
|
* This function cannot be called from within a task function.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the task could be joined.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_task_join (GstTask * task)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_TASK (task), FALSE);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (task, "Joining task %p", task);
|
|
|
|
|
|
|
|
GST_LOCK (task);
|
|
|
|
task->state = GST_TASK_STOPPED;
|
|
|
|
GST_TASK_SIGNAL (task);
|
|
|
|
while (task->running)
|
|
|
|
GST_TASK_WAIT (task);
|
|
|
|
GST_UNLOCK (task);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|