1 #include "pmc_garbage.h"
4 void * pmc_alloc(unsigned int * numbytesallocated, unsigned int minimumbytes) {
5 unsigned int memcheck=minimumbytes>PMC_MINALLOC?minimumbytes:PMC_MINALLOC;
7 for(int i=0;i<NUMCORES4GC;i+=2) {
8 void *startptr=pmc_heapptr->regions[i].lastptr;
9 void *finishptr=pmc_heapptr->regions[i+1].lastptr;
11 if ((finishptr-startptr)>memcheck) {
12 struct pmc_region *region=&pmc_heapptr->regions[i];
13 tmc_spin_mutex_lock(®ion->lock);
14 startptr=region->lastptr;
16 //double check that we have the space
17 if ((finishptr-startptr)<memcheck)
19 unsigned int startindex=region->lowunit;
20 unsigned int endindex=pmc_heapptr->regions[i+1]->highunit;
21 void * newstartptr=startptr+memcheck;
23 //update unit end points
24 for(unsigned int index=startindex;index<endindex;index++) {
25 void *ptr=pmc_unitend(index);
26 if ((ptr>startptr)&&(ptr<newstartptr)) {
27 pmc_heapptr->units[index].endptr=newstartptr;
32 region->lastptr=newstartptr;
34 *numbytesallocated=(unsigned int)(newstartptr-startptr);
35 tmc_spin_mutex_unlock(®ion->lock);
38 tmc_spin_mutex_unlock(®ion->lock);