diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-07-24 17:42:03 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-07-24 17:42:48 -0400 |
commit | cf707aa70da6729a00593c49d5eb8a35ab27dd11 (patch) | |
tree | 4cd9953b51727494b4079a4f0969d21915149d43 /src/backend/postmaster/pgstat.c | |
parent | 4a67a9ac13495d69b4d3b560b63cafda9318b4f4 (diff) | |
download | postgresql-cf707aa70da6729a00593c49d5eb8a35ab27dd11.tar.gz postgresql-cf707aa70da6729a00593c49d5eb8a35ab27dd11.zip |
Improve ilist.h's support for deletion of slist elements during iteration.
Previously one had to use slist_delete(), implying an additional scan of
the list, making this infrastructure considerably less efficient than
traditional Lists when deletion of element(s) in a long list is needed.
Modify the slist_foreach_modify() macro to support deleting the current
element in O(1) time, by keeping a "prev" pointer in addition to "cur"
and "next". Although this makes iteration with this macro a bit slower,
no real harm is done, since in any scenario where you're not going to
delete the current list element you might as well just use slist_foreach
instead. Improve the comments about when to use each macro.
Back-patch to 9.3 so that we'll have consistent semantics in all branches
that provide ilist.h. Note this is an ABI break for callers of
slist_foreach_modify().
Andres Freund and Tom Lane
Diffstat (limited to 'src/backend/postmaster/pgstat.c')
-rw-r--r-- | src/backend/postmaster/pgstat.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index ac20dffd988..dac5bca78aa 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -3598,6 +3598,13 @@ pgstat_write_statsfiles(bool permanent, bool allDbs) { slist_mutable_iter iter; + /* + * Strictly speaking we should do slist_delete_current() before + * freeing each request struct. We skip that and instead + * re-initialize the list header at the end. Nonetheless, we must use + * slist_foreach_modify, not just slist_foreach, since we will free + * the node's storage before advancing. + */ slist_foreach_modify(iter, &last_statrequests) { DBWriteRequest *req; |