* and gst_task_stop() respectively or with the gst_task_set_state() function.
*
* A #GstTask will repeatedly call the #GstTaskFunction with the user data
- * that was provided when creating the task with gst_task_create(). While calling
+ * that was provided when creating the task with gst_task_new(). While calling
* the function it will acquire the provided lock. The provided lock is released
* when the task pauses or stops.
*
#include "gstinfo.h"
#include "gsttask.h"
+#include "glib-compat-private.h"
#include <stdio.h>
#define GST_CAT_DEFAULT (task_debug)
#define SET_TASK_STATE(t,s) (g_atomic_int_set (&GST_TASK_STATE(t), (s)))
-#define GET_TASK_STATE(t) (g_atomic_int_get (&GST_TASK_STATE(t)))
+#define GET_TASK_STATE(t) ((GstTaskState) g_atomic_int_get (&GST_TASK_STATE(t)))
#define GST_TASK_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_TASK, GstTaskPrivate))
static void gst_task_func (GstTask * task);
-static GStaticMutex pool_lock = G_STATIC_MUTEX_INIT;
+static GMutex pool_lock;
#define _do_init \
{ \
static void
init_klass_pool (GstTaskClass * klass)
{
- g_static_mutex_lock (&pool_lock);
+ g_mutex_lock (&pool_lock);
if (klass->pool) {
gst_task_pool_cleanup (klass->pool);
gst_object_unref (klass->pool);
}
klass->pool = gst_task_pool_new ();
gst_task_pool_prepare (klass->pool, NULL);
- g_static_mutex_unlock (&pool_lock);
+ g_mutex_unlock (&pool_lock);
}
static void
task->running = FALSE;
task->thread = NULL;
task->lock = NULL;
- task->cond = g_cond_new ();
+ g_cond_init (&task->cond);
SET_TASK_STATE (task, GST_TASK_STOPPED);
task->priv->prio_set = FALSE;
/* use the default klass pool for this task, users can
* override this later */
- g_static_mutex_lock (&pool_lock);
+ g_mutex_lock (&pool_lock);
task->priv->pool = gst_object_ref (klass->pool);
- g_static_mutex_unlock (&pool_lock);
+ g_mutex_unlock (&pool_lock);
}
static void
/* task thread cannot be running here since it holds a ref
* to the task so that the finalize could not have happened */
- g_cond_free (task->cond);
- task->cond = NULL;
+ g_cond_clear (&task->cond);
G_OBJECT_CLASS (gst_task_parent_class)->finalize (object);
}
static void
gst_task_configure_name (GstTask * task)
{
-#ifdef HAVE_SYS_PRCTL_H
+#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME)
const gchar *name;
gchar thread_name[17] = { 0, };
static void
gst_task_func (GstTask * task)
{
- GStaticRecMutex *lock;
+ GRecMutex *lock;
GThread *tself;
GstTaskPrivate *priv;
goto no_lock;
task->thread = tself;
/* only update the priority when it was changed */
- if (priv->prio_set)
- g_thread_set_priority (tself, priv->priority);
+ if (priv->prio_set) {
+ GST_INFO_OBJECT (task, "Thread priorities no longer have any effect");
+ }
GST_OBJECT_UNLOCK (task);
/* fire the enter_thread callback when we need to */
priv->thr_callbacks.enter_thread (task, tself, priv->thr_user_data);
/* locking order is TASK_LOCK, LOCK */
- g_static_rec_mutex_lock (lock);
+ g_rec_mutex_lock (lock);
/* configure the thread name now */
gst_task_configure_name (task);
if (G_UNLIKELY (GET_TASK_STATE (task) == GST_TASK_PAUSED)) {
GST_OBJECT_LOCK (task);
while (G_UNLIKELY (GST_TASK_STATE (task) == GST_TASK_PAUSED)) {
- gint t;
+ g_rec_mutex_unlock (lock);
- t = g_static_rec_mutex_unlock_full (lock);
- if (t <= 0) {
- g_warning ("wrong STREAM_LOCK count %d", t);
- }
GST_TASK_SIGNAL (task);
GST_TASK_WAIT (task);
GST_OBJECT_UNLOCK (task);
/* locking order.. */
- if (t > 0)
- g_static_rec_mutex_lock_full (lock, t);
+ g_rec_mutex_lock (lock);
GST_OBJECT_LOCK (task);
if (G_UNLIKELY (GET_TASK_STATE (task) == GST_TASK_STOPPED)) {
task->func (task->data);
}
done:
- g_static_rec_mutex_unlock (lock);
+ g_rec_mutex_unlock (lock);
GST_OBJECT_LOCK (task);
task->thread = NULL;
GST_OBJECT_UNLOCK (task);
priv->thr_callbacks.leave_thread (task, tself, priv->thr_user_data);
GST_OBJECT_LOCK (task);
- } else {
- /* restore normal priority when releasing back into the pool, we will not
- * touch the priority when a custom callback has been installed. */
- g_thread_set_priority (tself, G_THREAD_PRIORITY_NORMAL);
}
/* now we allow messing with the lock again by setting the running flag to
* FALSE. Together with the SIGNAL this is the sign for the _join() to
}
/**
- * gst_task_create:
+ * gst_task_new:
* @func: The #GstTaskFunction to use
* @data: (closure): User data to pass to @func
*
* MT safe.
*/
GstTask *
-gst_task_create (GstTaskFunction func, gpointer data)
+gst_task_new (GstTaskFunction func, gpointer data)
{
GstTask *task;
/**
* gst_task_set_lock:
* @task: The #GstTask to use
- * @mutex: The #GMutex to use
+ * @mutex: The #GRecMutex to use
*
* Set the mutex used by the task. The mutex will be acquired before
* calling the #GstTaskFunction.
* MT safe.
*/
void
-gst_task_set_lock (GstTask * task, GStaticRecMutex * mutex)
+gst_task_set_lock (GstTask * task, GRecMutex * mutex)
{
GST_OBJECT_LOCK (task);
if (G_UNLIKELY (task->running))
*
* Since: 0.10.24
*/
+/* FIXME 0.11: remove gst_task_set_priority() */
void
gst_task_set_priority (GstTask * task, GThreadPriority priority)
{
if (thread != NULL) {
/* if this task already has a thread, we can configure the priority right
* away, else we do that when we assign a thread to the task. */
- g_thread_set_priority (thread, priority);
+ GST_INFO_OBJECT (task, "Thread priorities no longer have any effect");
}
GST_OBJECT_UNLOCK (task);
}