Task: add method to set the priority
authorWim Taymans <wim.taymans@collabora.co.uk>
Tue, 21 Apr 2009 17:15:48 +0000 (19:15 +0200)
committerWim Taymans <wim@metal.(none)>
Mon, 11 May 2009 22:08:35 +0000 (00:08 +0200)
Add a method to configure a priority for the threads used by GstTask.

docs/gst/gstreamer-sections.txt
gst/gsttask.c
gst/gsttask.h
win32/common/libgstreamer.def

index 83bfa67..c696d89 100644 (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
index 94bda1b..f93eea0 100644 (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);
@@ -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
index 2669693..afeeed9 100644 (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,
index 19eab26..b2c1743 100644 (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