mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 15:29:31 +03:00
fix for incorrect region count
This commit is contained in:
parent
f3c082462b
commit
b7e506ad9d
1 changed files with 5 additions and 8 deletions
13
src/memory.c
13
src/memory.c
|
@ -152,15 +152,12 @@ static bool mi_region_commit_blocks(mem_region_t* region, size_t idx, size_t bit
|
||||||
else {
|
else {
|
||||||
// failed, another thread allocated just before us!
|
// failed, another thread allocated just before us!
|
||||||
// we assign it to a later slot instead (up to 4 tries).
|
// we assign it to a later slot instead (up to 4 tries).
|
||||||
// note: we don't need to increment the region count, this will happen on another allocation
|
|
||||||
for(size_t i = 1; i <= 4 && idx + i < MI_REGION_MAX; i++) {
|
for(size_t i = 1; i <= 4 && idx + i < MI_REGION_MAX; i++) {
|
||||||
void* s = mi_atomic_read_ptr(®ions[idx+i].start);
|
if (mi_atomic_cas_ptr_strong(®ions[idx+i].start, start, NULL)) {
|
||||||
if (s == NULL) { // quick test
|
mi_atomic_increment(®ions_count);
|
||||||
if (mi_atomic_cas_ptr_strong(®ions[idx+i].start, start, NULL)) {
|
start = NULL;
|
||||||
start = NULL;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (start != NULL) {
|
if (start != NULL) {
|
||||||
// free it if we didn't succeed to save it to some other region
|
// free it if we didn't succeed to save it to some other region
|
||||||
|
|
Loading…
Add table
Reference in a new issue