Пример #1
0
void *remove_some_recycle_tasks(

  void *vp)

  {
  int        i;
  int        iter = -1;
  work_task *ptask;

  pthread_mutex_lock(tr.mutex);

  for (i = 0; i < TASKS_TO_REMOVE; i++)
    {
    ptask = next_task_from_recycler(&tr.tasks, &iter);

    if (ptask == NULL)
      break;

    remove_task(&tr.tasks, ptask);
    pthread_mutex_unlock(ptask->wt_mutex);
    free(ptask->wt_mutex);
    free(ptask);
    }

  pthread_mutex_unlock(tr.mutex);

  return(NULL);
  } /* END remove_some_recycle_tasks() */
Пример #2
0
END_TEST

START_TEST(test_one)
  {
  int rc;
  initialize_all_tasks_array(&task_list_event);
  initialize_task_recycler();

  if (task_list_timed == NULL)
    task_list_timed = new std::list<timed_task>();

  rc = initialize_threadpool(&request_pool, 5, 50, 60);
  fail_unless(rc == PBSE_NONE, "initalize_threadpool failed", rc);

  struct work_task *pWorkTask = set_task(WORK_Timed,357,check_nodes,NULL,0);
  fail_unless(pWorkTask != NULL);
  struct work_task *pWorkTask2 = set_task(WORK_Timed,356,check_nodes,NULL,0);
  fail_unless(pWorkTask2 != NULL);
  struct work_task *pWorkTask3 = set_task(WORK_Timed,358,check_nodes,NULL,0);
  fail_unless(pWorkTask3 != NULL);

  rc = dispatch_task(pWorkTask);
  fail_unless(rc == PBSE_NONE, "dispatch_task failed", rc);
  delete_task(pWorkTask);

  int iter = -1;
  struct work_task *pRecycled = next_task_from_recycler(&tr.tasks,&iter);
  fprintf(stderr,"%p %p\n",(void *)pWorkTask,(void *)pRecycled);
  fail_unless(pRecycled == pWorkTask);
  fail_unless(task_is_in_threadpool(pWorkTask2));
  }
Пример #3
0
void *remove_some_recycle_tasks(

  void *vp)

  {
  int        i;
  std::vector<work_task *>::iterator iter = tr.tasks.tasks.end();
  work_task *ptask;

  pthread_mutex_lock(tr.mutex);

  for (i = 0; i < TASKS_TO_REMOVE; i++)
    {
    ptask = next_task_from_recycler(&tr.tasks, iter);

    if (ptask == NULL)
      break;

    tr.tasks.tasks.erase(iter);
    pthread_mutex_unlock(ptask->wt_mutex);
    free(ptask->wt_mutex);
    free(ptask);
    }

  pthread_mutex_unlock(tr.mutex);

  return(NULL);
  } /* END remove_some_recycle_tasks() */
Пример #4
0
work_task *get_recycled_task()

  {
  work_task *ptask;

  pthread_mutex_lock(tr.mutex);
  ptask = next_task_from_recycler(&tr.tasks, &tr.iter);

  if (ptask == NULL)
    tr.iter = -1;
  pthread_mutex_unlock(tr.mutex);

  if (ptask != NULL)
    ptask->wt_being_recycled = FALSE;

  return(ptask);
  } /* END get_recycled_task() */