Exemplo n.º 1
0
static void *
tasklet_thread ( void *aux )
{
  tasklet_t *tsk;

  tvhtread_renice(20);

  pthread_mutex_lock(&tasklet_lock);
  while (tvheadend_running) {
    tsk = TAILQ_FIRST(&tasklets);
    if (tsk == NULL) {
      pthread_cond_wait(&tasklet_cond, &tasklet_lock);
      continue;
    }
    if (tsk->tsk_callback) {
      tsk->tsk_callback(tsk->tsk_opaque, 0);
      tsk->tsk_callback = NULL;
    }
    TAILQ_REMOVE(&tasklets, tsk, tsk_link);
    if (tsk->tsk_allocated)
      free(tsk);
  }
  pthread_mutex_unlock(&tasklet_lock);

  return NULL;
}
Exemplo n.º 2
0
static void *
tasklet_thread ( void *aux )
{
  tasklet_t *tsk;
  tsk_callback_t *tsk_cb;
  void *opaque;

  tvhtread_renice(20);

  pthread_mutex_lock(&tasklet_lock);
  while (tvheadend_is_running()) {
    tsk = TAILQ_FIRST(&tasklets);
    if (tsk == NULL) {
      tvh_cond_wait(&tasklet_cond, &tasklet_lock);
      continue;
    }
    /* the callback might re-initialize tasklet, save everythin */
    TAILQ_REMOVE(&tasklets, tsk, tsk_link);
    tsk_cb = tsk->tsk_callback;
    opaque = tsk->tsk_opaque;
    tsk->tsk_callback = NULL;
    if (tsk->tsk_allocated) {
      memoryinfo_free(&tasklet_memoryinfo, sizeof(*tsk));
      free(tsk);
    }
    /* now, the callback can be safely called */
    if (tsk_cb) {
      pthread_mutex_unlock(&tasklet_lock);
      tsk_cb(opaque, 0);
      pthread_mutex_lock(&tasklet_lock);
    }
  }
  pthread_mutex_unlock(&tasklet_lock);

  return NULL;
}