Refactor arenas array (fixes deadlock).

Refactor the arenas array, which contains pointers to all extant arenas,
such that it starts out as a sparse array of maximum size, and use
double-checked atomics-based reads as the basis for fast and simple
arena_get().  Additionally, reduce arenas_lock's role such that it only
protects against arena initalization races.  These changes remove the
possibility for arena lookups to trigger locking, which resolves at
least one known (fork-related) deadlock.

This resolves #315.
This commit is contained in:
Jason Evans 2016-02-24 23:58:10 -08:00
parent 3812729167
commit 767d85061a
9 changed files with 162 additions and 214 deletions

View file

@ -3261,6 +3261,27 @@ arena_stats_merge(arena_t *arena, const char **dss, ssize_t *lg_dirty_mult,
}
}
unsigned
arena_nthreads_get(arena_t *arena)
{
return (atomic_read_u(&arena->nthreads));
}
void
arena_nthreads_inc(arena_t *arena)
{
atomic_add_u(&arena->nthreads, 1);
}
void
arena_nthreads_dec(arena_t *arena)
{
atomic_sub_u(&arena->nthreads, 1);
}
arena_t *
arena_new(unsigned ind)
{