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 / flow / flow-queue.c next >
C/C++ Source or Header  |  2004-07-28  |  2KB  |  120 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 flows that the flow interface is
  8.  * managing
  9.  */
  10.  
  11. #include "gossip.h"
  12. #include "quicklist.h"
  13. #include "flow-queue.h"
  14. #include <errno.h>
  15.  
  16. /* flow_queue_new()
  17.  *
  18.  * creates a new flow queue
  19.  *
  20.  * returns pointer to queue on success, NULL on failure
  21.  */
  22. flow_queue_p flow_queue_new(void)
  23. {
  24.     struct qlist_head *tmp_flow_queue = NULL;
  25.  
  26.     tmp_flow_queue = (struct qlist_head *) malloc(sizeof(struct qlist_head));
  27.     if (tmp_flow_queue)
  28.     {
  29.     INIT_QLIST_HEAD(tmp_flow_queue);
  30.     }
  31.     return (tmp_flow_queue);
  32. }
  33.  
  34. /* flow_queue_cleanup()
  35.  *
  36.  * destroys an existing flow queue
  37.  *
  38.  * no return value
  39.  */
  40. void flow_queue_cleanup(flow_queue_p fqp)
  41. {
  42.     struct flow_descriptor *tmp_flow_d = NULL;
  43.  
  44.     do
  45.     {
  46.     tmp_flow_d = flow_queue_shownext(fqp);
  47.     if (tmp_flow_d)
  48.     {
  49.         flow_queue_remove(tmp_flow_d);
  50.         /* TODO: what to do here? release flow? */
  51.     }
  52.     } while (tmp_flow_d);
  53.  
  54.     free(fqp);
  55.     fqp = NULL;
  56.     return;
  57. }
  58.  
  59. /* flwo_queue_add()
  60.  *
  61.  * adds a flow to an existing queue
  62.  *
  63.  * no return value
  64.  */
  65. void flow_queue_add(flow_queue_p fqp,
  66.             struct flow_descriptor *flow_d)
  67. {
  68.     qlist_add_tail(&(flow_d->sched_queue_link), fqp);
  69.     return;
  70. }
  71.  
  72. /* flow_queue_remove()
  73.  *
  74.  * removes a flow from a queue
  75.  *
  76.  * no return value
  77.  */
  78. void flow_queue_remove(struct flow_descriptor *flow_d)
  79. {
  80.     qlist_del(&(flow_d->sched_queue_link));
  81.     return;
  82. }
  83.  
  84. /* flow_queue_empty()
  85.  *
  86.  * checks to see if a queue is empty
  87.  *
  88.  * returns 1 if empty, 0 otherwise
  89.  */
  90. int flow_queue_empty(flow_queue_p fqp)
  91. {
  92.     return (qlist_empty(fqp));
  93. }
  94.  
  95. /* flow_queue_shownext()
  96.  *
  97.  * returns a pointer to the next element in the queue
  98.  *
  99.  * returns pointer on success, NULL on failure
  100.  */
  101. struct flow_descriptor *flow_queue_shownext(flow_queue_p fqp)
  102. {
  103.     flow_descriptor *flow_d = NULL;
  104.     if (fqp->next == fqp)
  105.     {
  106.     return (NULL);
  107.     }
  108.     flow_d = qlist_entry(fqp->next, struct flow_descriptor, sched_queue_link);
  109.     return (flow_d);
  110. }
  111.  
  112. /*
  113.  * Local variables:
  114.  *  c-indent-level: 4
  115.  *  c-basic-offset: 4
  116.  * End:
  117.  *
  118.  * vim: ts=8 sts=4 sw=4 expandtab
  119.  */
  120.