static ClRcT clMemPartExpand(ClMemPartT *pMemPart, ClUint32T size) { STATUS rc = 0; if(pMemPart->index >= CL_MEM_PART_EXPANSION_SLOTS) { CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Mem part out of expansion slots trying to expand for size [%d]\n", size)); return CL_ERR_NO_SPACE; } if(pMemPart->partitions[pMemPart->index]) { CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Mem part already expanded\n")); return CL_ERR_UNSPECIFIED; } pMemPart->partitions[pMemPart->index] = malloc(size); if(!pMemPart->partitions[pMemPart->index]) { CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Mem part expand calloc failure for size [%d]\n", size)); return CL_ERR_NO_MEMORY; } if( (rc = memPartAddToPool(pMemPart->partId, pMemPart->partitions[pMemPart->index], size) ) == ERROR ) { free(pMemPart->partitions[pMemPart->index]); pMemPart->partitions[pMemPart->index] = NULL; CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Mem part add to pool for size [%d] failed with [%s]\n", size, strerror(errno))); return CL_ERR_NO_MEMORY; } ++pMemPart->index; return CL_OK; }
void memAddToPool ( FAST char *pPool, /* pointer to memory block */ FAST unsigned poolSize /* block size in bytes */ ) { (void) memPartAddToPool (&memSysPartition, pPool, poolSize); }
void memPartInit(PART_ID partId, char* pPool, unsigned poolSize) { memset((void*)partId, 0, sizeof(*partId)); partId->options = memPartDefaultOption; partId->minBlockWords = sizeof (FREE_BLOCK) >> 1; /* word not byte */ (* memPartSemInitRtn) (partId); dllInit(&partId->freeList); objCoreInit(&partId->objCore, memPartClassId); memPartAddToPool(partId, pPool, poolSize); }
void memPartInit ( FAST PART_ID partId, /* partition to initialize */ char *pPool, /* pointer to memory block */ unsigned poolSize /* block size in bytes */ ) { /* initialize partition descriptor */ bfill ((char *) partId, sizeof (*partId), 0); partId->options = memPartOptionsDefault; partId->minBlockWords = sizeof (FREE_BLOCK) >> 1; /* initialize partition semaphore with a virtual function so semaphore * type is selectable. By default memPartLibInit() will utilize binary * semaphores while memInit() will utilize mutual exclusion semaphores * with the options stored in _mutexOptionsMemLib. */ (* memPartSemInitRtn) (partId); dllInit (&partId->freeList); /* init. free list */ #ifdef WV_INSTRUMENTATION if (wvObjIsEnabled) { /* windview - connect object class event logging routine */ objCoreInit (&partId->objCore, memPartInstClassId); } else #endif objCoreInit (&partId->objCore, memPartClassId); /* initialize core */ (void) memPartAddToPool (partId, pPool, poolSize); }
void * ossPartMalloc ( UINT32 numBytes /* Size of buffer to allocate */ ) { void * pBfr; void * pMoreMemory; UINT32 growSize; /* Create the USB memory partition from cache safe memory */ if (ossPartInitFlag == TRUE) { /* on the first pass create 64k chunk of cache safe memory for usb */ pUsbMemSpace = (char *) cacheDmaMalloc (usbMemPartSize); if (pUsbMemSpace == NULL) { printf ("ossLib.c: unable to allocate USB memory space.\n"); return NULL; } /* make this chunk a partition */ usbMemPartId = memPartCreate (pUsbMemSpace, usbMemPartSize); if (usbMemPartId == NULL) { printf ("ossLib.c: unable to create USB memory partition.\n"); return NULL; } ossPartInitFlag = FALSE; } /* * If this call to ossMalloc is going to allocate more memory than is * available in the partition, then grow the partition by 8k, or if * numBytes is larger than 4k, then grow the partition by numBytes + 4k. */ if ((usbMemCount + numBytes) > (usbMemPartSize - 0x1000)) { growSize = 0x2000; if (numBytes > 0x1000) growSize += numBytes; pMoreMemory = cacheDmaMalloc (growSize); if (pMoreMemory == NULL) { printf ("ossLib.c: ossPartMalloc could not cacheDmaMalloc() new" \ " memory.\n"); return NULL; } if (memPartAddToPool (usbMemPartId, pMoreMemory, growSize) == ERROR) { printf ("ossLib.c: ossPartMalloc could not add new memory to" \ " pool.\n"); return NULL; } usbMemPartSize += growSize; } /* From now on, use this partition for all USB mallocs */ pBfr = memPartAlignedAlloc (usbMemPartId, ROUND_UP(numBytes, _CACHE_ALIGN_SIZE), _CACHE_ALIGN_SIZE); if (pBfr == NULL) { printf ("ossLib.c: unable to malloc USB memory.\n"); return NULL; } /* Update the amount of memory USB is currently using. */ usbMemCount += ROUND_UP(numBytes, _CACHE_ALIGN_SIZE); return pBfr; }
void memAddToPool(FAST char *pPool, FAST unsigned poolSize) { (void)memPartAddToPool(&memSysPartition, pPool, poolSize); }