workqueue.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Quagga Work Queues.
  3. *
  4. * Copyright (C) 2005 Sun Microsystems, Inc.
  5. *
  6. * This file is part of Quagga.
  7. *
  8. * Quagga is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * Quagga is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Quagga; see the file COPYING. If not, write to the Free
  20. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  21. * 02111-1307, USA.
  22. */
  23. #ifndef _QUAGGA_WORK_QUEUE_H
  24. #define _QUAGGA_WORK_QUEUE_H
  25. /* Hold time for the initial schedule of a queue run, in millisec */
  26. #define WORK_QUEUE_DEFAULT_HOLD 50
  27. /* action value, for use by item processor and item error handlers */
  28. typedef enum
  29. {
  30. WQ_SUCCESS = 0,
  31. WQ_ERROR, /* Error, run error handler if provided */
  32. WQ_RETRY_NOW, /* retry immediately */
  33. WQ_RETRY_LATER, /* retry later, cease processing work queue */
  34. WQ_REQUEUE, /* requeue item, continue processing work queue */
  35. WQ_QUEUE_BLOCKED, /* Queue cant be processed at this time.
  36. * Similar to WQ_RETRY_LATER, but doesn't penalise
  37. * the particular item.. */
  38. } wq_item_status;
  39. /* A single work queue item, unsurprisingly */
  40. struct work_queue_item
  41. {
  42. void *data; /* opaque data */
  43. unsigned short ran; /* # of times item has been run */
  44. };
  45. #define WQ_UNPLUGGED (1 << 0) /* available for draining */
  46. struct work_queue
  47. {
  48. /* Everything but the specification struct is private
  49. * the following may be read
  50. */
  51. struct thread_master *master; /* thread master */
  52. struct thread *thread; /* thread, if one is active */
  53. char *name; /* work queue name */
  54. /* Specification for this work queue.
  55. * Public, must be set before use by caller. May be modified at will.
  56. */
  57. struct {
  58. /* optional opaque user data, global to the queue. */
  59. void *data;
  60. /* work function to process items with:
  61. * First argument is the workqueue queue.
  62. * Second argument is the item data
  63. */
  64. wq_item_status (*workfunc) (struct work_queue *, void *);
  65. /* error handling function, optional */
  66. void (*errorfunc) (struct work_queue *, struct work_queue_item *);
  67. /* callback to delete user specific item data */
  68. void (*del_item_data) (struct work_queue *, void *);
  69. /* completion callback, called when queue is emptied, optional */
  70. void (*completion_func) (struct work_queue *);
  71. /* max number of retries to make for item that errors */
  72. unsigned int max_retries;
  73. unsigned int hold; /* hold time for first run, in ms */
  74. } spec;
  75. /* remaining fields should be opaque to users */
  76. struct list *items; /* queue item list */
  77. unsigned long runs; /* runs count */
  78. unsigned long worst_usec;
  79. struct {
  80. unsigned int best;
  81. unsigned int worst;
  82. unsigned int granularity;
  83. unsigned long total;
  84. } cycles; /* cycle counts */
  85. /* private state */
  86. u_int16_t flags; /* user set flag */
  87. };
  88. /* User API */
  89. /* create a new work queue, of given name.
  90. * user must fill in the spec of the returned work queue before adding
  91. * anything to it
  92. */
  93. extern struct work_queue *work_queue_new (struct thread_master *,
  94. const char *);
  95. /* destroy work queue */
  96. extern void work_queue_free (struct work_queue *);
  97. /* Add the supplied data as an item onto the workqueue */
  98. extern void work_queue_add (struct work_queue *, void *);
  99. /* plug the queue, ie prevent it from being drained / processed */
  100. extern void work_queue_plug (struct work_queue *wq);
  101. /* unplug the queue, allow it to be drained again */
  102. extern void work_queue_unplug (struct work_queue *wq);
  103. bool work_queue_is_scheduled (struct work_queue *);
  104. /* Helpers, exported for thread.c and command.c */
  105. extern int work_queue_run (struct thread *);
  106. extern struct cmd_element show_work_queues_cmd;
  107. #endif /* _QUAGGA_WORK_QUEUE_H */