mirror of
https://github.com/fluencelabs/musl
synced 2025-04-24 23:02:14 +00:00
fix unsorted bin problem
This commit is contained in:
parent
4d66a5607e
commit
9cdf2f77d5
@ -284,6 +284,34 @@ static void trim(struct chunk *self, size_t n)
|
|||||||
__bin_chunk(split);
|
__bin_chunk(split);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns chunk which size is more then given n from the 64-th unsorted bin
|
||||||
|
// if there is no suitable chunk returns 0
|
||||||
|
static struct chunk *get_chunk_from_unsorted_bin(size_t n)
|
||||||
|
{
|
||||||
|
const int unsorted_bin_id = 63;
|
||||||
|
struct chunk *current = 0;
|
||||||
|
|
||||||
|
lock_bin(unsorted_bin_id);
|
||||||
|
current = mal.bins[unsorted_bin_id].head;
|
||||||
|
|
||||||
|
while(current != 0 && current != mal.bins[unsorted_bin_id].tail) {
|
||||||
|
// it is a the first-fit strategy
|
||||||
|
if(current->csize >= n) {
|
||||||
|
if (!pretrim(current, n, unsorted_bin_id, unsorted_bin_id)) {
|
||||||
|
unbin(current, unsorted_bin_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
unlock_bin(unsorted_bin_id);
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
current = current->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
unlock_bin(unsorted_bin_id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void *malloc(size_t n)
|
void *malloc(size_t n)
|
||||||
{
|
{
|
||||||
struct chunk *c;
|
struct chunk *c;
|
||||||
@ -305,7 +333,14 @@ void *malloc(size_t n)
|
|||||||
i = bin_index_up(n);
|
i = bin_index_up(n);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
uint64_t mask = mal.binmap & -(1ULL<<i);
|
uint64_t mask = mal.binmap & -(1ULL<<i);
|
||||||
if (!mask) {
|
if (i == 64) {
|
||||||
|
c = get_chunk_from_unsorted_bin(n);
|
||||||
|
if(c != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 64 || !mask) {
|
||||||
c = expand_heap(n);
|
c = expand_heap(n);
|
||||||
if (!c) return 0;
|
if (!c) return 0;
|
||||||
if (alloc_rev(c)) {
|
if (alloc_rev(c)) {
|
||||||
@ -316,6 +351,7 @@ void *malloc(size_t n)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
j = first_set(mask);
|
j = first_set(mask);
|
||||||
lock_bin(j);
|
lock_bin(j);
|
||||||
c = mal.bins[j].head;
|
c = mal.bins[j].head;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user