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.
|
||||
*/
|
||||
|
||||
const static short qinfo[]= {
|
||||
static const unsigned short qinfo[]= {
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
int used;
|
||||
int num;
|
||||
int totalfree=0;
|
||||
|
@ -276,7 +276,7 @@ static void FragBlock(char *memp, int size)
|
|||
**************************************************************************/
|
||||
void dmalloc_initialize(void)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
/* Setup the nmax and fragsize fields of the top structs */
|
||||
for(i=0; i< sizeof(qinfo)/sizeof(qinfo[0]); i++) {
|
||||
top[i].fragsize = qinfo[i];
|
||||
|
@ -358,7 +358,7 @@ void *dmalloc(size_t size)
|
|||
struct MemTop *memtop=NULL; /* SAFE */
|
||||
|
||||
/* Determine which queue to use */
|
||||
int queue;
|
||||
unsigned int queue;
|
||||
for(queue=0; size > qinfo[queue]; queue++)
|
||||
;
|
||||
do {
|
||||
|
@ -383,7 +383,7 @@ void *dmalloc(size_t size)
|
|||
if(memtop->nfree) {
|
||||
/* 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 */
|
||||
while(!block->nfree)
|
||||
|
@ -397,17 +397,19 @@ void *dmalloc(size_t size)
|
|||
|
||||
}
|
||||
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),
|
||||
newblock,
|
||||
struct MemBlock *);
|
||||
if(!newblock) {
|
||||
if(++queue < sizeof(qinfo)/sizeof(qinfo[0])) {
|
||||
/* There are queues for bigger FRAGMENTS that we should check
|
||||
before we fail this for real */
|
||||
/* There are queues for bigger FRAGMENTS that we
|
||||
* should check before we fail this for real */
|
||||
#ifdef DEBUG_VERBOSE
|
||||
printf("*** " __FILE__ " Trying a bigger Q: %d\n", queue);
|
||||
printf("*** " __FILE__ " Trying a bigger Q: %d\n",
|
||||
queue);
|
||||
#endif
|
||||
mem = NULL;
|
||||
}
|
||||
|
@ -418,13 +420,16 @@ void *dmalloc(size_t size)
|
|||
}
|
||||
else {
|
||||
/* 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 */
|
||||
newblock->next = block; /* point to the previous first BLOCK */
|
||||
memtop->chain = newblock; /* attach this BLOCK to the
|
||||
chain */
|
||||
newblock->next = block; /* point to the previous first
|
||||
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->top = memtop; /* our head master */
|
||||
|
||||
|
@ -531,7 +536,9 @@ void dfree(void *memp)
|
|||
}
|
||||
else {
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
@ -567,32 +574,36 @@ void *drealloc(char *ptr, size_t size)
|
|||
|
||||
block = meminfo->block;
|
||||
|
||||
if(!((size_t)meminfo->block&BLOCK_BIT) &&
|
||||
(size + sizeof(struct MemInfo) <
|
||||
(prevsize = block->top->fragsize) )) {
|
||||
/* This is a FRAGMENT and new size is possible to retain within the same
|
||||
FRAGMENT */
|
||||
/* Here we check if this is a FRAGMENT and if the new size is
|
||||
still smaller than the fragsize for this block. */
|
||||
if(!((size_t)block&BLOCK_BIT) &&
|
||||
(size + sizeof(struct MemInfo) < block->top->fragsize )) {
|
||||
|
||||
prevsize = block->top->fragsize;
|
||||
/* This is a FRAGMENT and new size is possible to retain within the
|
||||
same FRAGMENT */
|
||||
if((prevsize > qinfo[0]) &&
|
||||
/* this is not the smallest memory Q */
|
||||
(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
|
||||
mem = ptr; /* Just return the same pointer as we got in. */
|
||||
}
|
||||
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) {
|
||||
/* This is a stand-alone BLOCK */
|
||||
prevsize = ((size_t)meminfo->block&~BLOCK_BIT) -
|
||||
sizeof(struct MemInfo);
|
||||
}
|
||||
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
|
||||
* from the old place and free the old memory again. */
|
||||
/* No tricks involved here, just grab a new bite of memory, copy the
|
||||
* data from the old place and free the old memory again. */
|
||||
mem = dmalloc(size);
|
||||
if(mem) {
|
||||
memcpy(mem, ptr, MIN(size, prevsize) );
|
||||
|
@ -621,3 +632,9 @@ dcalloc (size_t nmemb, size_t size)
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------
|
||||
* local variables:
|
||||
* eval: (load-file "../rockbox-mode.el")
|
||||
* end:
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue