]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/portable/MemMang/heap_4.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Source / portable / MemMang / heap_4.c
index 9ec5af5c294c19bbcc900ebabb1362c948b5fe7b..911d4f9a597e5a1a36a3eaee211f0d2a16ba637b 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
- * FreeRTOS Kernel V10.0.1\r
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ * FreeRTOS Kernel V10.3.0\r
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
  *\r
  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
  * this software and associated documentation files (the "Software"), to deal in\r
@@ -97,10 +97,12 @@ static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t ) ( p
 /* Create a couple of list links to mark the start and end of the list. */\r
 static BlockLink_t xStart, *pxEnd = NULL;\r
 \r
-/* Keeps track of the number of free bytes remaining, but says nothing about\r
-fragmentation. */\r
+/* Keeps track of the number of calls to allocate and free memory as well as the\r
+number of free bytes remaining, but says nothing about fragmentation. */\r
 static size_t xFreeBytesRemaining = 0U;\r
 static size_t xMinimumEverFreeBytesRemaining = 0U;\r
+static size_t xNumberOfSuccessfulAllocations = 0;\r
+static size_t xNumberOfSuccessfulFrees = 0;\r
 \r
 /* Gets set to the top bit of an size_t type.  When this bit in the xBlockSize\r
 member of an BlockLink_t structure is set then the block belongs to the\r
@@ -221,6 +223,7 @@ void *pvReturn = NULL;
                                        by the application and has no "next" block. */\r
                                        pxBlock->xBlockSize |= xBlockAllocatedBit;\r
                                        pxBlock->pxNextFreeBlock = NULL;\r
+                                       xNumberOfSuccessfulAllocations++;\r
                                }\r
                                else\r
                                {\r
@@ -292,6 +295,7 @@ BlockLink_t *pxLink;
                                        xFreeBytesRemaining += pxLink->xBlockSize;\r
                                        traceFREE( pv, pxLink->xBlockSize );\r
                                        prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );\r
+                                       xNumberOfSuccessfulFrees++;\r
                                }\r
                                ( void ) xTaskResumeAll();\r
                        }\r
@@ -433,4 +437,56 @@ uint8_t *puc;
                mtCOVERAGE_TEST_MARKER();\r
        }\r
 }\r
+/*-----------------------------------------------------------*/\r
+\r
+void vPortGetHeapStats( HeapStats_t *pxHeapStats )\r
+{\r
+BlockLink_t *pxBlock;\r
+size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */\r
+\r
+       vTaskSuspendAll();\r
+       {\r
+               pxBlock = xStart.pxNextFreeBlock;\r
+\r
+               /* pxBlock will be NULL if the heap has not been initialised.  The heap\r
+               is initialised automatically when the first allocation is made. */\r
+               if( pxBlock != NULL )\r
+               {\r
+                       do\r
+                       {\r
+                               /* Increment the number of blocks and record the largest block seen\r
+                               so far. */\r
+                               xBlocks++;\r
+\r
+                               if( pxBlock->xBlockSize > xMaxSize )\r
+                               {\r
+                                       xMaxSize = pxBlock->xBlockSize;\r
+                               }\r
+\r
+                               if( pxBlock->xBlockSize < xMinSize )\r
+                               {\r
+                                       xMinSize = pxBlock->xBlockSize;\r
+                               }\r
+\r
+                               /* Move to the next block in the chain until the last block is\r
+                               reached. */\r
+                               pxBlock = pxBlock->pxNextFreeBlock;\r
+                       } while( pxBlock != pxEnd );\r
+               }\r
+       }\r
+       xTaskResumeAll();\r
+\r
+       pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize;\r
+       pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize;\r
+       pxHeapStats->xNumberOfFreeBlocks = xBlocks;\r
+\r
+       taskENTER_CRITICAL();\r
+       {\r
+               pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining;\r
+               pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations;\r
+               pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees;\r
+               pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining;\r
+       }\r
+       taskEXIT_CRITICAL();\r
+}\r
 \r