summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog16
-rw-r--r--lib/linklist.c1
-rw-r--r--lib/workqueue.c24
-rw-r--r--lib/workqueue.h11
4 files changed, 41 insertions, 11 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 0725f795..bd66f071 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,19 @@
+2007-11-12 Denis Ovsienko
+
+ * linklist.c: (listnode_add_after) Don't forget to increment list
+ items counter.
+ * workqueue.h: Changed working queue flags from enum into integer
+ and introduced WQ_AIM_HEAD flag to indicate our will to insert
+ new data before the list head.
+ * workqueue.[ch]: (work_queue_schedule, show_work_queues,
+ work_queue_plug, work_queue_unplug) Adjust to the new flags style.
+ * workqueue.[ch]: (work_queue_aim_head) new function to control the
+ WQ_AIM_HEAD flag
+ * workqueue.[ch]: (work_queue_new) Explicitly set both WQ flags
+ during new WQ initialization.
+ * workqueue.[ch]: (work_queue_add) If WQ_AIM_HEAD indicates a need
+ to place the new data into list head, do it.
+
2007-10-22 Lorenzo Colitti <lorenzo@colitti.com>
* smux.c: (smux_stop) Avoid cancelling a defunct thread pointer
diff --git a/lib/linklist.c b/lib/linklist.c
index 11e16a8a..983da2d1 100644
--- a/lib/linklist.c
+++ b/lib/linklist.c
@@ -158,6 +158,7 @@ listnode_add_after (struct list *list, struct listnode *pp, void *val)
pp->next = nn;
}
+ list->count++;
}
diff --git a/lib/workqueue.c b/lib/workqueue.c
index a0f48bc8..8880b9e2 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -66,6 +66,8 @@ work_queue_new (struct thread_master *m, const char *queue_name)
new->name = XSTRDUP (MTYPE_WORK_QUEUE_NAME, queue_name);
new->master = m;
+ SET_FLAG (new->flags, WQ_UNPLUGGED);
+ UNSET_FLAG (new->flags, WQ_AIM_HEAD);
if ( (new->items = list_new ()) == NULL)
{
@@ -103,7 +105,7 @@ static inline int
work_queue_schedule (struct work_queue *wq, unsigned int delay)
{
/* if appropriate, schedule work queue thread */
- if ( (wq->flags == WQ_UNPLUGGED)
+ if ( CHECK_FLAG (wq->flags, WQ_UNPLUGGED)
&& (wq->thread == NULL)
&& (listcount (wq->items) > 0) )
{
@@ -129,7 +131,10 @@ work_queue_add (struct work_queue *wq, void *data)
}
item->data = data;
- listnode_add (wq->items, item);
+ if (CHECK_FLAG (wq->flags, WQ_AIM_HEAD))
+ listnode_add_after (wq->items, NULL, item);
+ else
+ listnode_add (wq->items, item);
work_queue_schedule (wq, wq->spec.hold);
@@ -186,7 +191,7 @@ DEFUN(show_work_queues,
for (ALL_LIST_ELEMENTS_RO ((&work_queues), node, wq))
{
vty_out (vty,"%c %8d %5d %8ld %7d %6d %6u %s%s",
- (wq->flags == WQ_PLUGGED ? 'P' : ' '),
+ (CHECK_FLAG (wq->flags, WQ_UNPLUGGED) ? ' ' : 'P'),
listcount (wq->items),
wq->spec.hold,
wq->runs,
@@ -211,7 +216,7 @@ work_queue_plug (struct work_queue *wq)
wq->thread = NULL;
- wq->flags = WQ_PLUGGED;
+ UNSET_FLAG (wq->flags, WQ_UNPLUGGED);
}
/* unplug queue, schedule it again, if appropriate
@@ -220,12 +225,21 @@ work_queue_plug (struct work_queue *wq)
void
work_queue_unplug (struct work_queue *wq)
{
- wq->flags = WQ_UNPLUGGED;
+ SET_FLAG (wq->flags, WQ_UNPLUGGED);
/* if thread isnt already waiting, add one */
work_queue_schedule (wq, wq->spec.hold);
}
+void
+work_queue_aim_head (struct work_queue *wq, const unsigned aim_head)
+{
+ if (aim_head)
+ SET_FLAG (wq->flags, WQ_AIM_HEAD);
+ else
+ UNSET_FLAG (wq->flags, WQ_AIM_HEAD);
+}
+
/* timer thread to process a work queue
* will reschedule itself if required,
* otherwise work_queue_item_add
diff --git a/lib/workqueue.h b/lib/workqueue.h
index 7e0e78ab..3150c32e 100644
--- a/lib/workqueue.h
+++ b/lib/workqueue.h
@@ -47,11 +47,8 @@ struct work_queue_item
unsigned short ran; /* # of times item has been run */
};
-enum work_queue_flags
-{
- WQ_UNPLUGGED = 0,
- WQ_PLUGGED = 1,
-};
+#define WQ_UNPLUGGED (1 << 0) /* available for draining */
+#define WQ_AIM_HEAD (1 << 1) /* add new items before list head, not after tail */
struct work_queue
{
@@ -101,7 +98,7 @@ struct work_queue
} cycles; /* cycle counts */
/* private state */
- enum work_queue_flags flags; /* user set flag */
+ u_int16_t flags; /* user set flag */
};
/* User API */
@@ -122,6 +119,8 @@ extern void work_queue_add (struct work_queue *, void *);
extern void work_queue_plug (struct work_queue *wq);
/* unplug the queue, allow it to be drained again */
extern void work_queue_unplug (struct work_queue *wq);
+/* control the value for WQ_AIM_HEAD flag */
+extern void work_queue_aim_head (struct work_queue *wq, const unsigned);
/* Helpers, exported for thread.c and command.c */
extern int work_queue_run (struct thread *);