• Tom Lane's avatar
    Improve error detection capability in proclists. · ea8e1bbc
    Tom Lane authored
    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
    ea8e1bbc
condition_variable.c 9.87 KB