예제 #1
0
void runAtTime(void (*schedFunc)(void), struct timeval *tv) {
  struct timeval now;
  struct TimedTask *t;

  getTime(&now);
  if (is_time_earlier(tv, &now)) {
    // error, can't schedule earlier than now
    printf("ERROR: UNABLE TO SCHEDULE TASK DURING PAST TIME\n\r");
    return;
  }

  t = (struct TimedTask *) malloc(sizeof(struct TimedTask));
  t->task = schedFunc;
  t->time = (struct timeval *) malloc(sizeof(struct timeval));
  memcpy(t->time, tv, sizeof(struct timeval));
  t->next_task = NULL;
  t->prev_task = NULL;

  enable_timed_task();
  insert_timed_task(&task_list, t);
  set_task_interrupt(task_list->time);
}
예제 #2
0
int dispatch_timed_task(

  work_task *ptask)

  {
  int rc = PBSE_NONE;

  if (can_dispatch_task() == false)
    {
    insert_timed_task(ptask);
    rc = PBSE_SERVER_BUSY;
    }
  else
    {
    /* mark the task as being recycled - it gets freed later */
    ptask->wt_being_recycled = TRUE;
    pthread_mutex_unlock(ptask->wt_mutex);

    if (ptask->wt_func != NULL)
      enqueue_threadpool_request((void *(*)(void *))ptask->wt_func, ptask);
    }

  return(rc);
  } /* END dispatch_timed_task() */