예제 #1
0
파일: queue_func.c 프로젝트: dhill12/test
pbs_queue *que_alloc(

  char *name,
  int   sv_qs_mutex_held)

  {
  static char *mem_err = "no memory";

  int        i;
  pbs_queue *pq;

  pq = (pbs_queue *)calloc(1, sizeof(pbs_queue));

  if (pq == NULL)
    {
    log_err(errno, __func__, mem_err);

    return(NULL);
    }

  pq->qu_qs.qu_type = QTYPE_Unset;

  pq->qu_mutex = calloc(1, sizeof(pthread_mutex_t));
  pq->qu_jobs = calloc(1, sizeof(struct all_jobs));
  pq->qu_jobs_array_sum = calloc(1, sizeof(struct all_jobs));
  
  if ((pq->qu_mutex == NULL) ||
      (pq->qu_jobs == NULL) ||
      (pq->qu_jobs_array_sum == NULL))
    {
    log_err(ENOMEM, __func__, mem_err);
    return(NULL);
    }

  initialize_all_jobs_array(pq->qu_jobs);
  initialize_all_jobs_array(pq->qu_jobs_array_sum);
  pthread_mutex_init(pq->qu_mutex,NULL);
  lock_queue(pq, "que_alloc", NULL, LOGLEVEL);

  strncpy(pq->qu_qs.qu_name, name, PBS_MAXQUEUENAME);

  insert_queue(&svr_queues,pq);
 
  if (sv_qs_mutex_held == FALSE)
    lock_sv_qs_mutex(server.sv_qs_mutex, __func__);
  server.sv_qs.sv_numque++;
  if (sv_qs_mutex_held == FALSE)
    unlock_sv_qs_mutex(server.sv_qs_mutex, __func__);

  /* set the working attributes to "unspecified" */

  for (i = 0; i < QA_ATR_LAST; i++)
    {
    clear_attr(&pq->qu_attr[i], &que_attr_def[i]);
    }

  return(pq);
  }  /* END que_alloc() */
예제 #2
0
END_TEST

START_TEST(insert_job_after_test)
  {
  struct all_jobs alljobs;
  struct job *test_job;

  int result;
  initialize_all_jobs_array(&alljobs);

  test_job = job_alloc();

  result = insert_job_after(NULL,test_job,test_job);
  fail_unless(result != PBSE_NONE, "insert into null array fail");

  result = insert_job_after(&alljobs,NULL,test_job);
  fail_unless(result != PBSE_NONE, "NULL job after insert fail");

  result = insert_job_after(&alljobs,test_job,NULL);
  fail_unless(result != PBSE_NONE, "NULL job to insert fail");

  insert_job(&alljobs,test_job);
  result = insert_job_after(&alljobs,test_job,test_job);
  fail_unless(result == PBSE_NONE, "job insert fail");
  }
예제 #3
0
END_TEST

START_TEST(swap_jobs_test)
  {
  struct all_jobs alljobs;
  struct job *test_job;
  struct job *second_test_job;

  int result;
  initialize_all_jobs_array(&alljobs);

  test_job = job_alloc();
  second_test_job = job_alloc();

  result = swap_jobs(&alljobs,NULL,test_job);
  fail_unless(result != PBSE_NONE, "NULL first input job fail");

  result = insert_job_after(&alljobs,test_job,NULL);
  fail_unless(result != PBSE_NONE, "NULL second input job fail");

  insert_job(&alljobs, test_job);
  insert_job(&alljobs, second_test_job);
  result = swap_jobs(&alljobs, test_job,second_test_job);
  fail_unless(result == PBSE_NONE, "swap jobs fail");
  }
예제 #4
0
void initialize_recycler()

  {
  recycler.rc_next_id = 0;
  initialize_all_jobs_array(&recycler.rc_jobs);
  recycler.rc_iter = -1;

  recycler.rc_mutex = calloc(1, sizeof(pthread_mutex_t));
  pthread_mutex_init(recycler.rc_mutex,NULL);
  } /* END initialize_recycler() */
예제 #5
0
END_TEST

START_TEST(next_job_from_back_test)
  {
  struct all_jobs alljobs;
  struct job *result;
  initialize_all_jobs_array(&alljobs);

  result = next_job_from_back(NULL,NULL);
  fail_unless(result == NULL, "null input parameters fail");

  result = next_job_from_back(&alljobs,NULL);
  fail_unless(result == NULL, "NULL input iterator fail");
  }
예제 #6
0
END_TEST

START_TEST(find_job_by_array_test)
  {
  struct all_jobs alljobs;
  struct job* result = find_job_by_array(NULL,(char *)"",0);
  initialize_all_jobs_array(&alljobs);

  result = find_job_by_array(NULL,(char *)"",0);
  fail_unless(result == NULL, "NULL all jobs input fail");

  result = find_job_by_array(&alljobs,NULL,0);
  fail_unless(result == NULL, "NULL job id input fail");

  result = find_job_by_array(&alljobs,(char *)"",0);
  fail_unless(result == NULL, "empty job id input fail");
  }
예제 #7
0
END_TEST

START_TEST(remove_job_test)
  {
  struct all_jobs alljobs;
  int result;
  struct job *test_job = job_alloc();
  initialize_all_jobs_array(&alljobs);

  result = remove_job(NULL,test_job);
  fail_unless(result != PBSE_NONE, "remove from null array fail");

  result = remove_job(&alljobs,NULL);
  fail_unless(result != PBSE_NONE, "NULL job remove fail");

  insert_job(&alljobs,test_job);
  result = remove_job(&alljobs,test_job);
  fail_unless(result == PBSE_NONE, "job remove fail");
  }
예제 #8
0
END_TEST

START_TEST(get_jobs_index_test)
  {
  struct all_jobs alljobs;
  struct job *test_job = job_alloc();
  int result;
  initialize_all_jobs_array(&alljobs);

  result = get_jobs_index(NULL,test_job);
  fail_unless(result == -1 * PBSE_BAD_PARAMETER, "null input array fail");

  result = get_jobs_index(&alljobs,NULL);
  fail_unless(result == -1 * PBSE_BAD_PARAMETER, "NULL input job fail");

  insert_job(&alljobs, test_job);
  result = get_jobs_index(&alljobs, test_job);
  fail_unless(result == PBSE_NONE, "get_jobs_index fail");
  }
예제 #9
0
END_TEST

START_TEST(has_job_test)
  {
  struct all_jobs alljobs;
  struct job *test_job = job_alloc();
  int result;
  initialize_all_jobs_array(&alljobs);


  result = has_job(NULL,test_job);
  fail_unless(result != PBSE_NONE, "null input array fail");

  result = has_job(&alljobs,NULL);
  fail_unless(result != PBSE_NONE, "NULL input job fail");

  insert_job(&alljobs, test_job);
  result = has_job(&alljobs, test_job);
  fail_unless(result == TRUE, "has_job fail");
  }
예제 #10
0
pbs_queue *que_alloc(

  char *name,
  int   sv_qs_mutex_held)

  {
  static char *mem_err = (char *)"no memory";

  int        i;
  pbs_queue *pq;

  pq = (pbs_queue *)calloc(1, sizeof(pbs_queue));

  if (pq == NULL)
    {
    log_err(errno, __func__, mem_err);

    return(NULL);
    }

  pq->qu_qs.qu_type = QTYPE_Unset;

  pq->qu_mutex = (pthread_mutex_t *)calloc(1, sizeof(pthread_mutex_t));
  pq->qu_jobs = (struct all_jobs *)calloc(1, sizeof(struct all_jobs));
  pq->qu_jobs_array_sum = (struct all_jobs *)calloc(1, sizeof(struct all_jobs));
  
  if ((pq->qu_mutex == NULL) ||
      (pq->qu_jobs == NULL) ||
      (pq->qu_jobs_array_sum == NULL))
    {
    log_err(ENOMEM, __func__, mem_err);
    free(pq);
    return(NULL);
    }

  initialize_all_jobs_array(pq->qu_jobs);
  initialize_all_jobs_array(pq->qu_jobs_array_sum);
  pthread_mutex_init(pq->qu_mutex,NULL);
  lock_queue(pq, __func__, NULL, LOGLEVEL);

  snprintf(pq->qu_qs.qu_name, sizeof(pq->qu_qs.qu_name), "%s", name);

  insert_queue(&svr_queues,pq);
 
  if (sv_qs_mutex_held == FALSE)
    lock_sv_qs_mutex(server.sv_qs_mutex, __func__);
  server.sv_qs.sv_numque++;
  if (sv_qs_mutex_held == FALSE)
    unlock_sv_qs_mutex(server.sv_qs_mutex, __func__);

  /* set up the user info struct */
  pq->qu_uih = (user_info_holder *)calloc(1, sizeof(user_info_holder));
  initialize_user_info_holder(pq->qu_uih);

  /* set the working attributes to "unspecified" */

  for (i = 0; i < QA_ATR_LAST; i++)
    {
    clear_attr(&pq->qu_attr[i], &que_attr_def[i]);
    }

  /* Set route_retry_thread_id in case this is a routing queue */
  pq->route_retry_thread_id = -1;

  return(pq);
  }  /* END que_alloc() */