*
* 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.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
/**
* SECTION:gsttaskpool
+ * @title: GstTaskPool
* @short_description: Pool of GStreamer streaming threads
* @see_also: #GstTask, #GstPad
*
* implementation uses a regular GThreadPool to start tasks.
*
* Subclasses can be made to create custom threads.
- *
- * Last reviewed on 2009-04-23 (0.10.24)
*/
#include "gst_private.h"
#include "gstinfo.h"
#include "gsttaskpool.h"
+#include "gsterror.h"
GST_DEBUG_CATEGORY_STATIC (taskpool_debug);
#define GST_CAT_DEFAULT (taskpool_debug)
-static void gst_task_pool_class_init (GstTaskPoolClass * klass);
-static void gst_task_pool_init (GstTaskPool * pool);
+#ifndef GST_DISABLE_GST_DEBUG
static void gst_task_pool_finalize (GObject * object);
+#endif
#define _do_init \
{ \
G_DEFINE_TYPE_WITH_CODE (GstTaskPool, gst_task_pool, GST_TYPE_OBJECT, _do_init);
+typedef struct
+{
+ GstTaskPoolFunction func;
+ gpointer user_data;
+} TaskData;
+
+static void
+default_func (TaskData * tdata, GstTaskPool * pool)
+{
+ GstTaskPoolFunction func;
+ gpointer user_data;
+
+ func = tdata->func;
+ user_data = tdata->user_data;
+ g_slice_free (TaskData, tdata);
+
+ func (user_data);
+}
+
static void
-default_prepare (GstTaskPool * pool, GFunc func, gpointer user_data,
- GError ** error)
+default_prepare (GstTaskPool * pool, GError ** error)
{
GST_OBJECT_LOCK (pool);
- pool->pool = g_thread_pool_new ((GFunc) func, user_data, -1, FALSE, NULL);
+ pool->pool = g_thread_pool_new ((GFunc) default_func, pool, -1, FALSE, error);
GST_OBJECT_UNLOCK (pool);
}
static void
default_cleanup (GstTaskPool * pool)
{
+ GThreadPool *pool_;
+
GST_OBJECT_LOCK (pool);
- if (pool->pool) {
+ pool_ = pool->pool;
+ pool->pool = NULL;
+ GST_OBJECT_UNLOCK (pool);
+
+ if (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 (pool->pool, FALSE, TRUE);
- pool->pool = NULL;
+ g_thread_pool_free (pool_, FALSE, TRUE);
}
- GST_OBJECT_UNLOCK (pool);
}
-static GThread *
-default_push (GstTaskPool * pool, gpointer data, GError ** error)
+static gpointer
+default_push (GstTaskPool * pool, GstTaskPoolFunction func,
+ gpointer user_data, GError ** error)
{
+ TaskData *tdata;
+
+ tdata = g_slice_new (TaskData);
+ tdata->func = func;
+ tdata->user_data = user_data;
+
GST_OBJECT_LOCK (pool);
if (pool->pool)
- g_thread_pool_push (pool->pool, data, error);
+ g_thread_pool_push (pool->pool, tdata, error);
+ else {
+ g_slice_free (TaskData, tdata);
+ g_set_error_literal (error, GST_CORE_ERROR, GST_CORE_ERROR_FAILED,
+ "No thread pool");
+
+ }
GST_OBJECT_UNLOCK (pool);
return NULL;
}
static void
-default_join (GstTaskPool * pool, GThread * thread)
+default_join (GstTaskPool * pool, gpointer id)
{
- /* does nothing, we can't join for threads from the threadpool */
+ /* we do nothing here, we can't join from the pools */
}
static void
gobject_class = (GObjectClass *) klass;
gsttaskpool_class = (GstTaskPoolClass *) klass;
- gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_task_pool_finalize);
+#ifndef GST_DISABLE_GST_DEBUG
+ gobject_class->finalize = gst_task_pool_finalize;
+#endif
gsttaskpool_class->prepare = default_prepare;
gsttaskpool_class->cleanup = default_cleanup;
{
}
+#ifndef GST_DISABLE_GST_DEBUG
static void
gst_task_pool_finalize (GObject * object)
{
- GstTaskPool *pool = GST_TASK_POOL (object);
-
- GST_DEBUG ("taskpool %p finalize", pool);
+ GST_DEBUG ("taskpool %p finalize", object);
G_OBJECT_CLASS (gst_task_pool_parent_class)->finalize (object);
}
-
+#endif
/**
* gst_task_pool_new:
*
* Create a new default task pool. The default task pool will use a regular
* GThreadPool for threads.
*
- * Returns: a new #GstTaskPool. gst_object_unref() after usage.
+ * Returns: (transfer full): a new #GstTaskPool. gst_object_unref() after usage.
*/
GstTaskPool *
gst_task_pool_new (void)
pool = g_object_new (GST_TYPE_TASK_POOL, NULL);
- return pool;
-}
+ /* clear floating flag */
+ gst_object_ref_sink (pool);
-void
-gst_task_pool_set_func (GstTaskPool * pool, GFunc func, gpointer user_data)
-{
- g_return_if_fail (GST_IS_TASK_POOL (pool));
-
- pool->func = func;
- pool->user_data = user_data;
+ return pool;
}
-
/**
* gst_task_pool_prepare:
* @pool: a #GstTaskPool
klass = GST_TASK_POOL_GET_CLASS (pool);
if (klass->prepare)
- klass->prepare (pool, pool->func, pool->user_data, error);
+ klass->prepare (pool, error);
}
/**
/**
* gst_task_pool_push:
* @pool: a #GstTaskPool
- * @data: data to pass to the thread function
+ * @func: (scope async): the function to call
+ * @user_data: (closure): data to pass to @func
* @error: return location for an error
*
* Start the execution of a new thread from @pool.
*
- * Returns: a #GThread or NULL when the GThread is not yet known. You must check
- * @error to detect errors.
+ * Returns: (transfer none) (nullable): a pointer that should be used
+ * for the gst_task_pool_join function. This pointer can be %NULL, you
+ * must check @error to detect errors.
*/
-GThread *
-gst_task_pool_push (GstTaskPool * pool, gpointer data, GError ** error)
+gpointer
+gst_task_pool_push (GstTaskPool * pool, GstTaskPoolFunction func,
+ gpointer user_data, GError ** error)
{
GstTaskPoolClass *klass;
if (klass->push == NULL)
goto not_supported;
- return klass->push (pool, data, error);
+ return klass->push (pool, func, user_data, error);
/* ERRORS */
not_supported:
/**
* gst_task_pool_join:
* @pool: a #GstTaskPool
- * @thread: a #GThread
+ * @id: the id
*
- * Join a GThread or return it to the pool.
+ * Join a task and/or return it to the pool. @id is the id obtained from
+ * gst_task_pool_push().
*/
void
-gst_task_pool_join (GstTaskPool * pool, GThread * thread)
+gst_task_pool_join (GstTaskPool * pool, gpointer id)
{
GstTaskPoolClass *klass;
klass = GST_TASK_POOL_GET_CLASS (pool);
if (klass->join)
- klass->join (pool, thread);
+ klass->join (pool, id);
}