Beispiel #1
0
/**
 * gst_task_pool_join:
 * @pool: a #GstTaskPool
 * @id: the id
 *
 * 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, gpointer id)
{
  GstTaskPoolClass *klass;

  g_return_if_fail (GST_IS_TASK_POOL (pool));

  klass = GST_TASK_POOL_GET_CLASS (pool);

  if (klass->join)
    klass->join (pool, id);
}
Beispiel #2
0
/**
 * gst_task_pool_cleanup:
 * @pool: a #GstTaskPool
 *
 * Wait for all tasks to be stopped. This is mainly used internally
 * to ensure proper cleanup of internal data structures in test suites.
 *
 * MT safe.
 */
void
gst_task_pool_cleanup (GstTaskPool * pool)
{
  GstTaskPoolClass *klass;

  g_return_if_fail (GST_IS_TASK_POOL (pool));

  klass = GST_TASK_POOL_GET_CLASS (pool);

  if (klass->cleanup)
    klass->cleanup (pool);
}
Beispiel #3
0
/**
 * gst_task_pool_prepare:
 * @pool: a #GstTaskPool
 * @error: an error return location
 *
 * Prepare the taskpool for accepting gst_task_pool_push() operations.
 *
 * MT safe.
 */
void
gst_task_pool_prepare (GstTaskPool * pool, GError ** error)
{
  GstTaskPoolClass *klass;

  g_return_if_fail (GST_IS_TASK_POOL (pool));

  klass = GST_TASK_POOL_GET_CLASS (pool);

  if (klass->prepare)
    klass->prepare (pool, error);
}
Beispiel #4
0
GMainContext *
gst_task_pool_get_schedule_context (GstTaskPool * pool)
{
  GMainContext *context;

  g_return_val_if_fail (GST_IS_TASK_POOL (pool), NULL);
  g_return_val_if_fail (pool->priv->need_schedule_thread > 0, NULL);

  g_mutex_lock (&pool->priv->schedule_lock);
  context = pool->priv->schedule_context;
  if (context)
    g_main_context_ref (context);
  g_mutex_unlock (&pool->priv->schedule_lock);

  return context;
}
Beispiel #5
0
gboolean
gst_task_pool_need_schedule_thread (GstTaskPool * pool, gboolean needed)
{
  gboolean ret;

  g_return_val_if_fail (GST_IS_TASK_POOL (pool), FALSE);
  g_return_val_if_fail (needed || pool->priv->need_schedule_thread > 0, FALSE);

  /* We don't allow this for the default pool */
  if (pool == gst_task_pool_get_default ()) {
    gst_object_unref (pool);
    return FALSE;
  }

  g_mutex_lock (&pool->priv->schedule_lock);
  if (needed) {
    ret = TRUE;
    if (pool->priv->need_schedule_thread == 0) {
      pool->priv->schedule_context = g_main_context_new ();
      pool->priv->schedule_loop =
          g_main_loop_new (pool->priv->schedule_context, FALSE);

      pool->priv->schedule_thread =
          g_thread_new (GST_OBJECT_NAME (pool), gst_task_pool_schedule_func,
          pool);

      g_cond_wait (&pool->priv->schedule_cond, &pool->priv->schedule_lock);
    }
    pool->priv->need_schedule_thread++;
  } else {
    ret = FALSE;
    pool->priv->need_schedule_thread--;
    if (pool->priv->need_schedule_thread == 0) {
      g_main_loop_quit (pool->priv->schedule_loop);
      g_thread_join (pool->priv->schedule_thread);
      g_main_loop_unref (pool->priv->schedule_loop);
      pool->priv->schedule_loop = NULL;
      g_main_context_unref (pool->priv->schedule_context);
      pool->priv->schedule_context = NULL;
      pool->priv->schedule_thread = NULL;
    }
  }
  g_mutex_unlock (&pool->priv->schedule_lock);

  return ret;
}
Beispiel #6
0
/**
 * gst_task_pool_push:
 * @pool: a #GstTaskPool
 * @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: (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.
 */
gpointer
gst_task_pool_push (GstTaskPool * pool, GstTaskPoolFunction func,
    gpointer user_data, GError ** error)
{
  GstTaskPoolClass *klass;

  g_return_val_if_fail (GST_IS_TASK_POOL (pool), NULL);

  klass = GST_TASK_POOL_GET_CLASS (pool);

  if (klass->push == NULL)
    goto not_supported;

  return klass->push (pool, func, user_data, error);

  /* ERRORS */
not_supported:
  {
    g_warning ("pushing tasks on pool %p is not supported", pool);
    return NULL;
  }
}
Beispiel #7
0
/**
 * gst_task_set_pool:
 * @task: a #GstTask
 * @pool: a #GstTaskPool
 *
 * Set @pool as the new GstTaskPool for @task. Any new streaming threads that
 * will be created by @task will now use @pool.
 *
 * MT safe.
 *
 * Since: 0.10.24
 */
void
gst_task_set_pool (GstTask * task, GstTaskPool * pool)
{
  GstTaskPool *old;
  GstTaskPrivate *priv;

  g_return_if_fail (GST_IS_TASK (task));
  g_return_if_fail (GST_IS_TASK_POOL (pool));

  priv = task->priv;

  GST_OBJECT_LOCK (task);
  if (priv->pool != pool) {
    old = priv->pool;
    priv->pool = gst_object_ref (pool);
  } else
    old = NULL;
  GST_OBJECT_UNLOCK (task);

  if (old)
    gst_object_unref (old);
}