klist - allow adding to tail
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
diff --git a/klist.c b/klist.c
index bded9d9..310c6f6 100644
--- a/klist.c
+++ b/klist.c
@@ -15,7 +15,7 @@ static void k_alloc_items(K_LIST *list, KLIST_FFL_ARGS)
int allocate, i;
if (list->is_store) {
- quithere(1, "List %s store can't %s" KLIST_FFL,
+ quithere(1, "List %s store can't %s()" KLIST_FFL,
list->name, __func__, KLIST_FFL_PASS);
}
@@ -177,7 +177,7 @@ K_ITEM *_k_unlink_tail(K_LIST *list, KLIST_FFL_ARGS)
K_ITEM *item;
if (!(list->do_tail)) {
- quithere(1, "List %s do_tail false can't %s" KLIST_FFL,
+ quithere(1, "List %s can't %s() - do_tail is false" KLIST_FFL,
list->name, __func__, KLIST_FFL_PASS);
}
@@ -201,7 +201,7 @@ K_ITEM *_k_unlink_tail(K_LIST *list, KLIST_FFL_ARGS)
void _k_add_head(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS)
{
if (item->name != list->name) {
- quithere(1, "List %s can't %s a %s item" KLIST_FFL,
+ quithere(1, "List %s can't %s() a %s item" KLIST_FFL,
list->name, __func__, item->name, KLIST_FFL_PASS);
}
@@ -229,6 +229,32 @@ void _k_free_head(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS)
}
*/
+void _k_add_tail(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS)
+{
+ if (item->name != list->name) {
+ quithere(1, "List %s can't %s() a %s item" KLIST_FFL,
+ list->name, __func__, item->name, KLIST_FFL_PASS);
+ }
+
+ if (!(list->do_tail)) {
+ quithere(1, "List %s can't %s() - do_tail is false" KLIST_FFL,
+ list->name, __func__, KLIST_FFL_PASS);
+ }
+
+ item->prev = list->tail;
+ item->next = NULL;
+ if (list->tail)
+ list->tail->next = item;
+
+ list->tail = item;
+
+ if (!(list->head))
+ list->head = item;
+
+ list->count++;
+ list->count_up++;
+}
+
void k_unlink_item(K_LIST *list, K_ITEM *item)
{
if (item->prev)
diff --git a/klist.h b/klist.h
index 7608e24..4b88f95 100644
--- a/klist.h
+++ b/klist.h
@@ -56,7 +56,6 @@ typedef struct k_list {
/*
* N.B. all locking is done in the code calling the k_ functions
*/
-
#define K_WLOCK(_list) cg_wlock(_list->lock)
#define K_WUNLOCK(_list) cg_wunlock(_list->lock)
#define K_RLOCK(_list) cg_rlock(_list->lock)
@@ -75,6 +74,8 @@ extern void _k_add_head(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS);
#define k_add_head(_list, _item) _k_add_head(_list, _item, KLIST_FFL_HERE)
// extern void k_free_head(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS);
#define k_free_head(__list, __item) _k_add_head(__list, __item, KLIST_FFL_HERE)
+extern void _k_add_tail(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS);
+#define k_add_tail(_list, _item) _k_add_tail(_list, _item, KLIST_FFL_HERE)
extern void k_unlink_item(K_LIST *list, K_ITEM *item);
extern K_LIST *_k_free_list(K_LIST *list, KLIST_FFL_ARGS);
#define k_free_list(_list) _k_free_list(_list, KLIST_FFL_HERE)