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
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2005-03-21 17:34:02 +00:00
|
|
|
*/
|
|
|
|
|
2005-10-20 19:30:57 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gsttask
|
2017-01-16 14:26:16 +00:00
|
|
|
* @title: GstTask
|
2005-10-20 19:30:57 +00:00
|
|
|
* @short_description: Abstraction of GStreamer streaming threads.
|
|
|
|
* @see_also: #GstElement, #GstPad
|
|
|
|
*
|
2005-11-09 16:32:49 +00:00
|
|
|
* #GstTask is used by #GstElement and #GstPad to provide the data passing
|
|
|
|
* threads in a #GstPipeline.
|
2005-10-20 19:30:57 +00:00
|
|
|
*
|
2005-11-09 16:32:49 +00:00
|
|
|
* A #GstPad will typically start a #GstTask to push or pull data to/from the
|
|
|
|
* peer pads. Most source elements start a #GstTask to push data. In some cases
|
|
|
|
* a demuxer element can start a #GstTask to pull data from a peer element. This
|
2005-10-20 19:30:57 +00:00
|
|
|
* is typically done when the demuxer can perform random access on the upstream
|
|
|
|
* peer element for improved performance.
|
|
|
|
*
|
2010-03-15 13:48:19 +00:00
|
|
|
* Although convenience functions exist on #GstPad to start/pause/stop tasks, it
|
2005-11-09 16:32:49 +00:00
|
|
|
* might sometimes be needed to create a #GstTask manually if it is not related to
|
|
|
|
* a #GstPad.
|
2005-10-20 19:30:57 +00:00
|
|
|
*
|
2012-11-14 11:20:54 +00:00
|
|
|
* Before the #GstTask can be run, it needs a #GRecMutex that can be set with
|
2005-10-20 19:30:57 +00:00
|
|
|
* gst_task_set_lock().
|
|
|
|
*
|
|
|
|
* The task can be started, paused and stopped with gst_task_start(), gst_task_pause()
|
2009-04-21 15:53:07 +00:00
|
|
|
* and gst_task_stop() respectively or with the gst_task_set_state() function.
|
2005-10-20 19:30:57 +00:00
|
|
|
*
|
2008-05-26 10:07:09 +00:00
|
|
|
* A #GstTask will repeatedly call the #GstTaskFunction with the user data
|
2011-10-29 07:26:49 +00:00
|
|
|
* that was provided when creating the task with gst_task_new(). While calling
|
2009-04-21 15:53:07 +00:00
|
|
|
* the function it will acquire the provided lock. The provided lock is released
|
|
|
|
* when the task pauses or stops.
|
2005-10-20 19:30:57 +00:00
|
|
|
*
|
2008-05-26 10:07:09 +00:00
|
|
|
* Stopping a task with gst_task_stop() will not immediately make sure the task is
|
2005-11-09 16:32:49 +00:00
|
|
|
* not running anymore. Use gst_task_join() to make sure the task is completely
|
2005-10-20 19:30:57 +00:00
|
|
|
* stopped and the thread is stopped.
|
|
|
|
*
|
2005-11-09 16:32:49 +00:00
|
|
|
* After creating a #GstTask, use gst_object_unref() to free its resources. This can
|
2012-03-29 11:34:50 +00:00
|
|
|
* only be done when the task is not running anymore.
|
2005-11-09 16:32:49 +00:00
|
|
|
*
|
2009-12-14 14:22:16 +00:00
|
|
|
* Task functions can send a #GstMessage to send out-of-band data to the
|
|
|
|
* application. The application can receive messages from the #GstBus in its
|
|
|
|
* mainloop.
|
|
|
|
*
|
2012-03-29 11:34:50 +00:00
|
|
|
* For debugging purposes, the task will configure its object name as the thread
|
2010-03-15 14:07:35 +00:00
|
|
|
* name on Linux. Please note that the object name should be configured before the
|
|
|
|
* task is started; changing the object name after the task has been started, has
|
|
|
|
* no effect on the thread name.
|
2005-10-20 19:30:57 +00:00
|
|
|
*/
|
|
|
|
|
2005-03-21 17:34:02 +00:00
|
|
|
#include "gst_private.h"
|
|
|
|
|
|
|
|
#include "gstinfo.h"
|
|
|
|
#include "gsttask.h"
|
2011-12-04 13:35:38 +00:00
|
|
|
#include "glib-compat-private.h"
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2010-03-16 07:56:41 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-03-15 13:48:19 +00:00
|
|
|
#ifdef HAVE_SYS_PRCTL_H
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#endif
|
|
|
|
|
2015-02-01 01:39:03 +00:00
|
|
|
#ifdef HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
2005-10-15 19:57:03 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (task_debug);
|
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
|
|
|
#define GST_CAT_DEFAULT (task_debug)
|
|
|
|
|
2010-10-20 09:58:06 +00:00
|
|
|
#define SET_TASK_STATE(t,s) (g_atomic_int_set (&GST_TASK_STATE(t), (s)))
|
2011-08-25 19:52:05 +00:00
|
|
|
#define GET_TASK_STATE(t) ((GstTaskState) g_atomic_int_get (&GST_TASK_STATE(t)))
|
2010-10-20 09:58:06 +00:00
|
|
|
|
2009-05-11 21:19:53 +00:00
|
|
|
struct _GstTaskPrivate
|
|
|
|
{
|
|
|
|
/* callbacks for managing the thread of this task */
|
2012-06-20 09:59:09 +00:00
|
|
|
GstTaskThreadFunc enter_func;
|
|
|
|
gpointer enter_user_data;
|
|
|
|
GDestroyNotify enter_notify;
|
|
|
|
|
|
|
|
GstTaskThreadFunc leave_func;
|
|
|
|
gpointer leave_user_data;
|
|
|
|
GDestroyNotify leave_notify;
|
2009-04-21 17:15:48 +00:00
|
|
|
|
2009-04-23 15:05:21 +00:00
|
|
|
/* configured pool */
|
2009-05-11 22:25:11 +00:00
|
|
|
GstTaskPool *pool;
|
2009-04-23 15:05:21 +00:00
|
|
|
|
|
|
|
/* remember the pool and id that is currently running. */
|
2009-05-11 22:25:11 +00:00
|
|
|
gpointer id;
|
2009-04-23 15:05:21 +00:00
|
|
|
GstTaskPool *pool_id;
|
2009-05-11 21:19:53 +00:00
|
|
|
};
|
|
|
|
|
2010-10-20 08:18:18 +00:00
|
|
|
#ifdef _MSC_VER
|
2016-02-19 14:56:26 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2010-10-20 08:18:18 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
2021-01-14 16:16:34 +00:00
|
|
|
typedef HRESULT (WINAPI * pSetThreadDescription) (HANDLE hThread,
|
|
|
|
PCWSTR lpThreadDescription);
|
|
|
|
static pSetThreadDescription SetThreadDescriptionFunc = NULL;
|
|
|
|
HMODULE kernel32_module = NULL;
|
|
|
|
|
2010-10-20 08:18:18 +00:00
|
|
|
struct _THREADNAME_INFO
|
|
|
|
{
|
|
|
|
DWORD dwType; // must be 0x1000
|
|
|
|
LPCSTR szName; // pointer to name (in user addr space)
|
|
|
|
DWORD dwThreadID; // thread ID (-1=caller thread)
|
|
|
|
DWORD dwFlags; // reserved for future use, must be zero
|
|
|
|
};
|
|
|
|
typedef struct _THREADNAME_INFO THREADNAME_INFO;
|
|
|
|
|
2021-01-14 16:16:34 +00:00
|
|
|
static void
|
2010-10-20 08:18:18 +00:00
|
|
|
SetThreadName (DWORD dwThreadID, LPCSTR szThreadName)
|
|
|
|
{
|
|
|
|
THREADNAME_INFO info;
|
|
|
|
info.dwType = 0x1000;
|
|
|
|
info.szName = szThreadName;
|
|
|
|
info.dwThreadID = dwThreadID;
|
|
|
|
info.dwFlags = 0;
|
|
|
|
|
|
|
|
__try {
|
|
|
|
RaiseException (0x406D1388, 0, sizeof (info) / sizeof (DWORD),
|
2016-11-11 18:30:44 +00:00
|
|
|
(const ULONG_PTR *) &info);
|
2010-10-20 08:18:18 +00:00
|
|
|
}
|
|
|
|
__except (EXCEPTION_CONTINUE_EXECUTION) {
|
|
|
|
}
|
|
|
|
}
|
2021-01-14 16:16:34 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_task_win32_load_library (void)
|
|
|
|
{
|
|
|
|
/* FIXME: Add support for UWP app */
|
|
|
|
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
2021-03-18 03:46:15 +00:00
|
|
|
static gsize _init_once = 0;
|
2021-01-14 16:16:34 +00:00
|
|
|
if (g_once_init_enter (&_init_once)) {
|
|
|
|
kernel32_module = LoadLibraryW (L"kernel32.dll");
|
|
|
|
if (kernel32_module) {
|
|
|
|
SetThreadDescriptionFunc =
|
|
|
|
(pSetThreadDescription) GetProcAddress (kernel32_module,
|
|
|
|
"SetThreadDescription");
|
|
|
|
if (!SetThreadDescriptionFunc)
|
|
|
|
FreeLibrary (kernel32_module);
|
|
|
|
}
|
|
|
|
g_once_init_leave (&_init_once, 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ! !SetThreadDescriptionFunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_task_win32_set_thread_desc (const gchar * name)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
wchar_t *namew;
|
|
|
|
|
|
|
|
if (!gst_task_win32_load_library () || !name)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
namew = g_utf8_to_utf16 (name, -1, NULL, NULL, NULL);
|
|
|
|
if (!namew)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hr = SetThreadDescriptionFunc (GetCurrentThread (), namew);
|
|
|
|
|
|
|
|
g_free (namew);
|
|
|
|
return SUCCEEDED (hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_task_win32_set_thread_name (const gchar * name)
|
|
|
|
{
|
|
|
|
/* Prefer SetThreadDescription over exception based way if available,
|
|
|
|
* since thread description set by SetThreadDescription will be preserved
|
|
|
|
* in dump file */
|
|
|
|
if (!gst_task_win32_set_thread_desc (name))
|
|
|
|
SetThreadName ((DWORD) - 1, name);
|
|
|
|
}
|
2010-10-20 08:18:18 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
static void gst_task_finalize (GObject * object);
|
|
|
|
|
2009-04-24 10:35:08 +00:00
|
|
|
static void gst_task_func (GstTask * task);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2012-01-22 22:44:59 +00:00
|
|
|
static GMutex pool_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
|
|
|
|
2020-06-12 13:07:42 +00:00
|
|
|
static GstTaskPool *_global_task_pool = NULL;
|
|
|
|
|
2009-04-04 08:20:36 +00:00
|
|
|
#define _do_init \
|
|
|
|
{ \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (task_debug, "task", 0, "Processing tasks"); \
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 15:01:09 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstTask, gst_task, GST_TYPE_OBJECT,
|
|
|
|
G_ADD_PRIVATE (GstTask) _do_init);
|
2009-04-04 08:20:36 +00:00
|
|
|
|
2020-06-12 13:07:42 +00:00
|
|
|
/* Called with pool_lock */
|
2009-05-11 22:25:11 +00:00
|
|
|
static void
|
2020-06-12 13:07:42 +00:00
|
|
|
ensure_klass_pool (GstTaskClass * klass)
|
2009-05-11 22:25:11 +00:00
|
|
|
{
|
2020-06-12 13:07:42 +00:00
|
|
|
if (G_UNLIKELY (_global_task_pool == NULL)) {
|
|
|
|
_global_task_pool = gst_task_pool_new ();
|
|
|
|
gst_task_pool_prepare (_global_task_pool, NULL);
|
|
|
|
|
|
|
|
/* Classes are never destroyed so this ref will never be dropped */
|
|
|
|
GST_OBJECT_FLAG_SET (_global_task_pool, GST_OBJECT_FLAG_MAY_BE_LEAKED);
|
2009-05-11 22:25:11 +00:00
|
|
|
}
|
2020-06-12 13:07:42 +00:00
|
|
|
klass->pool = _global_task_pool;
|
2009-05-11 22:25:11 +00:00
|
|
|
}
|
|
|
|
|
2005-03-21 17:34:02 +00:00
|
|
|
static void
|
|
|
|
gst_task_class_init (GstTaskClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
|
2009-10-28 00:29:30 +00:00
|
|
|
gobject_class->finalize = gst_task_finalize;
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_task_init (GstTask * task)
|
|
|
|
{
|
2009-05-11 22:25:11 +00:00
|
|
|
GstTaskClass *klass;
|
|
|
|
|
|
|
|
klass = GST_TASK_GET_CLASS (task);
|
|
|
|
|
2018-06-23 15:01:09 +00:00
|
|
|
task->priv = gst_task_get_instance_private (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;
|
2011-02-22 15:04:12 +00:00
|
|
|
task->thread = NULL;
|
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;
|
2012-01-19 08:27:04 +00:00
|
|
|
g_cond_init (&task->cond);
|
2010-10-20 09:58:06 +00:00
|
|
|
SET_TASK_STATE (task, GST_TASK_STOPPED);
|
2009-05-11 22:25:11 +00:00
|
|
|
|
|
|
|
/* use the default klass pool for this task, users can
|
|
|
|
* override this later */
|
2012-01-22 22:44:59 +00:00
|
|
|
g_mutex_lock (&pool_lock);
|
2020-06-12 13:07:42 +00:00
|
|
|
ensure_klass_pool (klass);
|
2009-05-11 22:25:11 +00:00
|
|
|
task->priv->pool = gst_object_ref (klass->pool);
|
2012-01-22 22:44:59 +00:00
|
|
|
g_mutex_unlock (&pool_lock);
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2009-04-20 15:19:21 +00:00
|
|
|
GstTaskPrivate *priv = task->priv;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
GST_DEBUG ("task %p finalize", task);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2012-06-20 09:59:09 +00:00
|
|
|
if (priv->enter_notify)
|
|
|
|
priv->enter_notify (priv->enter_user_data);
|
|
|
|
|
|
|
|
if (priv->leave_notify)
|
|
|
|
priv->leave_notify (priv->leave_user_data);
|
2009-04-20 15:19:21 +00:00
|
|
|
|
2012-06-20 08:31:49 +00:00
|
|
|
if (task->notify)
|
|
|
|
task->notify (task->user_data);
|
|
|
|
|
2009-04-23 15:05:21 +00:00
|
|
|
gst_object_unref (priv->pool);
|
|
|
|
|
2005-10-21 11:36:32 +00:00
|
|
|
/* task thread cannot be running here since it holds a ref
|
|
|
|
* to the task so that the finalize could not have happened */
|
2012-01-19 08:27:04 +00:00
|
|
|
g_cond_clear (&task->cond);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2009-04-20 15:07:50 +00:00
|
|
|
G_OBJECT_CLASS (gst_task_parent_class)->finalize (object);
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
2010-03-15 13:48:19 +00:00
|
|
|
/* should be called with the object LOCK */
|
|
|
|
static void
|
|
|
|
gst_task_configure_name (GstTask * task)
|
|
|
|
{
|
2011-06-25 20:51:52 +00:00
|
|
|
#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME)
|
2010-03-15 13:48:19 +00:00
|
|
|
const gchar *name;
|
|
|
|
gchar thread_name[17] = { 0, };
|
|
|
|
|
2010-10-20 09:58:06 +00:00
|
|
|
GST_OBJECT_LOCK (task);
|
2010-03-15 13:48:19 +00:00
|
|
|
name = GST_OBJECT_NAME (task);
|
|
|
|
|
|
|
|
/* set the thread name to something easily identifiable */
|
|
|
|
if (!snprintf (thread_name, 17, "%s", GST_STR_NULL (name))) {
|
|
|
|
GST_DEBUG_OBJECT (task, "Could not create thread name for '%s'", name);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (task, "Setting thread name to '%s'", thread_name);
|
2010-03-15 16:07:59 +00:00
|
|
|
if (prctl (PR_SET_NAME, (unsigned long int) thread_name, 0, 0, 0))
|
2010-03-15 13:48:19 +00:00
|
|
|
GST_DEBUG_OBJECT (task, "Failed to set thread name");
|
|
|
|
}
|
2010-10-20 09:58:06 +00:00
|
|
|
GST_OBJECT_UNLOCK (task);
|
2015-02-01 01:39:03 +00:00
|
|
|
#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)
|
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (task);
|
|
|
|
name = GST_OBJECT_NAME (task);
|
|
|
|
|
|
|
|
/* set the thread name to something easily identifiable */
|
|
|
|
GST_DEBUG_OBJECT (task, "Setting thread name to '%s'", name);
|
|
|
|
if (pthread_setname_np (name))
|
|
|
|
GST_DEBUG_OBJECT (task, "Failed to set thread name");
|
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
2015-02-01 19:23:26 +00:00
|
|
|
#elif defined (_MSC_VER)
|
2010-10-20 08:18:18 +00:00
|
|
|
const gchar *name;
|
|
|
|
name = GST_OBJECT_NAME (task);
|
|
|
|
|
|
|
|
/* set the thread name to something easily identifiable */
|
|
|
|
GST_DEBUG_OBJECT (task, "Setting thread name to '%s'", name);
|
2021-01-14 16:16:34 +00:00
|
|
|
gst_task_win32_set_thread_name (name);
|
2010-10-20 08:18:18 +00:00
|
|
|
#endif
|
2010-03-15 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
static void
|
2009-04-24 10:35:08 +00:00
|
|
|
gst_task_func (GstTask * task)
|
2005-07-18 12:49:53 +00:00
|
|
|
{
|
2012-01-19 08:27:04 +00:00
|
|
|
GRecMutex *lock;
|
2006-02-13 17:03:23 +00:00
|
|
|
GThread *tself;
|
2009-04-20 15:19:21 +00:00
|
|
|
GstTaskPrivate *priv;
|
|
|
|
|
|
|
|
priv = task->priv;
|
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
|
|
|
|
2006-02-13 17:03:23 +00:00
|
|
|
tself = g_thread_self ();
|
|
|
|
|
|
|
|
GST_DEBUG ("Entering task %p, thread %p", task, tself);
|
2005-07-18 12:49:53 +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
|
|
|
/* we have to grab the lock to get the mutex. We also
|
|
|
|
* mark our state running so that nobody can mess with
|
|
|
|
* the mutex. */
|
2005-11-21 16:34:26 +00:00
|
|
|
GST_OBJECT_LOCK (task);
|
2010-10-20 09:58:06 +00:00
|
|
|
if (GET_TASK_STATE (task) == 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
|
|
|
goto exit;
|
|
|
|
lock = GST_TASK_GET_LOCK (task);
|
2006-02-13 17:03:23 +00:00
|
|
|
if (G_UNLIKELY (lock == NULL))
|
|
|
|
goto no_lock;
|
2011-02-22 15:04:12 +00:00
|
|
|
task->thread = tself;
|
2005-11-21 16:34:26 +00:00
|
|
|
GST_OBJECT_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
|
|
|
|
2012-06-20 09:59:09 +00:00
|
|
|
/* fire the enter_func callback when we need to */
|
|
|
|
if (priv->enter_func)
|
|
|
|
priv->enter_func (task, tself, priv->enter_user_data);
|
2009-04-20 15:19:21 +00:00
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
/* locking order is TASK_LOCK, LOCK */
|
2012-01-19 08:27:04 +00:00
|
|
|
g_rec_mutex_lock (lock);
|
2010-03-15 13:48:19 +00:00
|
|
|
/* configure the thread name now */
|
|
|
|
gst_task_configure_name (task);
|
|
|
|
|
2010-10-20 09:58:06 +00:00
|
|
|
while (G_LIKELY (GET_TASK_STATE (task) != GST_TASK_STOPPED)) {
|
2014-11-12 10:30:51 +00:00
|
|
|
GST_OBJECT_LOCK (task);
|
|
|
|
while (G_UNLIKELY (GST_TASK_STATE (task) == GST_TASK_PAUSED)) {
|
|
|
|
g_rec_mutex_unlock (lock);
|
|
|
|
|
|
|
|
GST_TASK_SIGNAL (task);
|
|
|
|
GST_INFO_OBJECT (task, "Task going to paused");
|
|
|
|
GST_TASK_WAIT (task);
|
|
|
|
GST_INFO_OBJECT (task, "Task resume from paused");
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
|
|
|
/* locking order.. */
|
|
|
|
g_rec_mutex_lock (lock);
|
2010-10-20 09:58:06 +00:00
|
|
|
GST_OBJECT_LOCK (task);
|
2014-11-12 10:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (GET_TASK_STATE (task) == GST_TASK_STOPPED)) {
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
|
|
|
break;
|
|
|
|
} else {
|
2005-11-21 16:34:26 +00:00
|
|
|
GST_OBJECT_UNLOCK (task);
|
2005-07-18 12:49:53 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 08:31:49 +00:00
|
|
|
task->func (task->user_data);
|
2005-07-18 12:49:53 +00:00
|
|
|
}
|
2014-11-12 10:30:51 +00:00
|
|
|
|
2012-01-19 08:27:04 +00:00
|
|
|
g_rec_mutex_unlock (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
|
|
|
|
2005-11-21 16:34:26 +00:00
|
|
|
GST_OBJECT_LOCK (task);
|
2011-02-22 15:04:12 +00:00
|
|
|
task->thread = NULL;
|
2006-08-23 16:51:19 +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
|
|
|
exit:
|
2012-06-20 09:59:09 +00:00
|
|
|
if (priv->leave_func) {
|
|
|
|
/* fire the leave_func callback when we need to. We need to do this before
|
2009-04-21 12:42:05 +00:00
|
|
|
* we signal the task and with the task lock released. */
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
2012-06-20 09:59:09 +00:00
|
|
|
priv->leave_func (task, tself, priv->leave_user_data);
|
2009-04-21 12:42:05 +00:00
|
|
|
GST_OBJECT_LOCK (task);
|
|
|
|
}
|
2009-05-25 09:56:47 +00:00
|
|
|
/* now we allow messing with the lock again by setting the running flag to
|
2014-05-29 21:54:34 +00:00
|
|
|
* %FALSE. Together with the SIGNAL this is the sign for the _join() to
|
2010-03-15 13:48:19 +00:00
|
|
|
* complete.
|
2009-05-25 09:56:47 +00:00
|
|
|
* Note that we still have not dropped the final ref on the task. We could
|
|
|
|
* check here if there is a pending join() going on and drop the last ref
|
|
|
|
* before releasing the lock as we can be sure that a ref is held by the
|
|
|
|
* caller of the join(). */
|
|
|
|
task->running = FALSE;
|
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_SIGNAL (task);
|
2005-11-21 16:34:26 +00:00
|
|
|
GST_OBJECT_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);
|
2006-02-13 17:03:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
no_lock:
|
|
|
|
{
|
|
|
|
g_warning ("starting task without a lock");
|
|
|
|
goto exit;
|
|
|
|
}
|
2005-07-18 12:49:53 +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_cleanup_all:
|
|
|
|
*
|
|
|
|
* Wait for all tasks to be stopped. This is mainly used internally
|
2008-05-26 10:07:09 +00:00
|
|
|
* to ensure proper cleanup of internal data structures in test suites.
|
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
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_task_cleanup_all (void)
|
|
|
|
{
|
|
|
|
GstTaskClass *klass;
|
|
|
|
|
|
|
|
if ((klass = g_type_class_peek (GST_TYPE_TASK))) {
|
2020-06-12 13:07:42 +00:00
|
|
|
if (klass->pool) {
|
|
|
|
g_mutex_lock (&pool_lock);
|
|
|
|
gst_task_pool_cleanup (klass->pool);
|
|
|
|
gst_object_unref (klass->pool);
|
|
|
|
klass->pool = NULL;
|
|
|
|
_global_task_pool = NULL;
|
|
|
|
g_mutex_unlock (&pool_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
|
|
|
}
|
2016-07-08 14:36:01 +00:00
|
|
|
|
|
|
|
/* GstElement owns a GThreadPool */
|
|
|
|
_priv_gst_element_cleanup ();
|
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-03-21 17:34:02 +00:00
|
|
|
/**
|
2011-10-29 07:26:49 +00:00
|
|
|
* gst_task_new:
|
2005-03-21 17:34:02 +00:00
|
|
|
* @func: The #GstTaskFunction to use
|
2012-06-20 08:31:49 +00:00
|
|
|
* @user_data: User data to pass to @func
|
|
|
|
* @notify: the function to call when @user_data is no longer needed.
|
2005-03-21 17:34:02 +00:00
|
|
|
*
|
2008-05-26 10:07:09 +00:00
|
|
|
* Create a new Task that will repeatedly call the provided @func
|
2012-06-20 08:31:49 +00:00
|
|
|
* with @user_data as a parameter. Typically the task will run in
|
2005-03-21 17:34:02 +00:00
|
|
|
* a new thread.
|
|
|
|
*
|
2006-08-23 16:51:19 +00:00
|
|
|
* The function cannot be changed after the task has been created. You
|
2008-05-26 10:07:09 +00:00
|
|
|
* must create a new #GstTask to change the function.
|
2006-08-23 16:51:19 +00:00
|
|
|
*
|
2009-05-11 21:19:53 +00:00
|
|
|
* This function will not yet create and start a thread. Use gst_task_start() or
|
|
|
|
* gst_task_pause() to create and start the GThread.
|
|
|
|
*
|
2012-11-14 11:20:54 +00:00
|
|
|
* Before the task can be used, a #GRecMutex must be configured using the
|
2009-05-11 21:19:53 +00:00
|
|
|
* gst_task_set_lock() function. This lock will always be acquired while
|
|
|
|
* @func is called.
|
|
|
|
*
|
2010-12-07 18:35:04 +00:00
|
|
|
* Returns: (transfer full): A new #GstTask.
|
2005-03-21 17:34:02 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
GstTask *
|
2012-06-20 08:31:49 +00:00
|
|
|
gst_task_new (GstTaskFunction func, gpointer user_data, GDestroyNotify notify)
|
2005-03-21 17:34:02 +00:00
|
|
|
{
|
2005-07-18 12:49:53 +00:00
|
|
|
GstTask *task;
|
|
|
|
|
2015-03-19 10:25:14 +00:00
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
2017-04-04 16:53:39 +00:00
|
|
|
task = g_object_new (GST_TYPE_TASK, NULL);
|
2005-07-18 12:49:53 +00:00
|
|
|
task->func = func;
|
2012-06-20 08:31:49 +00:00
|
|
|
task->user_data = user_data;
|
|
|
|
task->notify = notify;
|
2005-07-18 12:49:53 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("Created task %p", task);
|
|
|
|
|
2017-05-15 11:32:48 +00:00
|
|
|
/* clear floating flag */
|
|
|
|
gst_object_ref_sink (task);
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
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
|
2012-01-19 08:27:04 +00:00
|
|
|
* @mutex: The #GRecMutex to use
|
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-10-21 11:36:32 +00:00
|
|
|
* Set the mutex used by the task. The mutex will be acquired before
|
|
|
|
* calling the #GstTaskFunction.
|
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
|
|
|
*
|
2006-02-13 17:03:23 +00:00
|
|
|
* This function has to be called before calling gst_task_pause() or
|
|
|
|
* gst_task_start().
|
|
|
|
*
|
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
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2012-01-19 08:27:04 +00:00
|
|
|
gst_task_set_lock (GstTask * task, GRecMutex * 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
|
|
|
{
|
2015-03-18 10:35:34 +00:00
|
|
|
g_return_if_fail (GST_IS_TASK (task));
|
|
|
|
|
2005-11-21 16:34:26 +00:00
|
|
|
GST_OBJECT_LOCK (task);
|
2006-08-23 16:51:19 +00:00
|
|
|
if (G_UNLIKELY (task->running))
|
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
|
|
|
goto is_running;
|
2012-03-08 16:30:49 +00:00
|
|
|
GST_INFO ("setting stream lock %p on task %p", mutex, 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_GET_LOCK (task) = mutex;
|
2005-11-21 16:34:26 +00:00
|
|
|
GST_OBJECT_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:
|
|
|
|
{
|
2005-11-21 16:34:26 +00:00
|
|
|
GST_OBJECT_UNLOCK (task);
|
2006-02-13 17:03:23 +00:00
|
|
|
g_warning ("cannot call set_lock on a running 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/: 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
|
|
|
}
|
|
|
|
|
2009-04-23 15:19:11 +00:00
|
|
|
/**
|
|
|
|
* gst_task_get_pool:
|
|
|
|
* @task: a #GstTask
|
|
|
|
*
|
|
|
|
* Get the #GstTaskPool that this task will use for its streaming
|
|
|
|
* threads.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*
|
2010-12-07 18:35:04 +00:00
|
|
|
* Returns: (transfer full): the #GstTaskPool used by @task. gst_object_unref()
|
2009-04-23 15:19:11 +00:00
|
|
|
* after usage.
|
|
|
|
*/
|
|
|
|
GstTaskPool *
|
|
|
|
gst_task_get_pool (GstTask * task)
|
|
|
|
{
|
|
|
|
GstTaskPool *result;
|
|
|
|
GstTaskPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_TASK (task), NULL);
|
|
|
|
|
|
|
|
priv = task->priv;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (task);
|
|
|
|
result = gst_object_ref (priv->pool);
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_task_set_pool:
|
|
|
|
* @task: a #GstTask
|
2010-12-07 18:35:04 +00:00
|
|
|
* @pool: (transfer none): a #GstTaskPool
|
2009-04-23 15:19:11 +00:00
|
|
|
*
|
|
|
|
* Set @pool as the new GstTaskPool for @task. Any new streaming threads that
|
|
|
|
* will be created by @task will now use @pool.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_task_set_pool (GstTask * task, GstTaskPool * pool)
|
|
|
|
{
|
|
|
|
GstTaskPool *old;
|
|
|
|
GstTaskPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_TASK (task));
|
|
|
|
g_return_if_fail (GST_IS_TASK_POOL (pool));
|
|
|
|
|
|
|
|
priv = task->priv;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (task);
|
|
|
|
if (priv->pool != pool) {
|
|
|
|
old = priv->pool;
|
|
|
|
priv->pool = gst_object_ref (pool);
|
|
|
|
} else
|
|
|
|
old = NULL;
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
|
|
|
|
|
|
|
if (old)
|
|
|
|
gst_object_unref (old);
|
|
|
|
}
|
|
|
|
|
2009-05-11 21:19:53 +00:00
|
|
|
/**
|
2012-06-20 09:59:09 +00:00
|
|
|
* gst_task_set_enter_callback:
|
2009-05-11 21:19:53 +00:00
|
|
|
* @task: The #GstTask to use
|
2012-06-20 09:59:09 +00:00
|
|
|
* @enter_func: (in): a #GstTaskThreadFunc
|
|
|
|
* @user_data: user data passed to @enter_func
|
2009-05-11 21:19:53 +00:00
|
|
|
* @notify: called when @user_data is no longer referenced
|
|
|
|
*
|
2012-06-20 09:59:09 +00:00
|
|
|
* Call @enter_func when the task function of @task is entered. @user_data will
|
|
|
|
* be passed to @enter_func and @notify will be called when @user_data is no
|
|
|
|
* longer referenced.
|
2009-05-11 21:19:53 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-06-20 09:59:09 +00:00
|
|
|
gst_task_set_enter_callback (GstTask * task, GstTaskThreadFunc enter_func,
|
|
|
|
gpointer user_data, GDestroyNotify notify)
|
2009-05-11 21:19:53 +00:00
|
|
|
{
|
|
|
|
GDestroyNotify old_notify;
|
|
|
|
|
|
|
|
g_return_if_fail (task != NULL);
|
|
|
|
g_return_if_fail (GST_IS_TASK (task));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (task);
|
2012-06-20 09:59:09 +00:00
|
|
|
if ((old_notify = task->priv->enter_notify)) {
|
|
|
|
gpointer old_data = task->priv->enter_user_data;
|
|
|
|
|
|
|
|
task->priv->enter_user_data = NULL;
|
|
|
|
task->priv->enter_notify = NULL;
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
|
|
|
|
|
|
|
old_notify (old_data);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (task);
|
|
|
|
}
|
|
|
|
task->priv->enter_func = enter_func;
|
|
|
|
task->priv->enter_user_data = user_data;
|
|
|
|
task->priv->enter_notify = notify;
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
|
|
|
}
|
2009-05-11 21:19:53 +00:00
|
|
|
|
2012-06-20 09:59:09 +00:00
|
|
|
/**
|
|
|
|
* gst_task_set_leave_callback:
|
|
|
|
* @task: The #GstTask to use
|
|
|
|
* @leave_func: (in): a #GstTaskThreadFunc
|
|
|
|
* @user_data: user data passed to @leave_func
|
|
|
|
* @notify: called when @user_data is no longer referenced
|
|
|
|
*
|
|
|
|
* Call @leave_func when the task function of @task is left. @user_data will
|
|
|
|
* be passed to @leave_func and @notify will be called when @user_data is no
|
|
|
|
* longer referenced.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_task_set_leave_callback (GstTask * task, GstTaskThreadFunc leave_func,
|
|
|
|
gpointer user_data, GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
GDestroyNotify old_notify;
|
2009-05-11 21:19:53 +00:00
|
|
|
|
2012-06-20 09:59:09 +00:00
|
|
|
g_return_if_fail (task != NULL);
|
|
|
|
g_return_if_fail (GST_IS_TASK (task));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (task);
|
|
|
|
if ((old_notify = task->priv->leave_notify)) {
|
|
|
|
gpointer old_data = task->priv->leave_user_data;
|
2009-05-11 21:19:53 +00:00
|
|
|
|
2012-06-20 09:59:09 +00:00
|
|
|
task->priv->leave_user_data = NULL;
|
|
|
|
task->priv->leave_notify = NULL;
|
2009-05-11 21:19:53 +00:00
|
|
|
GST_OBJECT_UNLOCK (task);
|
|
|
|
|
|
|
|
old_notify (old_data);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (task);
|
|
|
|
}
|
2012-06-20 09:59:09 +00:00
|
|
|
task->priv->leave_func = leave_func;
|
|
|
|
task->priv->leave_user_data = user_data;
|
|
|
|
task->priv->leave_notify = notify;
|
2009-05-11 21:19:53 +00:00
|
|
|
GST_OBJECT_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);
|
|
|
|
|
2010-10-20 09:58:06 +00:00
|
|
|
result = GET_TASK_STATE (task);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-05-11 20:59:35 +00:00
|
|
|
/* make sure the task is running and start a thread if it's not.
|
|
|
|
* This function must be called with the task LOCK. */
|
|
|
|
static gboolean
|
|
|
|
start_task (GstTask * task)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GError *error = NULL;
|
2009-05-11 22:34:44 +00:00
|
|
|
GstTaskPrivate *priv;
|
|
|
|
|
|
|
|
priv = task->priv;
|
2009-05-11 20:59:35 +00:00
|
|
|
|
|
|
|
/* new task, We ref before so that it remains alive while
|
|
|
|
* the thread is running. */
|
|
|
|
gst_object_ref (task);
|
|
|
|
/* mark task as running so that a join will wait until we schedule
|
|
|
|
* and exit the task function. */
|
|
|
|
task->running = TRUE;
|
|
|
|
|
2009-04-23 15:05:21 +00:00
|
|
|
/* push on the thread pool, we remember the original pool because the user
|
|
|
|
* could change it later on and then we join to the wrong pool. */
|
|
|
|
priv->pool_id = gst_object_ref (priv->pool);
|
2009-04-24 10:35:08 +00:00
|
|
|
priv->id =
|
|
|
|
gst_task_pool_push (priv->pool_id, (GstTaskPoolFunction) gst_task_func,
|
|
|
|
task, &error);
|
2009-05-11 20:59:35 +00:00
|
|
|
|
|
|
|
if (error != NULL) {
|
|
|
|
g_warning ("failed to create thread: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-01-31 16:32:10 +00:00
|
|
|
static inline gboolean
|
|
|
|
gst_task_set_state_unlocked (GstTask * task, GstTaskState state)
|
2005-03-21 17:34:02 +00:00
|
|
|
{
|
2005-07-18 12:49:53 +00:00
|
|
|
GstTaskState old;
|
2009-05-11 20:59:35 +00:00
|
|
|
gboolean res = TRUE;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2009-05-11 20:59:35 +00:00
|
|
|
GST_DEBUG_OBJECT (task, "Changing task %p to state %d", task, state);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2009-05-11 20:59:35 +00:00
|
|
|
if (state != GST_TASK_STOPPED)
|
|
|
|
if (G_UNLIKELY (GST_TASK_GET_LOCK (task) == NULL))
|
|
|
|
goto no_lock;
|
2005-07-18 12:49:53 +00:00
|
|
|
|
2009-05-11 20:59:35 +00:00
|
|
|
/* if the state changed, do our thing */
|
2010-10-20 09:58:06 +00:00
|
|
|
old = GET_TASK_STATE (task);
|
2009-05-11 20:59:35 +00:00
|
|
|
if (old != state) {
|
2010-10-20 09:58:06 +00:00
|
|
|
SET_TASK_STATE (task, state);
|
2009-05-11 20:59:35 +00:00
|
|
|
switch (old) {
|
|
|
|
case GST_TASK_STOPPED:
|
|
|
|
/* If the task already has a thread scheduled we don't have to do
|
|
|
|
* anything. */
|
|
|
|
if (G_UNLIKELY (!task->running))
|
|
|
|
res = start_task (task);
|
|
|
|
break;
|
|
|
|
case GST_TASK_PAUSED:
|
|
|
|
/* when we are paused, signal to go to the new state */
|
|
|
|
GST_TASK_SIGNAL (task);
|
|
|
|
break;
|
|
|
|
case GST_TASK_STARTED:
|
|
|
|
/* if we were started, we'll go to the new state after the next
|
|
|
|
* iteration. */
|
2006-08-23 16:51:19 +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
|
|
|
}
|
|
|
|
|
2009-05-11 20:59:35 +00:00
|
|
|
return res;
|
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:
|
|
|
|
{
|
2009-05-11 20:59:35 +00:00
|
|
|
GST_WARNING_OBJECT (task, "state %d set on task without a lock", state);
|
|
|
|
g_warning ("task without a lock can't be set to state %d", state);
|
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 FALSE;
|
|
|
|
}
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 16:32:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_task_set_state:
|
|
|
|
* @task: a #GstTask
|
|
|
|
* @state: the new task state
|
|
|
|
*
|
|
|
|
* Sets the state of @task to @state.
|
|
|
|
*
|
|
|
|
* The @task must have a lock associated with it using
|
|
|
|
* gst_task_set_lock() when going to GST_TASK_STARTED or GST_TASK_PAUSED or
|
|
|
|
* this function will return %FALSE.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the state could be changed.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_task_set_state (GstTask * task, GstTaskState state)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_TASK (task), FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (task);
|
|
|
|
res = gst_task_set_state_unlocked (task, state);
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-05-11 20:59:35 +00:00
|
|
|
/**
|
|
|
|
* gst_task_start:
|
|
|
|
* @task: The #GstTask to start
|
|
|
|
*
|
|
|
|
* Starts @task. The @task must have a lock associated with it using
|
|
|
|
* gst_task_set_lock() or this function will return %FALSE.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the task could be started.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_task_start (GstTask * task)
|
|
|
|
{
|
|
|
|
return gst_task_set_state (task, GST_TASK_STARTED);
|
|
|
|
}
|
|
|
|
|
2005-03-21 17:34:02 +00:00
|
|
|
/**
|
|
|
|
* gst_task_stop:
|
|
|
|
* @task: The #GstTask to stop
|
|
|
|
*
|
2005-10-21 11:36:32 +00:00
|
|
|
* Stops @task. This method merely schedules the task to stop and
|
|
|
|
* will not wait for the task to have completely stopped. Use
|
2005-11-09 16:32:49 +00:00
|
|
|
* gst_task_join() to stop and wait for completion.
|
2005-03-21 17:34:02 +00:00
|
|
|
*
|
2008-05-26 10:07:09 +00:00
|
|
|
* Returns: %TRUE if the task could be stopped.
|
2005-03-21 17:34:02 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_task_stop (GstTask * task)
|
|
|
|
{
|
2009-05-11 20:59:35 +00:00
|
|
|
return gst_task_set_state (task, GST_TASK_STOPPED);
|
2005-03-21 17:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_task_pause:
|
|
|
|
* @task: The #GstTask to pause
|
|
|
|
*
|
2005-10-21 11:36:32 +00:00
|
|
|
* Pauses @task. This method can also be called on a task in the
|
|
|
|
* stopped state, in which case a thread will be started and will remain
|
|
|
|
* in the paused state. This function does not wait for the task to complete
|
|
|
|
* the paused state.
|
2005-03-21 17:34:02 +00:00
|
|
|
*
|
2008-05-26 10:07:09 +00:00
|
|
|
* Returns: %TRUE if the task could be paused.
|
2005-03-21 17:34:02 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_task_pause (GstTask * task)
|
|
|
|
{
|
2009-05-11 20:59:35 +00:00
|
|
|
return gst_task_set_state (task, GST_TASK_PAUSED);
|
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
|
|
|
|
2020-01-31 16:32:10 +00:00
|
|
|
/**
|
|
|
|
* gst_task_resume:
|
|
|
|
* @task: The #GstTask to resume
|
|
|
|
*
|
|
|
|
* Resume @task in case it was paused. If the task was stopped, it will
|
|
|
|
* remain in that state and this function will return %FALSE.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the task could be resumed.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_task_resume (GstTask * task)
|
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
g_return_val_if_fail (GST_IS_TASK (task), FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (task);
|
|
|
|
if (GET_TASK_STATE (task) != GST_TASK_STOPPED)
|
|
|
|
res = gst_task_set_state_unlocked (task, GST_TASK_STARTED);
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
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
|
2005-11-09 16:32:49 +00:00
|
|
|
* and clean up the lock set with gst_task_set_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
|
|
|
*
|
|
|
|
* The task will automatically be stopped with this call.
|
|
|
|
*
|
2005-10-21 11:36:32 +00:00
|
|
|
* This function cannot be called from within a task function as this
|
2010-03-15 13:48:19 +00:00
|
|
|
* would cause a deadlock. The function will detect this and print a
|
2006-08-23 16:51:19 +00:00
|
|
|
* g_warning.
|
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
|
|
|
*
|
2008-05-26 10:07:09 +00:00
|
|
|
* Returns: %TRUE if the task could be joined.
|
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
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_task_join (GstTask * task)
|
|
|
|
{
|
2009-05-11 22:34:44 +00:00
|
|
|
GThread *tself;
|
2009-05-11 22:25:11 +00:00
|
|
|
GstTaskPrivate *priv;
|
|
|
|
gpointer id;
|
|
|
|
GstTaskPool *pool = 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_return_val_if_fail (GST_IS_TASK (task), FALSE);
|
|
|
|
|
2015-03-18 10:35:34 +00:00
|
|
|
priv = task->priv;
|
|
|
|
|
2006-02-13 17:03:23 +00:00
|
|
|
tself = g_thread_self ();
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (task, "Joining task %p, thread %p", task, tself);
|
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
|
|
|
|
2006-08-14 07:35:09 +00:00
|
|
|
/* we don't use a real thread join here because we are using
|
2008-05-26 10:07:09 +00:00
|
|
|
* thread pools */
|
2005-11-21 16:34:26 +00:00
|
|
|
GST_OBJECT_LOCK (task);
|
2011-02-22 15:04:12 +00:00
|
|
|
if (G_UNLIKELY (tself == task->thread))
|
2006-02-13 17:03:23 +00:00
|
|
|
goto joining_self;
|
2010-10-20 09:58:06 +00:00
|
|
|
SET_TASK_STATE (task, GST_TASK_STOPPED);
|
2006-08-23 16:51:19 +00:00
|
|
|
/* signal the state change for when it was blocked in 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
|
|
|
GST_TASK_SIGNAL (task);
|
2008-05-26 10:07:09 +00:00
|
|
|
/* we set the running flag when pushing the task on the thread pool.
|
2006-08-23 16:51:19 +00:00
|
|
|
* This means that the task function might not be called when we try
|
|
|
|
* to join it here. */
|
|
|
|
while (G_LIKELY (task->running))
|
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_WAIT (task);
|
2009-05-11 22:25:11 +00:00
|
|
|
/* clean the thread */
|
2011-02-22 15:04:12 +00:00
|
|
|
task->thread = NULL;
|
2009-05-11 22:25:11 +00:00
|
|
|
/* get the id and pool to join */
|
2009-07-20 13:44:36 +00:00
|
|
|
pool = priv->pool_id;
|
|
|
|
id = priv->id;
|
|
|
|
priv->pool_id = NULL;
|
|
|
|
priv->id = NULL;
|
2005-11-21 16:34:26 +00:00
|
|
|
GST_OBJECT_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
|
|
|
|
2009-05-11 22:25:11 +00:00
|
|
|
if (pool) {
|
2009-07-20 13:44:36 +00:00
|
|
|
if (id)
|
|
|
|
gst_task_pool_join (pool, id);
|
2009-05-11 22:25:11 +00:00
|
|
|
gst_object_unref (pool);
|
|
|
|
}
|
|
|
|
|
2005-11-12 10:03:08 +00:00
|
|
|
GST_DEBUG_OBJECT (task, "Joined task %p", 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 TRUE;
|
2006-02-13 17:03:23 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
joining_self:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (task, "trying to join task from its thread");
|
|
|
|
GST_OBJECT_UNLOCK (task);
|
2006-08-23 16:51:19 +00:00
|
|
|
g_warning ("\nTrying to join task %p from its thread would deadlock.\n"
|
|
|
|
"You cannot change the state of an element from its streaming\n"
|
|
|
|
"thread. Use g_idle_add() or post a GstMessage on the bus to\n"
|
|
|
|
"schedule the state change from the main thread.\n", task);
|
2006-02-13 17:03:23 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
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
|
|
|
}
|