forked from len0rd/rockbox
fixed warnings, indented properly
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@575 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
e5992829d7
commit
28bdaca814
1 changed files with 295 additions and 278 deletions
|
@ -160,7 +160,7 @@ struct MemInfo {
|
||||||
happy with us.
|
happy with us.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const static short qinfo[]= {
|
static const unsigned short qinfo[]= {
|
||||||
20, 28, 52, 116, 312, 580, 1016, 2032
|
20, 28, 52, 116, 312, 580, 1016, 2032
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ static struct MemTop top[ sizeof(qinfo)/sizeof(qinfo[0]) ];
|
||||||
|
|
||||||
void dmalloc_status(void)
|
void dmalloc_status(void)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned int i;
|
||||||
int used;
|
int used;
|
||||||
int num;
|
int num;
|
||||||
int totalfree=0;
|
int totalfree=0;
|
||||||
|
@ -276,7 +276,7 @@ static void FragBlock(char *memp, int size)
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
void dmalloc_initialize(void)
|
void dmalloc_initialize(void)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned int i;
|
||||||
/* Setup the nmax and fragsize fields of the top structs */
|
/* Setup the nmax and fragsize fields of the top structs */
|
||||||
for(i=0; i< sizeof(qinfo)/sizeof(qinfo[0]); i++) {
|
for(i=0; i< sizeof(qinfo)/sizeof(qinfo[0]); i++) {
|
||||||
top[i].fragsize = qinfo[i];
|
top[i].fragsize = qinfo[i];
|
||||||
|
@ -358,7 +358,7 @@ void *dmalloc(size_t size)
|
||||||
struct MemTop *memtop=NULL; /* SAFE */
|
struct MemTop *memtop=NULL; /* SAFE */
|
||||||
|
|
||||||
/* Determine which queue to use */
|
/* Determine which queue to use */
|
||||||
int queue;
|
unsigned int queue;
|
||||||
for(queue=0; size > qinfo[queue]; queue++)
|
for(queue=0; size > qinfo[queue]; queue++)
|
||||||
;
|
;
|
||||||
do {
|
do {
|
||||||
|
@ -383,7 +383,7 @@ void *dmalloc(size_t size)
|
||||||
if(memtop->nfree) {
|
if(memtop->nfree) {
|
||||||
/* there exists a free FRAGMENT in this chain */
|
/* there exists a free FRAGMENT in this chain */
|
||||||
|
|
||||||
/* I WANT THIS LOOP OUT OF HERE! */
|
/**** We'd prefer to not have this loop here! ****/
|
||||||
|
|
||||||
/* search for the free FRAGMENT */
|
/* search for the free FRAGMENT */
|
||||||
while(!block->nfree)
|
while(!block->nfree)
|
||||||
|
@ -397,17 +397,19 @@ void *dmalloc(size_t size)
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* we do *not* have a free FRAGMENT but need to get us a new BLOCK */
|
/* we do *not* have a free FRAGMENT but need to get us a new
|
||||||
|
* BLOCK */
|
||||||
|
|
||||||
DMEM_OSALLOCMEM(DMEM_BLOCKSIZE + sizeof(struct MemBlock),
|
DMEM_OSALLOCMEM(DMEM_BLOCKSIZE + sizeof(struct MemBlock),
|
||||||
newblock,
|
newblock,
|
||||||
struct MemBlock *);
|
struct MemBlock *);
|
||||||
if(!newblock) {
|
if(!newblock) {
|
||||||
if(++queue < sizeof(qinfo)/sizeof(qinfo[0])) {
|
if(++queue < sizeof(qinfo)/sizeof(qinfo[0])) {
|
||||||
/* There are queues for bigger FRAGMENTS that we should check
|
/* There are queues for bigger FRAGMENTS that we
|
||||||
before we fail this for real */
|
* should check before we fail this for real */
|
||||||
#ifdef DEBUG_VERBOSE
|
#ifdef DEBUG_VERBOSE
|
||||||
printf("*** " __FILE__ " Trying a bigger Q: %d\n", queue);
|
printf("*** " __FILE__ " Trying a bigger Q: %d\n",
|
||||||
|
queue);
|
||||||
#endif
|
#endif
|
||||||
mem = NULL;
|
mem = NULL;
|
||||||
}
|
}
|
||||||
|
@ -418,13 +420,16 @@ void *dmalloc(size_t size)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* allocation of big BLOCK was successful */
|
/* allocation of big BLOCK was successful */
|
||||||
|
MEMINCR(newblock, DMEM_BLOCKSIZE +
|
||||||
|
sizeof(struct MemBlock));
|
||||||
|
|
||||||
MEMINCR(newblock, DMEM_BLOCKSIZE + sizeof(struct MemBlock));
|
memtop->chain = newblock; /* attach this BLOCK to the
|
||||||
|
chain */
|
||||||
memtop->chain = newblock; /* attach this BLOCK to the chain */
|
newblock->next = block; /* point to the previous first
|
||||||
newblock->next = block; /* point to the previous first BLOCK */
|
BLOCK */
|
||||||
if(block)
|
if(block)
|
||||||
block->prev = newblock; /* point back on this new BLOCK */
|
block->prev = newblock; /* point back on this new
|
||||||
|
BLOCK */
|
||||||
newblock->prev = NULL; /* no previous */
|
newblock->prev = NULL; /* no previous */
|
||||||
newblock->top = memtop; /* our head master */
|
newblock->top = memtop; /* our head master */
|
||||||
|
|
||||||
|
@ -531,7 +536,9 @@ void dfree(void *memp)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* big stand-alone block, just give it back to the OS: */
|
/* big stand-alone block, just give it back to the OS: */
|
||||||
MEMDECR(meminfo->block, (size_t)meminfo->block&~BLOCK_BIT); /* clean BLOCK_BIT */
|
|
||||||
|
/* clean BLOCK_BIT */
|
||||||
|
MEMDECR(meminfo->block, (size_t)meminfo->block&~BLOCK_BIT);
|
||||||
DMEM_OSFREEMEM((void *)meminfo);
|
DMEM_OSFREEMEM((void *)meminfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -567,32 +574,36 @@ void *drealloc(char *ptr, size_t size)
|
||||||
|
|
||||||
block = meminfo->block;
|
block = meminfo->block;
|
||||||
|
|
||||||
if(!((size_t)meminfo->block&BLOCK_BIT) &&
|
/* Here we check if this is a FRAGMENT and if the new size is
|
||||||
(size + sizeof(struct MemInfo) <
|
still smaller than the fragsize for this block. */
|
||||||
(prevsize = block->top->fragsize) )) {
|
if(!((size_t)block&BLOCK_BIT) &&
|
||||||
/* This is a FRAGMENT and new size is possible to retain within the same
|
(size + sizeof(struct MemInfo) < block->top->fragsize )) {
|
||||||
FRAGMENT */
|
|
||||||
|
prevsize = block->top->fragsize;
|
||||||
|
/* This is a FRAGMENT and new size is possible to retain within the
|
||||||
|
same FRAGMENT */
|
||||||
if((prevsize > qinfo[0]) &&
|
if((prevsize > qinfo[0]) &&
|
||||||
/* this is not the smallest memory Q */
|
/* this is not the smallest memory Q */
|
||||||
(size < (block->top-1)->fragsize))
|
(size < (block->top-1)->fragsize))
|
||||||
/* this fits in a smaller Q */
|
/* This fits in a smaller fragment, so we will make a realloc
|
||||||
|
here */
|
||||||
;
|
;
|
||||||
else
|
else
|
||||||
mem = ptr; /* Just return the same pointer as we got in. */
|
mem = ptr; /* Just return the same pointer as we got in. */
|
||||||
}
|
}
|
||||||
if(!mem) {
|
if(!mem) {
|
||||||
/* This is a stand-alone BLOCK or a realloc that no longer fits within
|
|
||||||
the same FRAGMENT */
|
|
||||||
|
|
||||||
if((size_t)meminfo->block&BLOCK_BIT) {
|
if((size_t)meminfo->block&BLOCK_BIT) {
|
||||||
|
/* This is a stand-alone BLOCK */
|
||||||
prevsize = ((size_t)meminfo->block&~BLOCK_BIT) -
|
prevsize = ((size_t)meminfo->block&~BLOCK_BIT) -
|
||||||
sizeof(struct MemInfo);
|
sizeof(struct MemInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
prevsize -= sizeof(struct MemInfo);
|
/* a FRAGMENT realloc that no longer fits within the same FRAGMENT
|
||||||
|
* or one that fits in a smaller */
|
||||||
|
prevsize = block->top->fragsize;
|
||||||
|
|
||||||
/* No tricks involved here, just grab a new bite of memory, copy the data
|
/* No tricks involved here, just grab a new bite of memory, copy the
|
||||||
* from the old place and free the old memory again. */
|
* data from the old place and free the old memory again. */
|
||||||
mem = dmalloc(size);
|
mem = dmalloc(size);
|
||||||
if(mem) {
|
if(mem) {
|
||||||
memcpy(mem, ptr, MIN(size, prevsize) );
|
memcpy(mem, ptr, MIN(size, prevsize) );
|
||||||
|
@ -621,3 +632,9 @@ dcalloc (size_t nmemb, size_t size)
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------
|
||||||
|
* local variables:
|
||||||
|
* eval: (load-file "../rockbox-mode.el")
|
||||||
|
* end:
|
||||||
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue