0003-convert-catcache.h-cc_next-into-an-slist.patch
application/octet-stream
Filename: 0003-convert-catcache.h-cc_next-into-an-slist.patch
Type: application/octet-stream
Part: 2
Message:
Re: embedded list v2
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch 0003
Subject: convert catcache.h cc_next into an slist
| File | + | − |
|---|---|---|
| src/backend/utils/cache/catcache.c | 25 | 15 |
| src/include/utils/catcache.h | 2 | 2 |
From d670675371644e8905944e65b56b967d5b01f572 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Fri, 7 Sep 2012 13:24:52 -0300
Subject: [PATCH 3/3] convert catcache.h cc_next into an slist
---
src/backend/utils/cache/catcache.c | 40 ++++++++++++++++++++++-------------
src/include/utils/catcache.h | 4 +-
2 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 6ebb3ce..14ddcb0 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -291,7 +291,7 @@ CatalogCacheComputeTupleHashValue(CatCache *cache, HeapTuple tuple)
static void
CatCachePrintStats(int code, Datum arg)
{
- CatCache *cache;
+ slist_node *elem;
long cc_searches = 0;
long cc_hits = 0;
long cc_neg_hits = 0;
@@ -300,8 +300,10 @@ CatCachePrintStats(int code, Datum arg)
long cc_lsearches = 0;
long cc_lhits = 0;
- for (cache = CacheHdr->ch_caches; cache; cache = cache->cc_next)
+ slist_foreach(elem, &CacheHdr->ch_caches)
{
+ CatCache *cache = ilist_container(CatCache, cc_next, elem);
+
if (cache->cc_ntup == 0 && cache->cc_searches == 0)
continue; /* don't print unused caches */
elog(DEBUG2, "catcache %s/%u: %d tup, %ld srch, %ld+%ld=%ld hits, %ld+%ld=%ld loads, %ld invals, %ld lsrch, %ld lhits",
@@ -441,19 +443,20 @@ CatCacheRemoveCList(CatCache *cache, CatCList *cl)
void
CatalogCacheIdInvalidate(int cacheId, uint32 hashValue)
{
- CatCache *ccp;
+ slist_node *elem;
CACHE1_elog(DEBUG2, "CatalogCacheIdInvalidate: called");
/*
* inspect caches to find the proper cache
*/
- for (ccp = CacheHdr->ch_caches; ccp; ccp = ccp->cc_next)
+ slist_foreach(elem, &CacheHdr->ch_caches)
{
Index hashIndex;
dlist_node *elt,
*nextelt;
dlist_head *bucket;
+ CatCache *ccp = ilist_container(CatCache, cc_next, elem);
if (cacheId != ccp->id)
continue;
@@ -553,10 +556,11 @@ AtEOXact_CatCache(bool isCommit)
#ifdef USE_ASSERT_CHECKING
if (assert_enabled)
{
- CatCache *ccp;
+ slist_node *elem;
- for (ccp = CacheHdr->ch_caches; ccp; ccp = ccp->cc_next)
+ slist_foreach(elem, &(CacheHdr->ch_caches))
{
+ CatCache *ccp = ilist_container(CatCache, cc_next, elem);
dlist_node *elt;
int i;
@@ -648,12 +652,16 @@ ResetCatalogCache(CatCache *cache)
void
ResetCatalogCaches(void)
{
- CatCache *cache;
+ slist_node *elem;
CACHE1_elog(DEBUG2, "ResetCatalogCaches called");
- for (cache = CacheHdr->ch_caches; cache; cache = cache->cc_next)
+ slist_foreach(elem, &CacheHdr->ch_caches)
+ {
+ CatCache *cache = ilist_container(CatCache, cc_next, elem);
+
ResetCatalogCache(cache);
+ }
CACHE1_elog(DEBUG2, "end of ResetCatalogCaches call");
}
@@ -674,12 +682,14 @@ ResetCatalogCaches(void)
void
CatalogCacheFlushCatalog(Oid catId)
{
- CatCache *cache;
+ slist_node *elem;
CACHE2_elog(DEBUG2, "CatalogCacheFlushCatalog called for %u", catId);
- for (cache = CacheHdr->ch_caches; cache; cache = cache->cc_next)
+ slist_foreach(elem, &(CacheHdr->ch_caches))
{
+ CatCache *cache = ilist_container(CatCache, cc_next, elem);
+
/* Does this cache store tuples of the target catalog? */
if (cache->cc_reloid == catId)
{
@@ -754,7 +764,7 @@ InitCatCache(int id,
if (CacheHdr == NULL)
{
CacheHdr = (CatCacheHeader *) palloc(sizeof(CatCacheHeader));
- CacheHdr->ch_caches = NULL;
+ slist_init(&CacheHdr->ch_caches);
CacheHdr->ch_ntup = 0;
#ifdef CATCACHE_STATS
/* set up to dump stats at backend exit */
@@ -798,8 +808,7 @@ InitCatCache(int id,
/*
* add completed cache to top of group header's list
*/
- cp->cc_next = CacheHdr->ch_caches;
- CacheHdr->ch_caches = cp;
+ slist_push_head(&CacheHdr->ch_caches, &cp->cc_next);
/*
* back to the old context before we return...
@@ -1782,7 +1791,7 @@ PrepareToInvalidateCacheTuple(Relation relation,
HeapTuple newtuple,
void (*function) (int, uint32, Oid))
{
- CatCache *ccp;
+ slist_node *elem;
Oid reloid;
CACHE1_elog(DEBUG2, "PrepareToInvalidateCacheTuple: called");
@@ -1805,10 +1814,11 @@ PrepareToInvalidateCacheTuple(Relation relation,
* ----------------
*/
- for (ccp = CacheHdr->ch_caches; ccp; ccp = ccp->cc_next)
+ slist_foreach(elem, &(CacheHdr->ch_caches))
{
uint32 hashvalue;
Oid dbid;
+ CatCache *ccp = ilist_container(CatCache, cc_next, elem);
if (ccp->cc_reloid != reloid)
continue;
diff --git a/src/include/utils/catcache.h b/src/include/utils/catcache.h
index 1e59ea4..cc6dab2 100644
--- a/src/include/utils/catcache.h
+++ b/src/include/utils/catcache.h
@@ -37,7 +37,7 @@
typedef struct catcache
{
int id; /* cache identifier --- see syscache.h */
- struct catcache *cc_next; /* link to next catcache */
+ slist_node cc_next; /* list link */
const char *cc_relname; /* name of relation the tuples come from */
Oid cc_reloid; /* OID of relation the tuples come from */
Oid cc_indexoid; /* OID of index matching cache keys */
@@ -154,7 +154,7 @@ typedef struct catclist
typedef struct catcacheheader
{
- CatCache *ch_caches; /* head of list of CatCache structs */
+ slist_head ch_caches; /* head of list of CatCache structs */
int ch_ntup; /* # of tuples in all caches */
} CatCacheHeader;
--
1.7.2.5