Fixed allocation of multiple shared memory chunks.

Previously, one shared memory chunk was allocated under mutex and other
chunks (if required) were allocated using atomic operations.  So such
allocation is not guaranteed and the result buffer can be less than
requested.

This commit moves multiple chunks allocation under mutex and guarantees
the result buffer is large enough.
This commit is contained in:
Max Romanov
2018-06-20 19:11:27 +03:00
parent 6157a599f2
commit b1d7844449
2 changed files with 52 additions and 35 deletions

View File

@@ -129,13 +129,20 @@ nxt_port_mmap_chunk_start(nxt_port_mmap_header_t *hdr, nxt_chunk_id_t c)
static nxt_bool_t
nxt_port_mmap_get_free_chunk(nxt_free_map_t *m, nxt_chunk_id_t *c)
{
int ffs;
size_t i;
nxt_chunk_id_t chunk;
nxt_free_map_t bits;
const nxt_free_map_t default_mask = (nxt_free_map_t) -1;
int ffs;
size_t i, start;
nxt_chunk_id_t chunk;
nxt_free_map_t bits, mask;
start = FREE_IDX(*c);
mask = default_mask << ((*c) % FREE_BITS);
for (i = start; i < MAX_FREE_IDX; i++) {
bits = m[i] & mask;
mask = default_mask;
for (i = 0; i < MAX_FREE_IDX; i++) {
bits = m[i];
if (bits == 0) {
continue;
}