summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_port_memory_int.h
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2018-06-20 19:11:27 +0300
committerMax Romanov <max.romanov@nginx.com>2018-06-20 19:11:27 +0300
commitb1d7844449b813f8dde73da4e11b8b2d8233f704 (patch)
treed3043eb7149b6d853de28c2f08319fec8b9a3c60 /src/nxt_port_memory_int.h
parent6157a599f2d14a933409afdb0f41a8327950ffab (diff)
downloadunit-b1d7844449b813f8dde73da4e11b8b2d8233f704.tar.gz
unit-b1d7844449b813f8dde73da4e11b8b2d8233f704.tar.bz2
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.
Diffstat (limited to 'src/nxt_port_memory_int.h')
-rw-r--r--src/nxt_port_memory_int.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/nxt_port_memory_int.h b/src/nxt_port_memory_int.h
index 589416b6..e56eb4c8 100644
--- a/src/nxt_port_memory_int.h
+++ b/src/nxt_port_memory_int.h
@@ -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)
{
+ const nxt_free_map_t default_mask = (nxt_free_map_t) -1;
+
int ffs;
- size_t i;
+ size_t i, start;
nxt_chunk_id_t chunk;
- nxt_free_map_t bits;
+ 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;
}