From: Robert Haas Date: Fri, 27 Jul 2012 16:34:50 +0000 (+0000) Subject: Thinko: of course, invalid CHashPtrs can also be delete-marked. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=50a0f6747c5fbe5fcc9555101e936b6935a3f4fc;p=users%2Fandresfreund%2Fpostgres.git Thinko: of course, invalid CHashPtrs can also be delete-marked. --- diff --git a/src/backend/utils/hash/chash.c b/src/backend/utils/hash/chash.c index cfef6d5745..a076da07c2 100644 --- a/src/backend/utils/hash/chash.c +++ b/src/backend/utils/hash/chash.c @@ -105,6 +105,7 @@ */ typedef uint32 CHashPtr; #define InvalidCHashPtr ((uint32) -2) +#define CHashPtrIsInvalid(x) ((x) >= InvalidCHashPtr) #define CHashPtrIsMarked(x) ((x) & 1) #define CHashPtrGetOffset(x) ((x) >> 1) #define CHashPtrMark(x) ((x) | 1) @@ -160,7 +161,7 @@ typedef struct CHashTableData (AssertMacro((offset) < (table)->arena_limit), \ (CHashNode *) ((table)->arena + (table)->arena_stride * (offset))) #define CHashTableGetNode(table, ptr) \ - (AssertMacro((ptr) != InvalidCHashPtr), \ + (AssertMacro(!CHashPtrIsInvalid(ptr)), \ CHashTableGetRaw((table), CHashPtrGetOffset((ptr)))) /* @@ -580,7 +581,7 @@ retry: * If we've reached the end of the bucket chain, stop; otherwise, * figure out the actual address of the next item. */ - if (target == InvalidCHashPtr) + if (CHashPtrIsInvalid(target)) { res->found = false; break; @@ -748,7 +749,7 @@ CHashAllocate(CHashTable table) /* Try to pop a buffer from a freelist using compare-and-swap. */ b = &table->freelist[f_current]; new = *b; - if (new != InvalidCHashPtr) + if (!CHashPtrIsInvalid(new)) { CHashNode *n = CHashTableGetNode(table, new); @@ -766,7 +767,7 @@ CHashAllocate(CHashTable table) table->gc_next = (table->gc_next + 1) % table->ngarbage; b = &table->garbage[table->gc_next]; garbage = *b; - if (garbage != InvalidCHashPtr && + if (!CHashPtrIsInvalid(garbage) && __sync_bool_compare_and_swap(b, garbage, InvalidCHashPtr)) { uint64 chash_bucket; @@ -801,7 +802,7 @@ CHashAllocate(CHashTable table) fhead = n->un.gcnext; /* Put any remaining elements back on the free list. */ - if (fhead != InvalidCHashPtr) + if (!CHashPtrIsInvalid(fhead)) { CHashPtr fcurrent; CHashPtr fnext; @@ -813,7 +814,7 @@ CHashAllocate(CHashTable table) { n = CHashTableGetNode(table, fcurrent); fnext = n->un.gcnext; - if (fnext == InvalidCHashPtr) + if (CHashPtrIsInvalid(fnext)) break; fcurrent = fnext; } @@ -922,7 +923,7 @@ retry: * If we've reached the end of the bucket chain, stop; otherwise, * figure out the actual address of the next item. */ - if (target == InvalidCHashPtr) + if (CHashPtrIsInvalid(target)) break; target_node = CHashTableGetNode(table, target);