Minor optimization of allocator.
authorRobert Haas <rhaas@postgresql.org>
Wed, 1 Aug 2012 23:48:41 +0000 (23:48 +0000)
committerRobert Haas <rhaas@postgresql.org>
Mon, 13 Oct 2014 17:14:19 +0000 (13:14 -0400)
src/backend/utils/hash/chash.c

index 1fc507af1819be7efef6d47ecba0a59df0db81a9..4cb837183519bca95d405ce5bd0142348161cddb 100644 (file)
@@ -947,8 +947,14 @@ CHashAllocate(CHashTable table)
            pg_read_barrier_depends();
            fhead = n->un.gcnext;
 
-           /* Put any remaining elements back on the free list. */
-           if (!CHashPtrIsInvalid(fhead))
+           /*
+            * Prepend everything except the one node we've saved to satisfy
+            * this allocation to the free list.  If the free list is empty,
+            * we needn't update the list any further; otherwise, we've got
+            * to adjust the next-pointer in the last of the reclaimed nodes.
+            */
+           if (!CHashPtrIsInvalid(fhead)
+               && !__sync_bool_compare_and_swap(fh, InvalidCHashPtr, fhead))
            {
                CHashPtr    fcurrent;
                CHashPtr    fnext;