From 5266ce81a47c75e5c8d42c54ef60bf0afcaed755 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Sat, 19 Nov 2022 21:32:43 -0800
Subject: [PATCH v2 2/9] Constify some ilist.h functions

This is required for some of the replacements of SHM_QUEUE, because of
code dealing with const PGPROC's.
---
 src/include/lib/ilist.h | 22 +++++++++++-----------
 src/backend/lib/ilist.c |  8 ++++----
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/include/lib/ilist.h b/src/include/lib/ilist.h
index a1a4abf0609..64596ad0f1e 100644
--- a/src/include/lib/ilist.h
+++ b/src/include/lib/ilist.h
@@ -290,8 +290,8 @@ extern void slist_delete(slist_head *head, slist_node *node);
 
 #ifdef ILIST_DEBUG
 extern void dlist_member_check(dlist_head *head, dlist_node *node);
-extern void dlist_check(dlist_head *head);
-extern void slist_check(slist_head *head);
+extern void dlist_check(const dlist_head *head);
+extern void slist_check(const slist_head *head);
 #else
 /*
  * These seemingly useless casts to void are here to keep the compiler quiet
@@ -333,7 +333,7 @@ dlist_node_init(dlist_node *node)
  * An empty list has either its first 'next' pointer set to NULL, or to itself.
  */
 static inline bool
-dlist_is_empty(dlist_head *head)
+dlist_is_empty(const dlist_head *head)
 {
 	dlist_check(head);
 
@@ -500,7 +500,7 @@ dlist_move_tail(dlist_head *head, dlist_node *node)
  * Caution: unreliable if 'node' is not in the list.
  */
 static inline bool
-dlist_has_next(dlist_head *head, dlist_node *node)
+dlist_has_next(const dlist_head *head, const dlist_node *node)
 {
 	return node->next != &head->head;
 }
@@ -510,7 +510,7 @@ dlist_has_next(dlist_head *head, dlist_node *node)
  * Caution: unreliable if 'node' is not in the list.
  */
 static inline bool
-dlist_has_prev(dlist_head *head, dlist_node *node)
+dlist_has_prev(const dlist_head *head, const dlist_node *node)
 {
 	return node->prev != &head->head;
 }
@@ -679,7 +679,7 @@ dclist_init(dclist_head *head)
  *		Returns true if the list is empty, otherwise false.
  */
 static inline bool
-dclist_is_empty(dclist_head *head)
+dclist_is_empty(const dclist_head *head)
 {
 	Assert(dlist_is_empty(&head->dlist) == (head->count == 0));
 	return (head->count == 0);
@@ -836,7 +836,7 @@ dclist_move_tail(dclist_head *head, dlist_node *node)
  * Caution: 'node' must be a member of 'head'.
  */
 static inline bool
-dclist_has_next(dclist_head *head, dlist_node *node)
+dclist_has_next(const dclist_head *head, const dlist_node *node)
 {
 	dlist_member_check(&head->dlist, node);
 	Assert(head->count > 0);
@@ -851,7 +851,7 @@ dclist_has_next(dclist_head *head, dlist_node *node)
  * Caution: 'node' must be a member of 'head'.
  */
 static inline bool
-dclist_has_prev(dclist_head *head, dlist_node *node)
+dclist_has_prev(const dclist_head *head, const dlist_node *node)
 {
 	dlist_member_check(&head->dlist, node);
 	Assert(head->count > 0);
@@ -929,7 +929,7 @@ dclist_tail_node(dclist_head *head)
  *		Returns the stored number of entries in 'head'
  */
 static inline uint32
-dclist_count(dclist_head *head)
+dclist_count(const dclist_head *head)
 {
 	Assert(dlist_is_empty(&head->dlist) == (head->count == 0));
 
@@ -992,7 +992,7 @@ slist_init(slist_head *head)
  * Is the list empty?
  */
 static inline bool
-slist_is_empty(slist_head *head)
+slist_is_empty(const slist_head *head)
 {
 	slist_check(head);
 
@@ -1040,7 +1040,7 @@ slist_pop_head_node(slist_head *head)
  * Check whether 'node' has a following node.
  */
 static inline bool
-slist_has_next(slist_head *head, slist_node *node)
+slist_has_next(const slist_head *head, const slist_node *node)
 {
 	slist_check(head);
 
diff --git a/src/backend/lib/ilist.c b/src/backend/lib/ilist.c
index e8ea9811764..fc78e06b1f9 100644
--- a/src/backend/lib/ilist.c
+++ b/src/backend/lib/ilist.c
@@ -73,9 +73,9 @@ dlist_member_check(dlist_head *head, dlist_node *node)
  * Verify integrity of a doubly linked list
  */
 void
-dlist_check(dlist_head *head)
+dlist_check(const dlist_head *head)
 {
-	dlist_node *cur;
+	const dlist_node *cur;
 
 	if (head == NULL)
 		elog(ERROR, "doubly linked list head address is NULL");
@@ -110,9 +110,9 @@ dlist_check(dlist_head *head)
  * Verify integrity of a singly linked list
  */
 void
-slist_check(slist_head *head)
+slist_check(const slist_head *head)
 {
-	slist_node *cur;
+	const slist_node *cur;
 
 	if (head == NULL)
 		elog(ERROR, "singly linked list head address is NULL");
-- 
2.38.0

