コード例 #1
0
ファイル: utility.cpp プロジェクト: DGLSBC/jabs-clock
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void g_expri_thread(int inc)
{
#if _USEGTK
	GThreadPriority tp = inc < 0 ? G_THREAD_PRIORITY_HIGH : (inc > 0 ? G_THREAD_PRIORITY_LOW : G_THREAD_PRIORITY_NORMAL);
	g_thread_set_priority(g_thread_self(), tp);
#endif
}
コード例 #2
0
ファイル: athread.c プロジェクト: alex1818/aqualung
void
set_thread_priority(GThread * thread, const gchar * name, gboolean realtime,
		    gint priority) {

	if (realtime)
		g_thread_set_priority(thread, G_THREAD_PRIORITY_URGENT);

}
コード例 #3
0
gpointer rtp_scheduler_schedule(gpointer psched)
{
	RtpScheduler *sched=(RtpScheduler*) psched;
	RtpTimer *timer=sched->timer;
	RtpSession *current;
	int err;

	/* try to get the real time priority by getting root*/
#ifndef _WIN32
#ifdef HAVE_SETEUID
	err=seteuid(0);
#else
	err=setuid(0);
#endif
	if (err<0) g_message("Could not get root euid: %s",strerror(errno));
#endif
	g_message("scheduler: trying to reach real time kernel scheduling...");

	/* take this lock to prevent the thread to start until g_thread_create() returns
		because we need sched->thread to be initialized */
	g_mutex_lock(sched->lock);
	g_cond_signal(sched->unblock_select_cond);	/* unblock the starting thread */
	g_mutex_unlock(sched->lock);
	g_thread_set_priority(sched->thread,G_THREAD_PRIORITY_HIGH);
	timer->timer_init();
	while(sched->thread_running)
	{
		/* do the processing here: */
		
		g_mutex_lock(sched->lock);
		
		current=sched->list;
		/* processing all scheduled rtp sessions */
		while (current!=NULL)
		{
			ortp_debug("scheduler: processing session=%p.\n",current);
			rtp_session_process(current,sched->time_,sched);
			current=current->next;
		}
		/* wake up all the threads that are sleeping in _select()  */
		g_cond_broadcast(sched->unblock_select_cond);
		g_mutex_unlock(sched->lock);
		
		/* now while the scheduler is going to sleep, the other threads can compute their
		result mask and see if they have to leave, or to wait for next tick*/
		//g_message("scheduler: sleeping.");
		timer->timer_do();
		sched->time_+=sched->timer_inc;
	}
	/* when leaving the thread, stop the timer */
	timer->timer_uninit();
	return NULL;
}
コード例 #4
0
void ThreadClass::setPriority ( unsigned char pri )
{
    GThreadPriority priority = G_THREAD_PRIORITY_NORMAL;

    if ( pri == PRI_LOW )
        priority = G_THREAD_PRIORITY_LOW;
    else if ( pri == PRI_HIGH )
        priority = G_THREAD_PRIORITY_HIGH; 

    if ( ThreadId_ != NULL )
        g_thread_set_priority ( ThreadId_, priority ) ;
}
コード例 #5
0
ファイル: gsttask.c プロジェクト: genesi/gstreamer
/**
 * 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);
}
コード例 #6
0
ファイル: gsttask.c プロジェクト: genesi/gstreamer
static void
gst_task_func (GstTask * task)
{
  GStaticRecMutex *lock;
  GThread *tself;
  GstTaskPrivate *priv;

  priv = task->priv;

  tself = g_thread_self ();

  GST_DEBUG ("Entering task %p, thread %p", task, tself);

  /* we have to grab the lock to get the mutex. We also
   * mark our state running so that nobody can mess with
   * the mutex. */
  GST_OBJECT_LOCK (task);
  if (task->state == GST_TASK_STOPPED)
    goto exit;
  lock = GST_TASK_GET_LOCK (task);
  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 */
  if (priv->thr_callbacks.enter_thread)
    priv->thr_callbacks.enter_thread (task, tself, priv->thr_user_data);

  /* locking order is TASK_LOCK, LOCK */
  g_static_rec_mutex_lock (lock);
  GST_OBJECT_LOCK (task);
  /* configure the thread name now */
  gst_task_configure_name (task);

  while (G_LIKELY (task->state != GST_TASK_STOPPED)) {
    while (G_UNLIKELY (task->state == GST_TASK_PAUSED)) {
      gint t;

      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);

      GST_OBJECT_LOCK (task);
      if (G_UNLIKELY (task->state == GST_TASK_STOPPED))
        goto done;
    }
    GST_OBJECT_UNLOCK (task);

    task->func (task->data);

    GST_OBJECT_LOCK (task);
  }
done:
  GST_OBJECT_UNLOCK (task);
  g_static_rec_mutex_unlock (lock);

  GST_OBJECT_LOCK (task);
  task->abidata.ABI.thread = NULL;

exit:
  if (priv->thr_callbacks.leave_thread) {
    /* fire the leave_thread callback when we need to. We need to do this before
     * we signal the task and with the task lock released. */
    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
   * complete.
   * Note that we still have not dropped the final ref on the task. We could
   * check here if there is a pending join() going on and drop the last ref
   * before releasing the lock as we can be sure that a ref is held by the
   * caller of the join(). */
  task->running = FALSE;
  GST_TASK_SIGNAL (task);
  GST_OBJECT_UNLOCK (task);

  GST_DEBUG ("Exit task %p, thread %p", task, g_thread_self ());

  gst_object_unref (task);
  return;

no_lock:
  {
    g_warning ("starting task without a lock");
    goto exit;
  }
}