2016-08-16 00:09:55 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* proclist_types.h
|
|
|
|
* doubly-linked lists of pgprocnos
|
|
|
|
*
|
|
|
|
* See proclist.h for functions that operate on these types.
|
|
|
|
*
|
2023-01-02 21:00:37 +01:00
|
|
|
* Portions Copyright (c) 2016-2023, PostgreSQL Global Development Group
|
2016-08-16 00:09:55 +02:00
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/include/storage/proclist_types.h
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PROCLIST_TYPES_H
|
|
|
|
#define PROCLIST_TYPES_H
|
|
|
|
|
|
|
|
/*
|
Improve error detection capability in proclists.
Previously, although the initial state of a proclist_node is expected
to be next == prev == 0, proclist_delete_offset would reset nodes to
next == prev == INVALID_PGPROCNO when removing them from a list.
This is the same state that a node in a singleton list has, so that
it's impossible to distinguish not-in-a-list from in-a-list. Change
proclist_delete_offset to reset removed nodes to next == prev == 0,
making it possible to distinguish those cases, and then add Asserts
to the list add and delete functions that the supplied node isn't
or is in a list at entry. Also tighten assertions about the node
being in the particular list (not some other one) where it is possible
to check that in O(1) time.
In ConditionVariablePrepareToSleep, since we don't expect the process's
cvWaitLink to already be in a list, remove the more-or-less-useless
proclist_contains check; we'd rather have proclist_push_tail's new
assertion fire if that happens.
Improve various comments related to proclists, too.
Patch by me, reviewed by Thomas Munro. This isn't back-patchable, since
there could theoretically be inlined copies of proclist_delete_offset in
third-party modules. But it's only improving debuggability anyway.
Discussion: https://postgr.es/m/CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com
2018-01-09 00:07:04 +01:00
|
|
|
* A node in a doubly-linked list of processes. The link fields contain
|
|
|
|
* the 0-based PGPROC indexes of the next and previous process, or
|
|
|
|
* INVALID_PGPROCNO in the next-link of the last node and the prev-link
|
|
|
|
* of the first node. A node that is currently not in any list
|
|
|
|
* should have next == prev == 0; this is not a possible state for a node
|
|
|
|
* that is in a list, because we disallow circularity.
|
2016-08-16 00:09:55 +02:00
|
|
|
*/
|
|
|
|
typedef struct proclist_node
|
|
|
|
{
|
|
|
|
int next; /* pgprocno of the next PGPROC */
|
|
|
|
int prev; /* pgprocno of the prev PGPROC */
|
|
|
|
} proclist_node;
|
|
|
|
|
|
|
|
/*
|
Improve error detection capability in proclists.
Previously, although the initial state of a proclist_node is expected
to be next == prev == 0, proclist_delete_offset would reset nodes to
next == prev == INVALID_PGPROCNO when removing them from a list.
This is the same state that a node in a singleton list has, so that
it's impossible to distinguish not-in-a-list from in-a-list. Change
proclist_delete_offset to reset removed nodes to next == prev == 0,
making it possible to distinguish those cases, and then add Asserts
to the list add and delete functions that the supplied node isn't
or is in a list at entry. Also tighten assertions about the node
being in the particular list (not some other one) where it is possible
to check that in O(1) time.
In ConditionVariablePrepareToSleep, since we don't expect the process's
cvWaitLink to already be in a list, remove the more-or-less-useless
proclist_contains check; we'd rather have proclist_push_tail's new
assertion fire if that happens.
Improve various comments related to proclists, too.
Patch by me, reviewed by Thomas Munro. This isn't back-patchable, since
there could theoretically be inlined copies of proclist_delete_offset in
third-party modules. But it's only improving debuggability anyway.
Discussion: https://postgr.es/m/CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com
2018-01-09 00:07:04 +01:00
|
|
|
* Header of a doubly-linked list of PGPROCs, identified by pgprocno.
|
|
|
|
* An empty list is represented by head == tail == INVALID_PGPROCNO.
|
2016-08-16 00:09:55 +02:00
|
|
|
*/
|
|
|
|
typedef struct proclist_head
|
|
|
|
{
|
|
|
|
int head; /* pgprocno of the head PGPROC */
|
|
|
|
int tail; /* pgprocno of the tail PGPROC */
|
|
|
|
} proclist_head;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* List iterator allowing some modifications while iterating.
|
|
|
|
*/
|
|
|
|
typedef struct proclist_mutable_iter
|
|
|
|
{
|
|
|
|
int cur; /* pgprocno of the current PGPROC */
|
|
|
|
int next; /* pgprocno of the next PGPROC */
|
|
|
|
} proclist_mutable_iter;
|
|
|
|
|
Improve error detection capability in proclists.
Previously, although the initial state of a proclist_node is expected
to be next == prev == 0, proclist_delete_offset would reset nodes to
next == prev == INVALID_PGPROCNO when removing them from a list.
This is the same state that a node in a singleton list has, so that
it's impossible to distinguish not-in-a-list from in-a-list. Change
proclist_delete_offset to reset removed nodes to next == prev == 0,
making it possible to distinguish those cases, and then add Asserts
to the list add and delete functions that the supplied node isn't
or is in a list at entry. Also tighten assertions about the node
being in the particular list (not some other one) where it is possible
to check that in O(1) time.
In ConditionVariablePrepareToSleep, since we don't expect the process's
cvWaitLink to already be in a list, remove the more-or-less-useless
proclist_contains check; we'd rather have proclist_push_tail's new
assertion fire if that happens.
Improve various comments related to proclists, too.
Patch by me, reviewed by Thomas Munro. This isn't back-patchable, since
there could theoretically be inlined copies of proclist_delete_offset in
third-party modules. But it's only improving debuggability anyway.
Discussion: https://postgr.es/m/CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com
2018-01-09 00:07:04 +01:00
|
|
|
#endif /* PROCLIST_TYPES_H */
|