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;