From: Robert Haas Date: Fri, 13 Jul 2012 23:09:26 +0000 (-0400) Subject: More initialization code. X-Git-Url: http://git.postgresql.org/gitweb/static/developers.postgresql.org?a=commitdiff_plain;h=f26dd3586e58e4a9366eec40d532c0b7f4598889;p=users%2Fandresfreund%2Fpostgres.git More initialization code. --- diff --git a/src/backend/utils/hash/chash.c b/src/backend/utils/hash/chash.c index 3d9adca098..50fdafca43 100644 --- a/src/backend/utils/hash/chash.c +++ b/src/backend/utils/hash/chash.c @@ -19,7 +19,9 @@ * while arena offsets can be stored in a 32-bit word. In fact, we * reserve one bit in each such word as a mark bit, so the maximum size * of the arena is 2^31 elements, a restriction that does not currently - * appear to be problematic. + * appear to be problematic. An additional advantage of this representation + * is that aligned 32-bit loads and stores are atomic on all architectures + * we support, but 64-bit loads and stores are not. * * When an element is inserted, we copy the data from the backend-private * object supplied by the caller into one of these shared-memory entities. @@ -250,6 +252,7 @@ CHashInitialize(CHashTable table, CHashDescriptor *desc) Size size; bool found; void *shmem; + uint32 i; /* * If we're under the postmaster, this must be the EXEC_BACKEND case where @@ -286,8 +289,32 @@ CHashInitialize(CHashTable table, CHashDescriptor *desc) /* Arena follows the various lists. */ table->arena = (void *) (&table->freelist[table->nfreelists]); - /* XXX. Must initialize spinlocks, set lists to empty, and then put - * all arena nodes on free lists. */ + /* Initialize all three sets of lists to empty. */ + for (i = 0; i < table->nbuckets; ++i) + { + table->bucket[i].head = InvalidCHashPtr; + SpinLockInit(&table->bucket[i].head); + } + for (i = 0; i < table->ngarbage; ++i) + { + table->garbage[i].head = InvalidCHashPtr; + SpinLockInit(&table->garbage[i].head); + } + for (i = 0; i < table->nfreelists; ++i) + { + table->freelist[i].head = InvalidCHashPtr; + SpinLockInit(&table->freelist[i].head); + } + + /* Put all arena elements on the free lists. */ + for (i = 0; i < table->arena_limit; ++i) + { + CHashBucket *f = &table->freelist[i % table->nfreelists]; + CHashNode *n = CHashTableGetNode(table, i); + + n->next = f->head; + f->head = i; + } /* * Copy table (with pointers now filled in) to shared memory. This is