home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / src / io / job / job-desc-queue.c next >
C/C++ Source or Header  |  2008-11-19  |  5KB  |  230 lines

  1. /*
  2.  * (C) 2001 Clemson University and The University of Chicago
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. /* functions for handling queues of jobs that the job interface is
  8.  * managing
  9.  */
  10.  
  11. #include <stdlib.h>
  12. #include <errno.h>
  13. #include <string.h>
  14. #include <assert.h>
  15.  
  16. #include "job-desc-queue.h"
  17. #include "gossip.h"
  18. #include "id-generator.h"
  19. #include "pint-util.h"
  20.  
  21. /***************************************************************
  22.  * Visible functions
  23.  */
  24.  
  25. /* alloc_job_desc()
  26.  *
  27.  * creates a new job desc struct and fills in default values
  28.  *
  29.  * returns pointer to structure on success, NULL on failure
  30.  */
  31. struct job_desc *alloc_job_desc(int type)
  32. {
  33.     struct job_desc *jd = NULL;
  34.  
  35.     jd = (struct job_desc *) malloc(sizeof(struct job_desc));
  36.     if (!jd)
  37.     {
  38.     return (NULL);
  39.     }
  40.     memset(jd, 0, sizeof(struct job_desc));
  41.  
  42.     id_gen_safe_register(&(jd->job_id), jd);
  43.  
  44.     jd->type = type;
  45.  
  46.     return (jd);
  47. };
  48.  
  49. /* dealloc_job_desc()
  50.  *
  51.  * destroys an existing job desc structure
  52.  *
  53.  * no return value
  54.  */
  55. void dealloc_job_desc(struct job_desc *jd)
  56. {
  57.     id_gen_safe_unregister(jd->job_id);
  58.     free(jd);
  59. }
  60.  
  61. /* job_desc_q_new()
  62.  *
  63.  * creates a new queue of job descriptions
  64.  *
  65.  * returns pointer to queue on success, NULL on failure
  66.  */
  67. job_desc_q_p job_desc_q_new(void)
  68. {
  69.     struct qlist_head *tmp_job_desc_q = NULL;
  70.  
  71.     tmp_job_desc_q = (struct qlist_head *)
  72.         malloc(sizeof(struct qlist_head));
  73.     if (tmp_job_desc_q)
  74.     {
  75.         INIT_QLIST_HEAD(tmp_job_desc_q);
  76.     }
  77.     return (tmp_job_desc_q);
  78. }
  79.  
  80. /* job_desc_q_cleanup()
  81.  *
  82.  * destroys an existing queue of job descriptions
  83.  *
  84.  * no return value
  85.  */
  86. void job_desc_q_cleanup(job_desc_q_p jdqp)
  87. {
  88.     job_desc_q_p iterator = NULL;
  89.     job_desc_q_p scratch = NULL;
  90.     struct job_desc *tmp_job_desc = NULL;
  91.  
  92.     if (jdqp)
  93.     {
  94.             qlist_for_each_safe(iterator, scratch, jdqp)
  95.             {
  96.                 tmp_job_desc = qlist_entry(iterator, struct job_desc,
  97.                         job_desc_q_link);
  98.                 /* qlist_for_each_safe lets us iterate and remove nodes.  no
  99.                  * need to adjust pointers as we are freeing everything */
  100.                 free(tmp_job_desc);
  101.             }
  102.  
  103.             free(jdqp);
  104.             jdqp = NULL;
  105.     }
  106.     return;
  107. }
  108.  
  109. /* job_desc_q_add()
  110.  *
  111.  * adds a new job description to a queue
  112.  *
  113.  * no return value
  114.  */
  115. void job_desc_q_add(job_desc_q_p jdqp,
  116.             struct job_desc *desc)
  117. {
  118.     if (jdqp)
  119.     {
  120.         assert(desc);
  121.  
  122.         /* note that we are adding to tail to preserve fifo order */
  123.         qlist_add_tail(&(desc->job_desc_q_link), jdqp);
  124.     }
  125. }
  126.  
  127. /* job_desc_q_remove()
  128.  *
  129.  * removes an entry from a job desc queue
  130.  *
  131.  * no return value
  132.  */
  133. void job_desc_q_remove(struct job_desc *desc)
  134. {
  135.     assert(desc);
  136.     qlist_del(&(desc->job_desc_q_link));
  137. }
  138.  
  139. /* job_desc_q_empty()
  140.  *
  141.  * checks to see if a given queue is empty or not
  142.  *
  143.  * returns 1 if empty, 0 otherwise
  144.  */
  145. int job_desc_q_empty(job_desc_q_p jdqp)
  146. {
  147.     return (qlist_empty(jdqp));
  148. }
  149.  
  150. /* job_desc_q_shownext()
  151.  *
  152.  * returns a pointer to the next item in the queue
  153.  *
  154.  * returns pointer to job desc on success, NULL on failure
  155.  */
  156. struct job_desc *job_desc_q_shownext(job_desc_q_p jdqp)
  157. {
  158.     if (jdqp->next == jdqp)
  159.     {
  160.     return (NULL);
  161.     }
  162.     return (qlist_entry(jdqp->next, struct job_desc, job_desc_q_link));
  163. }
  164.  
  165.  
  166. /* job_desc_q_dump()
  167.  *
  168.  * prints out the contents of the desired job desc queue
  169.  *
  170.  * no return value
  171.  */
  172. void job_desc_q_dump(job_desc_q_p jdqp)
  173. {
  174.     struct qlist_head *tmp_link = NULL;
  175.     struct job_desc *tmp_entry = NULL;
  176.  
  177.     gossip_err("job_desc_q_dump():\n");
  178.     gossip_err("------------------\n");
  179.  
  180.     /* iterate all the way through the queue */
  181.     qlist_for_each(tmp_link, jdqp)
  182.     {
  183.     tmp_entry = qlist_entry(tmp_link, struct job_desc,
  184.                 job_desc_q_link);
  185.     gossip_err("  job id: %ld.\n", (long) tmp_entry->job_id);
  186.     switch (tmp_entry->type)
  187.     {
  188.     case JOB_BMI:
  189.         gossip_err("    type: JOB_BMI.\n");
  190.         gossip_err("    bmi_id: %ld.\n", (long) tmp_entry->u.bmi.id);
  191.         break;
  192.     case JOB_BMI_UNEXP:
  193.         gossip_err("    type: JOB_BMI_UNEXP.\n");
  194.         break;
  195.     case JOB_TROVE:
  196.         gossip_err("    type: JOB_TROVE.\n");
  197.         break;
  198.     case JOB_FLOW:
  199.         gossip_err("    type: JOB_FLOW.\n");
  200.         break;
  201.     case JOB_REQ_SCHED:
  202.         gossip_err("    type: JOB_REQ_SCHED.\n");
  203.         break;
  204.     case JOB_DEV_UNEXP:
  205.         gossip_err("    type: JOB_DEV_UNEXP.\n");
  206.         break;
  207.     case JOB_REQ_SCHED_TIMER:
  208.         gossip_err("    type: JOB_REQ_SCHED_TIMER.\n");
  209.         break;
  210.     case JOB_NULL:
  211.         gossip_err("    type: JOB_NULL.\n");
  212.         break;
  213.     case JOB_PRECREATE_POOL:
  214.         gossip_err("    type: JOB_PRECREATE_POOL.\n");
  215.         break;
  216.     }
  217.     }
  218.  
  219.     return;
  220. }
  221.  
  222. /*
  223.  * Local variables:
  224.  *  c-indent-level: 4
  225.  *  c-basic-offset: 4
  226.  * End:
  227.  *
  228.  * vim: ts=8 sts=4 sw=4 expandtab
  229.  */
  230.