Task: add method to set the priority

Add a method to configure a priority for the threads used by GstTask.
This commit is contained in:
Wim Taymans 2009-04-21 19:15:48 +02:00 committed by Wim Taymans
parent 2aaf72d259
commit 2d8a22c1da
4 changed files with 49 additions and 0 deletions

View file

@ -2185,6 +2185,7 @@ GST_TASK_WAIT
gst_task_create
gst_task_set_lock
gst_task_set_priority
GstTaskThreadCallbacks
gst_task_set_thread_callbacks

View file

@ -76,6 +76,9 @@ struct _GstTaskPrivate
GstTaskThreadCallbacks thr_callbacks;
gpointer thr_user_data;
GDestroyNotify thr_notify;
gboolean prio_set;
GThreadPriority priority;
};
static void gst_task_class_init (GstTaskClass * klass);
@ -117,6 +120,7 @@ gst_task_init (GstTask * task)
task->lock = NULL;
task->cond = g_cond_new ();
task->state = GST_TASK_STOPPED;
task->priv->prio_set = FALSE;
}
static void
@ -163,6 +167,9 @@ gst_task_func (GstTask * task, GstTaskClass * tclass)
if (G_UNLIKELY (lock == NULL))
goto no_lock;
task->abidata.ABI.thread = tself;
/* only update the priority when it was changed */
if (priv->prio_set)
g_thread_set_priority (tself, priv->priority);
GST_OBJECT_UNLOCK (task);
/* fire the enter_thread callback when we need to */
@ -219,6 +226,10 @@ exit:
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);
}
GST_TASK_SIGNAL (task);
GST_OBJECT_UNLOCK (task);
@ -333,6 +344,41 @@ is_running:
}
}
/**
* gst_task_set_priority:
* @task: a #GstTask
* @priority: a new priority for @task
*
* Changes the priority of @task to @priority.
*
* Note: try not to depend on task priorities.
*
* MT safe.
*
* Since: 0.10.24
*/
void
gst_task_set_priority (GstTask * task, GThreadPriority priority)
{
GstTaskPrivate *priv;
GThread *thread;
g_return_if_fail (GST_IS_TASK (task));
priv = task->priv;
GST_OBJECT_LOCK (task);
priv->prio_set = TRUE;
priv->priority = priority;
thread = task->abidata.ABI.thread;
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_OBJECT_UNLOCK (task);
}
/**
* gst_task_set_thread_callbacks:
* @task: The #GstTask to use

View file

@ -180,6 +180,7 @@ GType gst_task_get_type (void);
GstTask* gst_task_create (GstTaskFunction func, gpointer data);
void gst_task_set_lock (GstTask *task, GStaticRecMutex *mutex);
void gst_task_set_priority (GstTask *task, GThreadPriority priority);
void gst_task_set_thread_callbacks (GstTask *task,
GstTaskThreadCallbacks *callbacks,

View file

@ -944,6 +944,7 @@ EXPORTS
gst_task_join
gst_task_pause
gst_task_set_lock
gst_task_set_priority
gst_task_set_state
gst_task_set_thread_callbacks
gst_task_start