Allocate the bitset in the foreground thread.

This prevents the possibility of a race in dereferencing it in the
client threads.
This commit is contained in:
Alex Young
2012-10-09 17:54:00 +01:00
parent 22bea81445
commit dcef6d29e5

View File

@@ -762,12 +762,13 @@ void* build_allocation_map_thread(void* serve_uncast)
NULLCHECK( serve_uncast );
struct server* serve = (struct server*) serve_uncast;
NULLCHECK( serve->filename );
NULLCHECK( serve->allocation_map );
int fd = open( serve->filename, O_RDONLY );
FATAL_IF_NEGATIVE( fd, "Couldn't open %s", serve->filename );
serve->allocation_map =
bitset_alloc(serve->size, block_allocation_resolution);
if ( build_allocation_map( serve->allocation_map, fd ) ) {
serve->allocation_map_built = 1;
}
@@ -785,6 +786,7 @@ void* build_allocation_map_thread(void* serve_uncast)
void serve_init_allocation_map(struct server* params)
{
NULLCHECK( params );
NULLCHECK( params->filename );
int fd = open( params->filename, O_RDONLY );
off64_t size;
@@ -794,9 +796,16 @@ void serve_init_allocation_map(struct server* params)
params->size = size;
FATAL_IF_NEGATIVE( size, "Couldn't find size of %s",
params->filename );
FATAL_IF_NEGATIVE(pthread_create(&params->allocation_map_builder_thread,
NULL, build_allocation_map_thread, params),
"Couldn't create thread");
params->allocation_map =
bitset_alloc( params->size, block_allocation_resolution );
int ok = pthread_create( &params->allocation_map_builder_thread,
NULL,
build_allocation_map_thread,
params );
FATAL_IF_NEGATIVE( ok, "Couldn't create thread" );
}