本文整理汇总了C++中prvInsertBlockIntoFreeList函数的典型用法代码示例。如果您正苦于以下问题:C++ prvInsertBlockIntoFreeList函数的具体用法?C++ prvInsertBlockIntoFreeList怎么用?C++ prvInsertBlockIntoFreeList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了prvInsertBlockIntoFreeList函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vPortFree
void vPortFree( void *pv )
{
uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;
if( pv != NULL )
{
/* The memory being freed will have an BlockLink_t structure immediately
before it. */
puc -= xHeapStructSize;
/* This casting is to keep the compiler from issuing warnings. */
pxLink = ( BlockLink_t * ) puc;
/* Check the block is actually allocated. */
configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 );
configASSERT( pxLink->pxNextFreeBlock == NULL );
if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 )
{
if( pxLink->pxNextFreeBlock == NULL )
{
/* The block is being returned to the heap - it is no longer
allocated. */
pxLink->xBlockSize &= ~xBlockAllocatedBit;
vTaskSuspendAll();
{
/* Add this block to the list of free blocks. */
xFreeBytesRemaining += pxLink->xBlockSize;
traceFREE( pv, pxLink->xBlockSize );
prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );
}
( void ) xTaskResumeAll();
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
}
示例2: vPortFree
void vPortFree( void *pv )
{
uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;
RAM_TYPE ramType;
if( pv != NULL )
{
/* The memory being freed will have an BlockLink_t structure immediately
before it. */
puc -= xHeapStructSize;
/* This casting is to keep the compiler from issuing warnings. */
pxLink = ( void * ) puc;
/* Check the block is actually allocated. */
configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 );
configASSERT( pxLink->pxNextFreeBlock == NULL );
if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 )
{
if( pxLink->pxNextFreeBlock == NULL )
{
/* The block is being returned to the heap - it is no longer
allocated. */
ramType = ( RAM_TYPE )( pxLink->xBlockSize >> RAM_TYPE_BITS_OFFSET );
pxLink->xBlockSize &= ~BLOCK_ALLOCATED_BITS_MASK;
vTaskSuspendAll();
{
/* Add this block to the list of free blocks. */
xFreeBytesRemaining[ramType] += pxLink->xBlockSize;
traceFREE( pv, pxLink->xBlockSize );
prvInsertBlockIntoFreeList( ramType, ( ( BlockLink_t * ) pxLink ) );
}
( void ) xTaskResumeAll();
#ifdef CONFIG_DLPS_EN
/* Release the heapSTRUCT from partital-on memory */
if(ramType == RAM_TYPE_DATA_OFF || ramType == RAM_TYPE_BUFFER_OFF)
{
DLPS_BUFFER_UNREG(puc);
}
#endif
}
else
{
示例3: vPortFree
/*-----------------------------------------------------------*/
void vPortFree( void *pv )
{
pre_free_hook(pv);
unsigned char *puc = ( unsigned char * ) pv;
xBlockLink *pxLink;
ASSERT( ( pv >= (void*)WMSDK_HEAP_START_ADDR ) ||
( pv == NULL ) );
ASSERT( ( pv <= (void*)lastHeapAddress ) ||
( pv == NULL ) );
if( pv )
{
/* The memory being freed will have an xBlockLink structure immediately
before it. */
puc -= heapSTRUCT_SIZE;
/* This casting is to keep the compiler from issuing warnings. */
pxLink = ( void * ) puc;
ATRACE("MDC F %10x %6d %10d R: %x\r\n",
puc + heapSTRUCT_SIZE, BLOCK_SIZE( pxLink ),
xFreeBytesRemaining + BLOCK_SIZE(pxLink),
__builtin_return_address(0));
post_free_hook(((unsigned)puc + heapSTRUCT_SIZE),
GET_ACTUAL_SIZE( pxLink ));
randomizeAreaData((unsigned char*)((unsigned)puc + heapSTRUCT_SIZE),
BLOCK_SIZE( pxLink ) - heapSTRUCT_SIZE);
vTaskSuspendAll();
{
/* Add this block to the list of free blocks. */
SET_FREE( pxLink );
xFreeBytesRemaining += BLOCK_SIZE(pxLink);
prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) );
#ifdef FREERTOS_ENABLE_MALLOC_STATS
hI.totalAllocations--;
#endif // FREERTOS_ENABLE_MALLOC_STATS
}
xTaskResumeAll();
}
}
示例4: vPortFree
void vPortFree( void *pv )
{
unsigned char *puc = ( unsigned char * ) pv;
xBlockLink *pxLink;
// printf("%s\n", __func__);
if( pv != NULL )
{
/* The memory being freed will have an xBlockLink structure immediately
before it. */
puc -= heapSTRUCT_SIZE;
/* This casting is to keep the compiler from issuing warnings. */
pxLink = ( void * ) puc;
/* Check the block is actually allocated. */
configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 );
configASSERT( pxLink->pxNextFreeBlock == NULL );
if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 )
{
if( pxLink->pxNextFreeBlock == NULL )
{
/* The block is being returned to the heap - it is no longer
allocated. */
pxLink->xBlockSize &= ~xBlockAllocatedBit;
// vTaskSuspendAll();
ETS_INTR_LOCK();
{
/* Add this block to the list of free blocks. */
xFreeBytesRemaining += pxLink->xBlockSize;
prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) );
}
// xTaskResumeAll();
ETS_INTR_UNLOCK();
}
}
}
// printf("%s %x %d\n", __func__, pv, xFreeBytesRemaining);
}
示例5: vPortFree
void vPortFree( void *pv )
{
unsigned portCHAR *puc = ( unsigned portCHAR * ) pv;
xBlockLink *pxLink;
if( pv )
{
/* The memory being freed will have an xBlockLink structure immediately
before it. */
puc -= heapSTRUCT_SIZE;
/* This casting is to keep the compiler from issuing warnings. */
pxLink = ( void * ) puc;
vTaskSuspendAll();
{
/* Add this block to the list of free blocks. */
prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) );
}
xTaskResumeAll();
}
}
示例6: vPortFree
void vPortFree( void *pv )
{
unsigned char *puc = ( unsigned char * ) pv;
xBlockLink *pxLink;
if( pv != NULL )
{
/* The memory being freed will have an xBlockLink structure immediately
before it. */
puc -= heapSTRUCT_SIZE;
/* This casting is to keep the compiler from issuing warnings. */
pxLink = ( void * ) puc;
taskENTER_CRITICAL( &xMemLock );
{
/* Add this block to the list of free blocks. */
xFreeBytesRemaining += pxLink->xBlockSize;
prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) );
}
taskEXIT_CRITICAL( &xMemLock );
}
}
示例7: mem_4_free
void mem_4_free(void *pv)
{
unsigned char *puc = ( unsigned char * ) pv;
xBlockLink *pxLink;
if( pv != NULL )
{
/* The memory being freed will have an xBlockLink structure immediately
before it. */
puc -= heapSTRUCT_SIZE;
/* This casting is to keep the compiler from issuing warnings. */
pxLink = ( void * ) puc;
/* Check the block is actually allocated. */
RAW_ASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 );
RAW_ASSERT( pxLink->pxNextFreeBlock == NULL );
if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 )
{
if( pxLink->pxNextFreeBlock == NULL )
{
/* The block is being returned to the heap - it is no longer
allocated. */
pxLink->xBlockSize &= ~xBlockAllocatedBit;
raw_disable_sche();
{
/* Add this block to the list of free blocks. */
xFreeBytesRemaining += pxLink->xBlockSize;
prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) );
}
raw_enable_sche();
}
}
}
}
示例8: vPortFree
void vPortFree( void *pv )
{
uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;
if( pv != NULL ) {
/* The memory being freed will have an BlockLink_t structure immediately
before it. */
puc -= heapSTRUCT_SIZE;
/* This unexpected casting is to keep some compilers from issuing
byte alignment warnings. */
pxLink = ( void * ) puc;
vTaskSuspendAll();
{
/* Add this block to the list of free blocks. */
prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );
xFreeBytesRemaining += pxLink->xBlockSize;
traceFREE( pv, pxLink->xBlockSize );
}
( void ) xTaskResumeAll();
}
}
示例9: pvPortReAlloc
/*-----------------------------------------------------------*/
void* pvPortReAlloc( void *pv, size_t xWantedSize )
{
ASSERT( ( pv >= (void*)WMSDK_HEAP_START_ADDR ) ||
( pv == NULL ) );
ASSERT( ( pv <= (void*)lastHeapAddress ) ||
( pv == NULL ) );
pre_free_hook(pv);
unsigned char *puc = ( unsigned char * ) pv;
#ifdef ALLOC_TRACE
unsigned char *old_ptr= puc;
#endif /* ALLOC_TRACE */
xBlockLink *pxLink;
if( pv )
{
if( !xWantedSize )
{
vPortFree( pv );
return NULL;
}
void *newArea = pvPortMalloc( xWantedSize );
if( newArea )
{
/* The memory being freed will have an xBlockLink structure immediately
before it. */
puc -= heapSTRUCT_SIZE;
/* This casting is to keep the compiler from issuing warnings. */
pxLink = ( void * ) puc;
ATRACE("MDC F %10x %10d %10d\r\n",
puc + heapSTRUCT_SIZE, BLOCK_SIZE( pxLink ),
xFreeBytesRemaining + BLOCK_SIZE(pxLink));
post_free_hook( ( ( unsigned )puc + heapSTRUCT_SIZE ),
GET_ACTUAL_SIZE( pxLink ) );
int oldSize = BLOCK_SIZE( pxLink ) - heapSTRUCT_SIZE;
int copySize = ( oldSize < xWantedSize ) ?
oldSize : xWantedSize;
memcpy( newArea, pv, copySize );
randomizeAreaData((unsigned char*)
((unsigned)pxLink + heapSTRUCT_SIZE),
BLOCK_SIZE( pxLink ) - heapSTRUCT_SIZE);
vTaskSuspendAll();
{
/* Add this block to the list of free blocks. */
SET_FREE( pxLink );
xFreeBytesRemaining += BLOCK_SIZE(pxLink);
prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) );
#ifdef FREERTOS_ENABLE_MALLOC_STATS
hI.totalAllocations--;
#endif // FREERTOS_ENABLE_MALLOC_STATS
}
xTaskResumeAll();
return newArea;
}
}
else if( xWantedSize )
return pvPortMalloc( xWantedSize );
else
return NULL;
return NULL;
}
示例10: pre_alloc_hook
void *pvPortMalloc( size_t xWantedSize )
{
xBlockLink *pxBlock = NULL, *pxPreviousBlock, *pxNewBlockLink;
void *pvReturn = NULL;
if(!xWantedSize)
return NULL;
pre_alloc_hook( xWantedSize );
vTaskSuspendAll();
{
/* If this is the first call to malloc then the heap will require
initialisation to setup the list of free blocks. */
if( xHeapHasBeenInitialised == pdFALSE )
{
prvHeapInit();
xHeapHasBeenInitialised = pdTRUE;
}
/* The wanted size is increased so it can contain a xBlockLink
structure in addition to the requested amount of bytes. */
if( xWantedSize > 0 )
{
xWantedSize += heapSTRUCT_SIZE;
/* Ensure that blocks are always aligned to the required number of bytes. */
if( xWantedSize & portBYTE_ALIGNMENT_MASK )
{
/* Byte alignment required. */
xWantedSize += ( portBYTE_ALIGNMENT -
( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
}
}
if( ( xWantedSize > 0 ) && ( xWantedSize < configTOTAL_HEAP_SIZE ) )
{
/* Blocks are stored in byte order - traverse the list from the start
(smallest) block until one of adequate size is found. */
pxPreviousBlock = &xStart;
pxBlock = xStart.pxNextFreeBlock;
while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock ) )
{
pxPreviousBlock = pxBlock;
pxBlock = pxBlock->pxNextFreeBlock;
}
/* If we found the end marker then a block of adequate size was not found. */
if( pxBlock != &xEnd )
{
/* Return the memory space - jumping over the xBlockLink structure
at its start. */
pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock )
+ heapSTRUCT_SIZE );
#ifdef FREERTOS_ENABLE_MALLOC_STATS
hI.totalAllocations++;
#endif // FREERTOS_ENABLE_MALLOC_STATS
/* This block is being returned for use so must be taken off the
list of free blocks. */
pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;
pxBlock->pxNextFreeBlock = NULL;
/* If the block is larger than required it can be split into two. */
if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )
{
/* This block is to be split into two. Create a new block
following the number of bytes requested. The void cast is
used to prevent byte alignment warnings from the compiler. */
pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize );
/* Calculate the sizes of two blocks split from the single
block. */
pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
/* Assume bit 0 is 0 i.e. BLOCK_ALLOCATED flag is clear */
pxBlock->xBlockSize = xWantedSize;
/* Add the new block to the serial list */
pxNewBlockLink->pxPrev = pxBlock;
if( ! IS_LAST_BLOCK(pxNewBlockLink) )
NEXT_BLOCK( pxNewBlockLink )->pxPrev =
pxNewBlockLink;
SET_ALLOCATED(pxBlock);
/* insert the new block into the list of free blocks. */
prvInsertBlockIntoFreeList( pxNewBlockLink );
}
else {
SET_ALLOCATED(pxBlock);
}
xFreeBytesRemaining -= BLOCK_SIZE(pxBlock);
}
}
}
xTaskResumeAll();
#if( configUSE_MALLOC_FAILED_HOOK == 1 )
//.........这里部分代码省略.........
示例11: vPortDefineHeapRegions
//.........这里部分代码省略.........
{
pxPreviousBlock = pxBlock;
pxBlock = pxBlock->pxNextFreeBlock;
}
/* If the end marker was reached then a block of adequate size
was not found. */
if( pxBlock != pxEnd )
{
/* Return the memory space pointed to - jumping over the
BlockLink_t structure at its start. */
pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + uxHeapStructSize );
/* This block is being returned for use so must be taken out
of the list of free blocks. */
pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;
/* If the block is larger than required it can be split into
two. */
if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )
{
/* This block is to be split into two. Create a new
block following the number of bytes requested. The void
cast is used to prevent byte alignment warnings from the
compiler. */
pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );
/* Calculate the sizes of two blocks split from the
single block. */
pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
pxBlock->xBlockSize = xWantedSize;
/* Insert the new block into the list of free blocks. */
prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );
}
else
{
mtCOVERAGE_TEST_MARKER();
}
xFreeBytesRemaining -= pxBlock->xBlockSize;
if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining )
{
xMinimumEverFreeBytesRemaining = xFreeBytesRemaining;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
/* The block is being returned - it is allocated and owned
by the application and has no "next" block. */
pxBlock->xBlockSize |= xBlockAllocatedBit;
pxBlock->pxNextFreeBlock = NULL;
#ifdef MEMLEAK_DEBUG
if(uxHeapStructSize >= sizeof( BlockLink_t )){
pxBlock->file = file;
pxBlock->line = line;
}
//link the use block
prvInsertBlockIntoUsedList(pxBlock);
#endif
}
else
示例12: raw_disable_sche
void *mem_4_malloc(size_t xWantedSize)
{
xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink;
void *pvReturn = NULL;
raw_disable_sche();
{
/* If this is the first call to malloc then the heap will require
initialisation to setup the list of free blocks. */
if( pxEnd == NULL )
{
prvHeapInit();
}
/* Check the requested block size is not so large that the top bit is
set. The top bit of the block size member of the xBlockLink structure
is used to determine who owns the block - the application or the
kernel, so it must be free. */
if( ( xWantedSize & xBlockAllocatedBit ) == 0 )
{
/* The wanted size is increased so it can contain a xBlockLink
structure in addition to the requested amount of bytes. */
if( xWantedSize > 0 )
{
xWantedSize += heapSTRUCT_SIZE;
/* Ensure that blocks are always aligned to the required number
of bytes. */
if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 )
{
/* Byte alignment required. */
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
}
}
if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )
{
/* Traverse the list from the start (lowest address) block until
one of adequate size is found. */
pxPreviousBlock = &xStart;
pxBlock = xStart.pxNextFreeBlock;
while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )
{
pxPreviousBlock = pxBlock;
pxBlock = pxBlock->pxNextFreeBlock;
}
/* If the end marker was reached then a block of adequate size
was not found. */
if( pxBlock != pxEnd )
{
/* Return the memory space pointed to - jumping over the
xBlockLink structure at its start. */
pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE );
/* This block is being returned for use so must be taken out
of the list of free blocks. */
pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;
/* If the block is larger than required it can be split into
two. */
if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )
{
/* This block is to be split into two. Create a new
block following the number of bytes requested. The void
cast is used to prevent byte alignment warnings from the
compiler. */
pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize );
/* Calculate the sizes of two blocks split from the
single block. */
pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
pxBlock->xBlockSize = xWantedSize;
/* Insert the new block into the list of free blocks. */
prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );
}
xFreeBytesRemaining -= pxBlock->xBlockSize;
/* The block is being returned - it is allocated and owned
by the application and has no "next" block. */
pxBlock->xBlockSize |= xBlockAllocatedBit;
pxBlock->pxNextFreeBlock = NULL;
}
}
}
}
raw_enable_sche();
return pvReturn;
}
示例13: sector_Malloc
//.........这里部分代码省略.........
if(xWantedSize > sl->sector[index].FreeBytesRemaining)
{
err=ERR_NO_FREE_SPACE;
goto exit;
}
/* Traverse the list from the start (lowest address) block until
one of adequate size is found. */
//чтение сектора xStart
xStart->pxCurrentAddr=sl->sector[index].xStart_Addr;
err=ReadBlockLink(index, xStart);
if(err!=ERR_OK)
goto exit;
pxPreviousBlock = xStart;
pxBlock->pxCurrentAddr=xStart->body.pxNextFreeBlock;
err=ReadBlockLink(index,pxBlock);
if(err!=ERR_OK)
goto exit;
while( (pxBlock->body.xBlockSize < xWantedSize) && (pxBlock->body.pxNextFreeBlock !=0) )
{
pxPreviousBlock=pxBlock; //скопировать а не ссылка!
pxBlock->pxCurrentAddr=pxBlock->body.pxNextFreeBlock;
err=ReadBlockLink(index,pxBlock);
if(err!=ERR_OK)
goto exit;
}
/* If the end marker was reached then a block of adequate size
was not found. */
if(pxBlock->pxCurrentAddr != sl->sector[index].pxEnd_Addr)
{
/* Return the memory space pointed to - jumping over the
BlockLink_t structure at its start. */
*addr=pxPreviousBlock->body.pxNextFreeBlock + sl->sector[index].bl_size;
/* This block is being returned for use so must be taken out
of the list of free blocks. */
if(pxPreviousBlock->pxCurrentAddr != pxBlock->pxCurrentAddr)
{
pxPreviousBlock->body.pxNextFreeBlock=pxBlock->body.pxNextFreeBlock;
err=WriteBlockLink(index,pxPreviousBlock);
if(err!=ERR_OK)
goto exit;
}
/* If the block is larger than required it can be split into
two. */
if( (pxBlock->body.xBlockSize - xWantedSize) > (UINT32_T)(sl->sector[index].bl_size<<1) )
{
/* This block is to be split into two. Create a new
block following the number of bytes requested. The void
cast is used to prevent byte alignment warnings from the
compiler. */
pxNewBlockLink->pxCurrentAddr = pxBlock->pxCurrentAddr + xWantedSize;
/* Calculate the sizes of two blocks split from the
single block. */
pxNewBlockLink->body.xBlockSize=pxBlock->body.xBlockSize - xWantedSize;
pxNewBlockLink->body.pxNextFreeBlock=0;
pxBlock->body.xBlockSize=xWantedSize;
/* Insert the new block into the list of free blocks. */
err=prvInsertBlockIntoFreeList(index , pxNewBlockLink);
if(err!=ERR_OK)
goto exit;
#if (configUSE_SegmentCounter==TRUE)
sl->sector[index].xSegmentCounter++;
#endif
}
sl->sector[index].FreeBytesRemaining -= pxBlock->body.xBlockSize;
/* The block is being returned - it is allocated and owned
by the application and has no "next" block. */
pxBlock->body.xBlockSize |= (UINT32_T)(0x01 << ((8*sl->sector[index].SectorSizeLen)-1));
pxBlock->body.pxNextFreeBlock = 0;
err=WriteBlockLink(index,pxBlock);
//if(err!=ERR_OK)
// goto exit;
}
exit:
local_free((void*)pxBlock);
local_free((void*)pxNewBlockLink);
return err;
}
示例14: ETS_INTR_LOCK
void *pvPortMalloc( size_t xWantedSize )
{
xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink;
void *pvReturn = NULL;
// printf("%s %d %d\n", __func__, xWantedSize, xFreeBytesRemaining);
// vTaskSuspendAll();
ETS_INTR_LOCK();
{
/* If this is the first call to malloc then the heap will require
initialisation to setup the list of free blocks. */
if( pxEnd == NULL )
{
prvHeapInit();
}
/* Check the requested block size is not so large that the top bit is
set. The top bit of the block size member of the xBlockLink structure
is used to determine who owns the block - the application or the
kernel, so it must be free. */
if( ( xWantedSize & xBlockAllocatedBit ) == 0 )
{
/* The wanted size is increased so it can contain a xBlockLink
structure in addition to the requested amount of bytes. */
if( xWantedSize > 0 )
{
xWantedSize = xPortWantedSizeAlign(xWantedSize);
}
if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )
{
/* Traverse the list from the start (lowest address) block until
one of adequate size is found. */
pxPreviousBlock = &xStart;
pxBlock = xStart.pxNextFreeBlock;
while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )
{
pxPreviousBlock = pxBlock;
pxBlock = pxBlock->pxNextFreeBlock;
}
/* If the end marker was reached then a block of adequate size
was not found. */
if( pxBlock != pxEnd )
{
/* Return the memory space pointed to - jumping over the
xBlockLink structure at its start. */
pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE );
/* This block is being returned for use so must be taken out
of the list of free blocks. */
pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;
/* If the block is larger than required it can be split into
two. */
if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )
{
/* This block is to be split into two. Create a new
block following the number of bytes requested. The void
cast is used to prevent byte alignment warnings from the
compiler. */
pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize );
/* Calculate the sizes of two blocks split from the
single block. */
pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
pxBlock->xBlockSize = xWantedSize;
/* Insert the new block into the list of free blocks. */
prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );
}
xFreeBytesRemaining -= pxBlock->xBlockSize;
/* The block is being returned - it is allocated and owned
by the application and has no "next" block. */
pxBlock->xBlockSize |= xBlockAllocatedBit;
pxBlock->pxNextFreeBlock = NULL;
}
}
}
}
// xTaskResumeAll();
ETS_INTR_UNLOCK();
#if( configUSE_MALLOC_FAILED_HOOK == 1 )
{
if( pvReturn == NULL )
{
extern void vApplicationMallocFailedHook( void );
vApplicationMallocFailedHook();
}
}
#endif
// printf("%s %x %x\n", __func__, pvReturn, pxBlock);
return pvReturn;
}
示例15: vTaskSuspendAll
void *pvPortMalloc( size_t xWantedSize )
{
BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink;
void *pvReturn = NULL;
vTaskSuspendAll();
{
/* If this is the first call to malloc then the heap will require
initialisation to setup the list of free blocks. */
if( pxEnd == NULL )
{
prvHeapInit();
}
else
{
mtCOVERAGE_TEST_MARKER();
}
/* Check the requested block size is not so large that the top bit is
set. The top bit of the block size member of the BlockLink_t structure
is used to determine who owns the block - the application or the
kernel, so it must be free. */
if( ( xWantedSize & xBlockAllocatedBit ) == 0 )
{
/* The wanted size is increased so it can contain a BlockLink_t
structure in addition to the requested amount of bytes. */
if( xWantedSize > 0 )
{
xWantedSize += xHeapStructSize;
/* Ensure that blocks are always aligned to the required number
of bytes. */
if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 )
{
/* Byte alignment required. */
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 );
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
else
{
mtCOVERAGE_TEST_MARKER();
}
if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )
{
/* Traverse the list from the start (lowest address) block until
one of adequate size is found. */
pxPreviousBlock = &xStart;
pxBlock = xStart.pxNextFreeBlock;
while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )
{
pxPreviousBlock = pxBlock;
pxBlock = pxBlock->pxNextFreeBlock;
}
/* If the end marker was reached then a block of adequate size
was not found. */
if( pxBlock != pxEnd )
{
/* Return the memory space pointed to - jumping over the
BlockLink_t structure at its start. */
pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize );
/* This block is being returned for use so must be taken out
of the list of free blocks. */
pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;
/* If the block is larger than required it can be split into
two. */
if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )
{
/* This block is to be split into two. Create a new
block following the number of bytes requested. The void
cast is used to prevent byte alignment warnings from the
compiler. */
pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );
configASSERT( ( ( ( size_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 );
/* Calculate the sizes of two blocks split from the
single block. */
pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
pxBlock->xBlockSize = xWantedSize;
/* Insert the new block into the list of free blocks. */
prvInsertBlockIntoFreeList( pxNewBlockLink );
}
else
{
mtCOVERAGE_TEST_MARKER();
}
xFreeBytesRemaining -= pxBlock->xBlockSize;
if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining )
{
//.........这里部分代码省略.........