Commit 86bf22af76e0d4c7920564a189e07b22178261d0

Kano 2014-01-08T22:17:30

klist - allow adding to tail

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)