void DoubleListDestroy(DoubleList *p_list) { DoubleListMakeEmpty(p_list); #if ENABLE_DSAA_OPTIMIZATION MemoryPoolFree(&p_list->pool, p_list->head); MemoryPoolFree(&p_list->pool, p_list->tail); MemoryPoolDestroy(&p_list->pool); #else free(p_list->head); free(p_list->tail); #endif p_list->head = NULL; p_list->tail = NULL; p_list->unit_size = 0; }
void DoubleListRemove(DoubleList *p_list, DoubleListNode *p_node) { p_node->prev->next = p_node->next; p_node->next->prev = p_node->prev; #if ENABLE_DSAA_OPTIMIZATION MemoryPoolFree(&p_list->pool, p_node); #else free(p_node); #endif }
/** * Generic function to stress a memory pool. */ void StressPool(MemoryPool_t p, int NumPoolItems, int dataSize, int PatternStart) { unsigned char **addr; int localStart; int i, j; /* Create an array to hold the addresses we will alloc. */ addr = (unsigned char **)malloc(sizeof(unsigned char *) * (NumPoolItems + 1)); /* Set up the unique pattern(s) we are going to fill in. */ localStart = PatternStart; /* Try to allocate the whole pool. */ for (i = 0; i < NumPoolItems + 1; i++) { addr[i] = (unsigned char*)MemoryPoolAllocate(p); /* If you got an item, fill it with a known pattern, */ /* and create the next pattern. */ if (addr[i]) { memset(addr[i], localStart, dataSize); localStart++; } } /* Wait a bit just to allow multithreading to randomize things. */ /* We want the threads competing for the pools. */ vTaskDelay(PatternStart); /* Now check and free. */ for (i = 0; i < NumPoolItems + 1; i++) { if (addr[i]) { /* If we allocated an item from the pool, verify all */ /* bytes are what we think they should be. */ for (j = 0; j < dataSize; j++) { configASSERT(addr[i][j] == PatternStart); } /* We are working with bytes so make sure we wrap. */ if (++PatternStart >= 256) { PatternStart = 0; } /* Poison the memory before freeing it. */ memset(addr[i], 0xEE, dataSize); MemoryPoolFree(p, addr[i]); addr[i] = NULL; } } free(addr); }