diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-04-21 19:15:48 +0200 |
---|---|---|
committer | Wim Taymans <wim@metal.(none)> | 2009-05-12 00:08:35 +0200 |
commit | 2d8a22c1da74eecb144fe5f554124e38f81c1337 (patch) | |
tree | d2736a06a5e382a4ad8e3ba214e417825c242e77 | |
parent | 2aaf72d259701c4437b7c24e4903084b93bdb79b (diff) |
Task: add method to set the priority
Add a method to configure a priority for the threads used by GstTask.
-rw-r--r-- | docs/gst/gstreamer-sections.txt | 1 | ||||
-rw-r--r-- | gst/gsttask.c | 46 | ||||
-rw-r--r-- | gst/gsttask.h | 1 | ||||
-rw-r--r-- | win32/common/libgstreamer.def | 1 |
4 files changed, 49 insertions, 0 deletions
diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 83bfa677e9..c696d89759 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -2185,6 +2185,7 @@ GST_TASK_WAIT gst_task_create gst_task_set_lock +gst_task_set_priority GstTaskThreadCallbacks gst_task_set_thread_callbacks diff --git a/gst/gsttask.c b/gst/gsttask.c index 94bda1b3d2..f93eea0ac5 100644 --- a/gst/gsttask.c +++ b/gst/gsttask.c @@ -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); @@ -334,6 +345,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 * @callbacks: a #GstTaskThreadCallbacks pointer diff --git a/gst/gsttask.h b/gst/gsttask.h index 2669693931..afeeed9ff7 100644 --- a/gst/gsttask.h +++ b/gst/gsttask.h @@ -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, diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index 19eab261ad..b2c1743321 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -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 |