forked from KolibriOS/kolibrios
menuetlibc: thread-safe malloc
git-svn-id: svn://kolibrios.org@5129 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
347bbd1570
commit
73dfca6a00
@ -110,7 +110,7 @@ split_block(BLOCK *b, size_t size)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RET(rv) CHECK(rv); ENDSZ(rv) |= 1; rv->size |= 1; return DATA(rv)
|
#define RET(rv) CHECK(rv); ENDSZ(rv) |= 1; rv->size |= 1; malloc_unlock(); return DATA(rv)
|
||||||
|
|
||||||
void * malloc(size_t size)
|
void * malloc(size_t size)
|
||||||
{
|
{
|
||||||
@ -124,6 +124,8 @@ void * malloc(size_t size)
|
|||||||
printf("malloc(%u)\n", size);
|
printf("malloc(%u)\n", size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
malloc_lock();
|
||||||
|
|
||||||
#if NUMSMALL
|
#if NUMSMALL
|
||||||
if (size < SMALL)
|
if (size < SMALL)
|
||||||
{
|
{
|
||||||
@ -131,6 +133,7 @@ void * malloc(size_t size)
|
|||||||
if (rv)
|
if (rv)
|
||||||
{
|
{
|
||||||
smallblocks[size/ALIGN] = rv->next;
|
smallblocks[size/ALIGN] = rv->next;
|
||||||
|
malloc_unlock();
|
||||||
return DATA(rv);
|
return DATA(rv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,8 +208,10 @@ void * malloc(size_t size)
|
|||||||
|
|
||||||
chunk_size = size+16; /* two ends plus two placeholders */
|
chunk_size = size+16; /* two ends plus two placeholders */
|
||||||
rv = (BLOCK *)sbrk(chunk_size);
|
rv = (BLOCK *)sbrk(chunk_size);
|
||||||
if (rv == (BLOCK *)(-1))
|
if (rv == (BLOCK *)(-1)) {
|
||||||
|
malloc_unlock();
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
printf("sbrk(%d) -> %08x, expected %08x\n", chunk_size, rv, expected_sbrk);
|
printf("sbrk(%d) -> %08x, expected %08x\n", chunk_size, rv, expected_sbrk);
|
||||||
#endif
|
#endif
|
||||||
@ -297,11 +302,14 @@ free(void *ptr)
|
|||||||
return;
|
return;
|
||||||
block = (BLOCK *)((char *)ptr-4);
|
block = (BLOCK *)((char *)ptr-4);
|
||||||
|
|
||||||
|
malloc_lock();
|
||||||
|
|
||||||
#if NUMSMALL
|
#if NUMSMALL
|
||||||
if (block->size < SMALL)
|
if (block->size < SMALL)
|
||||||
{
|
{
|
||||||
block->next = smallblocks[block->size/ALIGN];
|
block->next = smallblocks[block->size/ALIGN];
|
||||||
smallblocks[block->size/ALIGN] = block;
|
smallblocks[block->size/ALIGN] = block;
|
||||||
|
malloc_unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -335,6 +343,7 @@ free(void *ptr)
|
|||||||
block->next = freelist[b];
|
block->next = freelist[b];
|
||||||
freelist[b] = block;
|
freelist[b] = block;
|
||||||
CHECK(block);
|
CHECK(block);
|
||||||
|
malloc_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void * realloc(void *ptr, size_t size)
|
void * realloc(void *ptr, size_t size)
|
||||||
|
Loading…
Reference in New Issue
Block a user