summaryrefslogtreecommitdiffstats
path: root/lib/workqueue.h
diff options
context:
space:
mode:
authorJorge Boncompte <jbonor@gmail.com>2017-08-08 20:32:30 +0200
committerJorge Boncompte <jbonor@gmail.com>2017-08-17 17:47:07 +0200
commitf104f6c1a62c92a4420e1d99abb336d566c1ff51 (patch)
treeb3eceba4d39ae56d9e8eff27e4a2bb16f1024b82 /lib/workqueue.h
parentlib: standardize use of queue.h (diff)
downloadfrr-f104f6c1a62c92a4420e1d99abb336d566c1ff51.tar.xz
frr-f104f6c1a62c92a4420e1d99abb336d566c1ff51.zip
lib: cleanup the work queue implementation
Convert the work queue implementation to not use the generic linked list to mantain the item list and use instead a simple queue from queue.h that does not allocate memory for each node. Signed-off-by: Jorge Boncompte <jbonor@gmail.com>
Diffstat (limited to 'lib/workqueue.h')
-rw-r--r--lib/workqueue.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/workqueue.h b/lib/workqueue.h
index ff7f57690..df35d44fb 100644
--- a/lib/workqueue.h
+++ b/lib/workqueue.h
@@ -24,6 +24,7 @@
#define _QUAGGA_WORK_QUEUE_H
#include "memory.h"
+#include "queue.h"
DECLARE_MTYPE(WORK_QUEUE)
/* Hold time for the initial schedule of a queue run, in millisec */
@@ -43,6 +44,7 @@ typedef enum {
/* A single work queue item, unsurprisingly */
struct work_queue_item {
+ STAILQ_ENTRY(work_queue_item) wq;
void *data; /* opaque data */
unsigned short ran; /* # of times item has been run */
};
@@ -91,7 +93,8 @@ struct work_queue {
} spec;
/* remaining fields should be opaque to users */
- struct list *items; /* queue item list */
+ STAILQ_HEAD(work_queue_items, work_queue_item) items; /* queue item list */
+ int item_count; /* queued items */
unsigned long runs; /* runs count */
unsigned long yields; /* yields count */
@@ -107,6 +110,37 @@ struct work_queue {
/* User API */
+static inline int work_queue_item_count(struct work_queue *wq)
+{
+ return wq->item_count;
+}
+
+static inline bool work_queue_empty(struct work_queue *wq)
+{
+ return (wq->item_count == 0) ? true : false;
+}
+
+static inline struct work_queue_item *work_queue_last_item(struct work_queue *wq)
+{
+ return STAILQ_LAST(&wq->items, work_queue_item, wq);
+}
+
+static inline void work_queue_item_enqueue(struct work_queue *wq,
+ struct work_queue_item *item)
+{
+ STAILQ_INSERT_TAIL(&wq->items, item, wq);
+ wq->item_count++;
+}
+
+static inline void work_queue_item_dequeue(struct work_queue *wq,
+ struct work_queue_item *item)
+{
+ assert(wq->item_count > 0);
+
+ wq->item_count--;
+ STAILQ_REMOVE(&wq->items, item, work_queue_item, wq);
+}
+
/* create a new work queue, of given name.
* user must fill in the spec of the returned work queue before adding
* anything to it