]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c
Update TCP/IP tack to latest form Git.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / BufferManagement / BufferAllocation_2.c
index 5647ac695552bfe0bcb5f301153071da64cfb14b..e008da07a5fc7790073f7d0c245ea4c2e6a048f1 100644 (file)
@@ -210,81 +210,84 @@ NetworkBufferDescriptor_t *pxGetNetworkBufferWithDescriptor( size_t xRequestedSi
 NetworkBufferDescriptor_t *pxReturn = NULL;\r
 size_t uxCount;\r
 \r
-       if( ( xRequestedSizeBytes != 0u ) && ( xRequestedSizeBytes < ( size_t ) baMINIMAL_BUFFER_SIZE ) )\r
+       if( xNetworkBufferSemaphore != NULL )\r
        {\r
-               /* ARP packets can replace application packets, so the storage must be\r
-               at least large enough to hold an ARP. */\r
-               xRequestedSizeBytes = baMINIMAL_BUFFER_SIZE;\r
-       }\r
-\r
-       /* Add 2 bytes to xRequestedSizeBytes and round up xRequestedSizeBytes\r
-       to the nearest multiple of N bytes, where N equals 'sizeof( size_t )'. */\r
-       xRequestedSizeBytes += 2u;\r
-       if( ( xRequestedSizeBytes & ( sizeof( size_t ) - 1u ) ) != 0u )\r
-       {\r
-               xRequestedSizeBytes = ( xRequestedSizeBytes | ( sizeof( size_t ) - 1u ) ) + 1u;\r
-       }\r
-\r
-       /* If there is a semaphore available, there is a network buffer available. */\r
-       if( xSemaphoreTake( xNetworkBufferSemaphore, xBlockTimeTicks ) == pdPASS )\r
-       {\r
-               /* Protect the structure as it is accessed from tasks and interrupts. */\r
-               taskENTER_CRITICAL();\r
+               if( ( xRequestedSizeBytes != 0u ) && ( xRequestedSizeBytes < ( size_t ) baMINIMAL_BUFFER_SIZE ) )\r
                {\r
-                       pxReturn = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &xFreeBuffersList );\r
-                       uxListRemove( &( pxReturn->xBufferListItem ) );\r
+                       /* ARP packets can replace application packets, so the storage must be\r
+                       at least large enough to hold an ARP. */\r
+                       xRequestedSizeBytes = baMINIMAL_BUFFER_SIZE;\r
                }\r
-               taskEXIT_CRITICAL();\r
-\r
-               /* Reading UBaseType_t, no critical section needed. */\r
-               uxCount = listCURRENT_LIST_LENGTH( &xFreeBuffersList );\r
 \r
-               if( uxMinimumFreeNetworkBuffers > uxCount )\r
+               /* Add 2 bytes to xRequestedSizeBytes and round up xRequestedSizeBytes\r
+               to the nearest multiple of N bytes, where N equals 'sizeof( size_t )'. */\r
+               xRequestedSizeBytes += 2u;\r
+               if( ( xRequestedSizeBytes & ( sizeof( size_t ) - 1u ) ) != 0u )\r
                {\r
-                       uxMinimumFreeNetworkBuffers = uxCount;\r
+                       xRequestedSizeBytes = ( xRequestedSizeBytes | ( sizeof( size_t ) - 1u ) ) + 1u;\r
                }\r
 \r
-               /* Allocate storage of exactly the requested size to the buffer. */\r
-               configASSERT( pxReturn->pucEthernetBuffer == NULL );\r
-               if( xRequestedSizeBytes > 0 )\r
+               /* If there is a semaphore available, there is a network buffer available. */\r
+               if( xSemaphoreTake( xNetworkBufferSemaphore, xBlockTimeTicks ) == pdPASS )\r
                {\r
-                       /* Extra space is obtained so a pointer to the network buffer can\r
-                       be stored at the beginning of the buffer. */\r
-                       pxReturn->pucEthernetBuffer = ( uint8_t * ) pvPortMalloc( xRequestedSizeBytes + ipBUFFER_PADDING );\r
+                       /* Protect the structure as it is accessed from tasks and interrupts. */\r
+                       taskENTER_CRITICAL();\r
+                       {\r
+                               pxReturn = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &xFreeBuffersList );\r
+                               uxListRemove( &( pxReturn->xBufferListItem ) );\r
+                       }\r
+                       taskEXIT_CRITICAL();\r
+\r
+                       /* Reading UBaseType_t, no critical section needed. */\r
+                       uxCount = listCURRENT_LIST_LENGTH( &xFreeBuffersList );\r
 \r
-                       if( pxReturn->pucEthernetBuffer == NULL )\r
+                       if( uxMinimumFreeNetworkBuffers > uxCount )\r
                        {\r
-                               /* The attempt to allocate storage for the buffer payload failed,\r
-                               so the network buffer structure cannot be used and must be\r
-                               released. */\r
-                               vReleaseNetworkBufferAndDescriptor( pxReturn );\r
-                               pxReturn = NULL;\r
+                               uxMinimumFreeNetworkBuffers = uxCount;\r
                        }\r
-                       else\r
+\r
+                       /* Allocate storage of exactly the requested size to the buffer. */\r
+                       configASSERT( pxReturn->pucEthernetBuffer == NULL );\r
+                       if( xRequestedSizeBytes > 0 )\r
                        {\r
-                               /* Store a pointer to the network buffer structure in the\r
-                               buffer storage area, then move the buffer pointer on past the\r
-                               stored pointer so the pointer value is not overwritten by the\r
-                               application when the buffer is used. */\r
-                               *( ( NetworkBufferDescriptor_t ** ) ( pxReturn->pucEthernetBuffer ) ) = pxReturn;\r
-                               pxReturn->pucEthernetBuffer += ipBUFFER_PADDING;\r
-\r
-                               /* Store the actual size of the allocated buffer, which may be\r
-                               greater than the original requested size. */\r
-                               pxReturn->xDataLength = xRequestedSizeBytes;\r
-\r
-                               #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )\r
+                               /* Extra space is obtained so a pointer to the network buffer can\r
+                               be stored at the beginning of the buffer. */\r
+                               pxReturn->pucEthernetBuffer = ( uint8_t * ) pvPortMalloc( xRequestedSizeBytes + ipBUFFER_PADDING );\r
+\r
+                               if( pxReturn->pucEthernetBuffer == NULL )\r
+                               {\r
+                                       /* The attempt to allocate storage for the buffer payload failed,\r
+                                       so the network buffer structure cannot be used and must be\r
+                                       released. */\r
+                                       vReleaseNetworkBufferAndDescriptor( pxReturn );\r
+                                       pxReturn = NULL;\r
+                               }\r
+                               else\r
                                {\r
-                                       /* make sure the buffer is not linked */\r
-                                       pxReturn->pxNextBuffer = NULL;\r
+                                       /* Store a pointer to the network buffer structure in the\r
+                                       buffer storage area, then move the buffer pointer on past the\r
+                                       stored pointer so the pointer value is not overwritten by the\r
+                                       application when the buffer is used. */\r
+                                       *( ( NetworkBufferDescriptor_t ** ) ( pxReturn->pucEthernetBuffer ) ) = pxReturn;\r
+                                       pxReturn->pucEthernetBuffer += ipBUFFER_PADDING;\r
+\r
+                                       /* Store the actual size of the allocated buffer, which may be\r
+                                       greater than the original requested size. */\r
+                                       pxReturn->xDataLength = xRequestedSizeBytes;\r
+\r
+                                       #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )\r
+                                       {\r
+                                               /* make sure the buffer is not linked */\r
+                                               pxReturn->pxNextBuffer = NULL;\r
+                                       }\r
+                                       #endif /* ipconfigUSE_LINKED_RX_MESSAGES */\r
                                }\r
-                               #endif /* ipconfigUSE_LINKED_RX_MESSAGES */\r
                        }\r
-               }\r
-               else\r
-               {\r
-                       /* A descriptor is being returned without an associated buffer being\r
-                       allocated. */\r
+                       else\r
+                       {\r
+                               /* A descriptor is being returned without an associated buffer being\r
+                               allocated. */\r
+                       }\r
                }\r
        }\r
 \r