CLEANUP: lists/tree-wide: rename some list operations to avoid some confusion
The current "ADD" vs "ADDQ" is confusing because when thinking in terms
of appending at the end of a list, "ADD" naturally comes to mind, but
here it does the opposite, it inserts. Several times already it's been
incorrectly used where ADDQ was expected, the latest of which was a
fortunate accident explained in 6fa922562 ("CLEANUP: stream: explain
why we queue the stream at the head of the server list").
Let's use more explicit (but slightly longer) names now:
LIST_ADD -> LIST_INSERT
LIST_ADDQ -> LIST_APPEND
LIST_ADDED -> LIST_INLIST
LIST_DEL -> LIST_DELETE
The same is true for MT_LISTs, including their "TRY" variant.
LIST_DEL_INIT keeps its short name to encourage to use it instead of the
lazier LIST_DELETE which is often less safe.
The change is large (~674 non-comment entries) but is mechanical enough
to remain safe. No permutation was performed, so any out-of-tree code
can easily map older names to new ones.
The list doc was updated.
diff --git a/src/lru.c b/src/lru.c
index 84442a4..22f15f7 100644
--- a/src/lru.c
+++ b/src/lru.c
@@ -25,8 +25,8 @@
#include <import/lru.h>
/* Minimal list manipulation macros for lru64_list */
-#define LIST_ADD(lh, el) ({ (el)->n = (lh)->n; (el)->n->p = (lh)->n = (el); (el)->p = (lh); })
-#define LIST_DEL(el) ({ (el)->n->p = (el)->p; (el)->p->n = (el)->n; })
+#define LIST_INSERT(lh, el) ({ (el)->n = (lh)->n; (el)->n->p = (lh)->n = (el); (el)->p = (lh); })
+#define LIST_DELETE(el) ({ (el)->n->p = (el)->p; (el)->p->n = (el)->n; })
/* Lookup key <key> in LRU cache <lru> for use with domain <domain> whose data's
@@ -46,8 +46,8 @@
* head of the LRU list.
*/
if (elem->domain == domain && elem->revision == revision) {
- LIST_DEL(&elem->lru);
- LIST_ADD(&lru->list, &elem->lru);
+ LIST_DELETE(&elem->lru);
+ LIST_INSERT(&lru->list, &elem->lru);
return elem;
}
}
@@ -87,8 +87,8 @@
* head of the LRU list.
*/
if (elem->domain == domain && elem->revision == revision) {
- LIST_DEL(&elem->lru);
- LIST_ADD(&lru->list, &elem->lru);
+ LIST_DELETE(&elem->lru);
+ LIST_INSERT(&lru->list, &elem->lru);
return elem;
}
@@ -96,7 +96,7 @@
return NULL; // currently locked
/* recycle this entry */
- LIST_DEL(&elem->lru);
+ LIST_DELETE(&elem->lru);
}
else {
/* New entry inserted, initialize and move to the head of the
@@ -107,7 +107,7 @@
}
elem->domain = NULL;
- LIST_ADD(&lru->list, &elem->lru);
+ LIST_INSERT(&lru->list, &elem->lru);
if (lru->cache_usage > lru->cache_size) {
/* try to kill oldest entry */
@@ -116,7 +116,7 @@
old = container_of(lru->list.p, typeof(*old), lru);
if (old->domain) {
/* not locked */
- LIST_DEL(&old->lru);
+ LIST_DELETE(&old->lru);
__eb64_delete(&old->node);
if (old->data && old->free)
old->free(old->data);
@@ -181,7 +181,7 @@
next = container_of(elem->lru.p, typeof(*next), lru);
if (elem->domain) {
/* not locked */
- LIST_DEL(&elem->lru);
+ LIST_DELETE(&elem->lru);
eb64_delete(&elem->node);
if (elem->data && elem->free)
elem->free(elem->data);
@@ -211,7 +211,7 @@
if (!elem->domain)
continue; /* locked entry */
- LIST_DEL(&elem->lru);
+ LIST_DELETE(&elem->lru);
eb64_delete(&elem->node);
if (elem->data && elem->free)
elem->free(elem->data);