PostgreSQL Source Code  git master
ilist.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dlist_node
 
struct  dlist_head
 
struct  dlist_iter
 
struct  dlist_mutable_iter
 
struct  slist_node
 
struct  slist_head
 
struct  slist_iter
 
struct  slist_mutable_iter
 

Macros

#define DLIST_STATIC_INIT(name)   {{&(name).head, &(name).head}}
 
#define SLIST_STATIC_INIT(name)   {{NULL}}
 
#define dlist_check(head)   ((void) (head))
 
#define slist_check(head)   ((void) (head))
 
#define dlist_container(type, membername, ptr)
 
#define dlist_head_element(type, membername, lhead)
 
#define dlist_tail_element(type, membername, lhead)
 
#define dlist_foreach(iter, lhead)
 
#define dlist_foreach_modify(iter, lhead)
 
#define dlist_reverse_foreach(iter, lhead)
 
#define slist_container(type, membername, ptr)
 
#define slist_head_element(type, membername, lhead)
 
#define slist_foreach(iter, lhead)
 
#define slist_foreach_modify(iter, lhead)
 

Typedefs

typedef struct dlist_node dlist_node
 
typedef struct dlist_head dlist_head
 
typedef struct dlist_iter dlist_iter
 
typedef struct dlist_mutable_iter dlist_mutable_iter
 
typedef struct slist_node slist_node
 
typedef struct slist_head slist_head
 
typedef struct slist_iter slist_iter
 
typedef struct slist_mutable_iter slist_mutable_iter
 

Functions

void slist_delete (slist_head *head, slist_node *node)
 
static void dlist_init (dlist_head *head)
 
static bool dlist_is_empty (dlist_head *head)
 
static void dlist_push_head (dlist_head *head, dlist_node *node)
 
static void dlist_push_tail (dlist_head *head, dlist_node *node)
 
static void dlist_insert_after (dlist_node *after, dlist_node *node)
 
static void dlist_insert_before (dlist_node *before, dlist_node *node)
 
static void dlist_delete (dlist_node *node)
 
static dlist_nodedlist_pop_head_node (dlist_head *head)
 
static void dlist_move_head (dlist_head *head, dlist_node *node)
 
static void dlist_move_tail (dlist_head *head, dlist_node *node)
 
static bool dlist_has_next (dlist_head *head, dlist_node *node)
 
static bool dlist_has_prev (dlist_head *head, dlist_node *node)
 
static dlist_nodedlist_next_node (dlist_head *head, dlist_node *node)
 
static dlist_nodedlist_prev_node (dlist_head *head, dlist_node *node)
 
static void * dlist_head_element_off (dlist_head *head, size_t off)
 
static dlist_nodedlist_head_node (dlist_head *head)
 
static void * dlist_tail_element_off (dlist_head *head, size_t off)
 
static dlist_nodedlist_tail_node (dlist_head *head)
 
static void slist_init (slist_head *head)
 
static bool slist_is_empty (slist_head *head)
 
static void slist_push_head (slist_head *head, slist_node *node)
 
static void slist_insert_after (slist_node *after, slist_node *node)
 
static slist_nodeslist_pop_head_node (slist_head *head)
 
static bool slist_has_next (slist_head *head, slist_node *node)
 
static slist_nodeslist_next_node (slist_head *head, slist_node *node)
 
static void * slist_head_element_off (slist_head *head, size_t off)
 
static slist_nodeslist_head_node (slist_head *head)
 
static void slist_delete_current (slist_mutable_iter *iter)
 

Macro Definition Documentation

◆ dlist_check

#define dlist_check (   head)    ((void) (head))

Definition at line 267 of file ilist.h.

◆ dlist_container

#define dlist_container (   type,
  membername,
  ptr 
)
Value:
AssertVariableIsOfTypeMacro(((type *) NULL)->membername, dlist_node), \
((type *) ((char *) (ptr) - offsetof(type, membername))))
#define offsetof(type, field)
Definition: c.h:727
#define AssertVariableIsOfTypeMacro(varname, typename)
Definition: c.h:966

Definition at line 496 of file ilist.h.

◆ dlist_foreach

#define dlist_foreach (   iter,
  lhead 
)
Value:
(iter).end = &(lhead)->head, \
(iter).cur = (iter).end->next ? (iter).end->next : (iter).end; \
(iter).cur != (iter).end; \
(iter).cur = (iter).cur->next)
struct cursor * cur
Definition: ecpg.c:28
struct cursor * next
Definition: type.h:141

Definition at line 526 of file ilist.h.

◆ dlist_foreach_modify

#define dlist_foreach_modify (   iter,
  lhead 
)
Value:
(iter).end = &(lhead)->head, \
(iter).cur = (iter).end->next ? (iter).end->next : (iter).end, \
(iter).next = (iter).cur->next; \
(iter).cur != (iter).end; \
(iter).cur = (iter).next, (iter).next = (iter).cur->next)

Definition at line 543 of file ilist.h.

◆ dlist_head_element

#define dlist_head_element (   type,
  membername,
  lhead 
)
Value:
(AssertVariableIsOfTypeMacro(((type *) NULL)->membername, dlist_node), \
(type *) dlist_head_element_off(lhead, offsetof(type, membername)))
static void * dlist_head_element_off(dlist_head *head, size_t off)
Definition: ilist.h:458

Definition at line 506 of file ilist.h.

◆ dlist_reverse_foreach

#define dlist_reverse_foreach (   iter,
  lhead 
)
Value:
(iter).end = &(lhead)->head, \
(iter).cur = (iter).end->prev ? (iter).end->prev : (iter).end; \
(iter).cur != (iter).end; \
(iter).cur = (iter).cur->prev)

Definition at line 557 of file ilist.h.

◆ DLIST_STATIC_INIT

#define DLIST_STATIC_INIT (   name)    {{&(name).head, &(name).head}}

Definition at line 248 of file ilist.h.

◆ dlist_tail_element

#define dlist_tail_element (   type,
  membername,
  lhead 
)
Value:
(AssertVariableIsOfTypeMacro(((type *) NULL)->membername, dlist_node), \
((type *) dlist_tail_element_off(lhead, offsetof(type, membername))))
static void * dlist_tail_element_off(dlist_head *head, size_t off)
Definition: ilist.h:475

Definition at line 515 of file ilist.h.

◆ slist_check

#define slist_check (   head)    ((void) (head))

Definition at line 268 of file ilist.h.

◆ slist_container

#define slist_container (   type,
  membername,
  ptr 
)
Value:
AssertVariableIsOfTypeMacro(((type *) NULL)->membername, slist_node), \
((type *) ((char *) (ptr) - offsetof(type, membername))))

Definition at line 693 of file ilist.h.

◆ slist_foreach

#define slist_foreach (   iter,
  lhead 
)
Value:
(iter).cur = (lhead)->head.next; \
(iter).cur != NULL; \
(iter).cur = (iter).cur->next)

Definition at line 719 of file ilist.h.

◆ slist_foreach_modify

#define slist_foreach_modify (   iter,
  lhead 
)
Value:
(iter).prev = &(lhead)->head, \
(iter).cur = (iter).prev->next, \
(iter).next = (iter).cur ? (iter).cur->next : NULL; \
(iter).cur != NULL; \
(iter).prev = (iter).cur, \
(iter).cur = (iter).next, \
(iter).next = (iter).next ? (iter).next->next : NULL)

Definition at line 735 of file ilist.h.

◆ slist_head_element

#define slist_head_element (   type,
  membername,
  lhead 
)
Value:
(AssertVariableIsOfTypeMacro(((type *) NULL)->membername, slist_node), \
(type *) slist_head_element_off(lhead, offsetof(type, membername)))
static void * slist_head_element_off(slist_head *head, size_t off)
Definition: ilist.h:649

Definition at line 703 of file ilist.h.

◆ SLIST_STATIC_INIT

#define SLIST_STATIC_INIT (   name)    {{NULL}}

Definition at line 249 of file ilist.h.

Typedef Documentation

◆ dlist_head

typedef struct dlist_head dlist_head

◆ dlist_iter

typedef struct dlist_iter dlist_iter

◆ dlist_mutable_iter

◆ dlist_node

typedef struct dlist_node dlist_node

Definition at line 1 of file ilist.h.

◆ slist_head

typedef struct slist_head slist_head

◆ slist_iter

typedef struct slist_iter slist_iter

◆ slist_mutable_iter

◆ slist_node

typedef struct slist_node slist_node

Definition at line 1 of file ilist.h.

Function Documentation

◆ dlist_delete()

◆ dlist_has_next()

static bool dlist_has_next ( dlist_head head,
dlist_node node 
)
inlinestatic

Definition at line 421 of file ilist.h.

422 {
423  return node->next != &head->head;
424 }
dlist_node head
Definition: ilist.h:144

References dlist_head::head, and dlist_node::next.

Referenced by addItemsToLeaf(), dataPlaceToPageLeafSplit(), dlist_next_node(), GenerationReset(), leafRepackItems(), pgstat_flush_pending_entries(), and ReorderBufferIterTXNNext().

◆ dlist_has_prev()

static bool dlist_has_prev ( dlist_head head,
dlist_node node 
)
inlinestatic

Definition at line 431 of file ilist.h.

432 {
433  return node->prev != &head->head;
434 }

References dlist_head::head, and dlist_node::prev.

Referenced by dataBeginPlaceToPageLeaf(), and dlist_prev_node().

◆ dlist_head_element_off()

static void* dlist_head_element_off ( dlist_head head,
size_t  off 
)
inlinestatic

Definition at line 458 of file ilist.h.

459 {
460  Assert(!dlist_is_empty(head));
461  return (char *) head->head.next - off;
462 }
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289
Assert(fmt[strlen(fmt) - 1] !='\n')

References Assert(), dlist_is_empty(), dlist_head::head, and dlist_node::next.

Referenced by dlist_head_node().

◆ dlist_head_node()

static dlist_node* dlist_head_node ( dlist_head head)
inlinestatic

Definition at line 468 of file ilist.h.

469 {
470  return (dlist_node *) dlist_head_element_off(head, 0);
471 }

References dlist_head_element_off().

Referenced by dataPlaceToPageLeafSplit(), GenerationReset(), leafRepackItems(), and pgstat_flush_pending_entries().

◆ dlist_init()

◆ dlist_insert_after()

static void dlist_insert_after ( dlist_node after,
dlist_node node 
)
inlinestatic

Definition at line 334 of file ilist.h.

335 {
336  node->prev = after;
337  node->next = after->next;
338  after->next = node;
339  node->next->prev = node;
340 }

References dlist_node::next, and dlist_node::prev.

Referenced by leafRepackItems().

◆ dlist_insert_before()

static void dlist_insert_before ( dlist_node before,
dlist_node node 
)
inlinestatic

Definition at line 346 of file ilist.h.

347 {
348  node->prev = before->prev;
349  node->next = before;
350  before->prev = node;
351  node->prev->next = node;
352 }
static int before(chr x, chr y)
Definition: regc_locale.c:492

References before(), dlist_node::next, and dlist_node::prev.

Referenced by ReorderBufferTransferSnapToParent().

◆ dlist_is_empty()

◆ dlist_move_head()

static void dlist_move_head ( dlist_head head,
dlist_node node 
)
inlinestatic

Definition at line 385 of file ilist.h.

386 {
387  /* fast path if it's already at the head */
388  if (head->head.next == node)
389  return;
390 
391  dlist_delete(node);
392  dlist_push_head(head, node);
393 
394  dlist_check(head);
395 }
static void dlist_delete(dlist_node *node)
Definition: ilist.h:358
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:300

References dlist_check, dlist_delete(), dlist_push_head(), dlist_head::head, and dlist_node::next.

Referenced by launch_worker(), mXactCacheGetById(), mXactCacheGetBySet(), SearchCatCacheInternal(), and SearchCatCacheList().

◆ dlist_move_tail()

static void dlist_move_tail ( dlist_head head,
dlist_node node 
)
inlinestatic

Definition at line 404 of file ilist.h.

405 {
406  /* fast path if it's already at the tail */
407  if (head->head.prev == node)
408  return;
409 
410  dlist_delete(node);
411  dlist_push_tail(head, node);
412 
413  dlist_check(head);
414 }
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:317

References dlist_check, dlist_delete(), dlist_push_tail(), dlist_head::head, and dlist_node::prev.

Referenced by cache_lookup().

◆ dlist_next_node()

static dlist_node* dlist_next_node ( dlist_head head,
dlist_node node 
)
inlinestatic

Definition at line 440 of file ilist.h.

441 {
442  Assert(dlist_has_next(head, node));
443  return node->next;
444 }
static bool dlist_has_next(dlist_head *head, dlist_node *node)
Definition: ilist.h:421

References Assert(), dlist_has_next(), and dlist_node::next.

Referenced by addItemsToLeaf(), dataPlaceToPageLeafSplit(), leafRepackItems(), pgstat_flush_pending_entries(), and ReorderBufferIterTXNNext().

◆ dlist_pop_head_node()

static dlist_node* dlist_pop_head_node ( dlist_head head)
inlinestatic

Definition at line 368 of file ilist.h.

369 {
370  dlist_node *node;
371 
372  Assert(!dlist_is_empty(head));
373  node = head->head.next;
374  dlist_delete(node);
375  return node;
376 }

References Assert(), dlist_delete(), dlist_is_empty(), dlist_head::head, and dlist_node::next.

Referenced by do_start_worker(), ReorderBufferIterTXNFinish(), and ReorderBufferIterTXNNext().

◆ dlist_prev_node()

static dlist_node* dlist_prev_node ( dlist_head head,
dlist_node node 
)
inlinestatic

Definition at line 450 of file ilist.h.

451 {
452  Assert(dlist_has_prev(head, node));
453  return node->prev;
454 }
static bool dlist_has_prev(dlist_head *head, dlist_node *node)
Definition: ilist.h:431

References Assert(), dlist_has_prev(), and dlist_node::prev.

Referenced by dataBeginPlaceToPageLeaf(), and leafRepackItems().

◆ dlist_push_head()

static void dlist_push_head ( dlist_head head,
dlist_node node 
)
inlinestatic

◆ dlist_push_tail()

◆ dlist_tail_element_off()

static void* dlist_tail_element_off ( dlist_head head,
size_t  off 
)
inlinestatic

Definition at line 475 of file ilist.h.

476 {
477  Assert(!dlist_is_empty(head));
478  return (char *) head->head.prev - off;
479 }

References Assert(), dlist_is_empty(), dlist_head::head, and dlist_node::prev.

Referenced by dlist_tail_node().

◆ dlist_tail_node()

static dlist_node* dlist_tail_node ( dlist_head head)
inlinestatic

Definition at line 485 of file ilist.h.

486 {
487  return (dlist_node *) dlist_tail_element_off(head, 0);
488 }

References dlist_tail_element_off().

Referenced by dataBeginPlaceToPageLeaf(), and mXactCachePut().

◆ slist_delete()

void slist_delete ( slist_head head,
slist_node node 
)

Definition at line 31 of file ilist.c.

32 {
33  slist_node *last = &head->head;
34  slist_node *cur;
35  bool found PG_USED_FOR_ASSERTS_ONLY = false;
36 
37  while ((cur = last->next) != NULL)
38  {
39  if (cur == node)
40  {
41  last->next = cur->next;
42 #ifdef USE_ASSERT_CHECKING
43  found = true;
44 #endif
45  break;
46  }
47  last = cur;
48  }
49  Assert(found);
50 
51  slist_check(head);
52 }
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:155
#define slist_check(head)
Definition: ilist.h:268
slist_node head
Definition: ilist.h:205
slist_node * next
Definition: ilist.h:193

References Assert(), cur, slist_head::head, slist_node::next, cursor::next, PG_USED_FOR_ASSERTS_ONLY, and slist_check.

◆ slist_delete_current()

static void slist_delete_current ( slist_mutable_iter iter)
inlinestatic

Definition at line 671 of file ilist.h.

672 {
673  /*
674  * Update previous element's forward link. If the iteration is at the
675  * first list element, iter->prev will point to the list header's "head"
676  * field, so we don't need a special case for that.
677  */
678  iter->prev->next = iter->next;
679 
680  /*
681  * Reset cur to prev, so that prev will continue to point to the prior
682  * valid list element after slist_foreach_modify() advances to the next.
683  */
684  iter->cur = iter->prev;
685 }
slist_node * next
Definition: ilist.h:242
slist_node * prev
Definition: ilist.h:243
slist_node * cur
Definition: ilist.h:241

References slist_mutable_iter::cur, slist_node::next, slist_mutable_iter::next, and slist_mutable_iter::prev.

Referenced by AtEOSubXact_SPI(), cancel_on_dsm_detach(), ForgetBackgroundWorker(), and SPI_freetuptable().

◆ slist_has_next()

static bool slist_has_next ( slist_head head,
slist_node node 
)
inlinestatic

Definition at line 630 of file ilist.h.

631 {
632  slist_check(head);
633 
634  return node->next != NULL;
635 }

References slist_node::next, and slist_check.

Referenced by slist_next_node().

◆ slist_head_element_off()

static void* slist_head_element_off ( slist_head head,
size_t  off 
)
inlinestatic

Definition at line 649 of file ilist.h.

650 {
651  Assert(!slist_is_empty(head));
652  return (char *) head->head.next - off;
653 }
static bool slist_is_empty(slist_head *head)
Definition: ilist.h:582

References Assert(), slist_head::head, slist_node::next, and slist_is_empty().

Referenced by slist_head_node().

◆ slist_head_node()

static slist_node* slist_head_node ( slist_head head)
inlinestatic

Definition at line 659 of file ilist.h.

660 {
661  return (slist_node *) slist_head_element_off(head, 0);
662 }

References slist_head_element_off().

◆ slist_init()

static void slist_init ( slist_head head)
inlinestatic

Definition at line 573 of file ilist.h.

574 {
575  head->head.next = NULL;
576 }

References slist_head::head, and slist_node::next.

Referenced by dsm_create_descriptor(), EventTriggerBeginCompleteQuery(), InitCatCache(), and SPI_connect_ext().

◆ slist_insert_after()

static void slist_insert_after ( slist_node after,
slist_node node 
)
inlinestatic

Definition at line 605 of file ilist.h.

606 {
607  node->next = after->next;
608  after->next = node;
609 }

References slist_node::next.

◆ slist_is_empty()

static bool slist_is_empty ( slist_head head)
inlinestatic

Definition at line 582 of file ilist.h.

583 {
584  slist_check(head);
585 
586  return head->head.next == NULL;
587 }

References slist_head::head, slist_node::next, and slist_check.

Referenced by dsm_detach(), EventTriggerSQLDrop(), reset_on_dsm_detach(), slist_head_element_off(), and slist_pop_head_node().

◆ slist_next_node()

static slist_node* slist_next_node ( slist_head head,
slist_node node 
)
inlinestatic

Definition at line 641 of file ilist.h.

642 {
643  Assert(slist_has_next(head, node));
644  return node->next;
645 }
static bool slist_has_next(slist_head *head, slist_node *node)
Definition: ilist.h:630

References Assert(), slist_node::next, and slist_has_next().

◆ slist_pop_head_node()

static slist_node* slist_pop_head_node ( slist_head head)
inlinestatic

Definition at line 615 of file ilist.h.

616 {
617  slist_node *node;
618 
619  Assert(!slist_is_empty(head));
620  node = head->head.next;
621  head->head.next = node->next;
622  slist_check(head);
623  return node;
624 }

References Assert(), slist_head::head, slist_node::next, slist_check, and slist_is_empty().

Referenced by dsm_detach(), and reset_on_dsm_detach().

◆ slist_push_head()

static void slist_push_head ( slist_head head,
slist_node node 
)
inlinestatic

Definition at line 593 of file ilist.h.

594 {
595  node->next = head->head.next;
596  head->head.next = node;
597 
598  slist_check(head);
599 }

References slist_head::head, slist_node::next, and slist_check.

Referenced by BackgroundWorkerStateChange(), EventTriggerSQLDropAddObject(), InitCatCache(), on_dsm_detach(), RegisterBackgroundWorker(), and spi_dest_startup().