void DeleteNode(LINKEDLIST *list, LISTNODE *node) { LISTNODE *del; if (!(list)) return; if (node == list->head) { list->head = node->next; _free_node(node); return; } del = list->head; while (del != NULL && del->next != node) del = del->next; if (!(del)) return; if(del->next == list->tail) list->tail = del; del->next = del->next->next; _free_node(node); }
gnrc_pktsnip_t* gnrc_priority_pktqueue_pop(gnrc_priority_pktqueue_t* queue) { if(!queue || (gnrc_priority_pktqueue_length(queue) == 0)){ return NULL; } priority_queue_node_t *head = priority_queue_remove_head(queue); gnrc_pktsnip_t* pkt = (gnrc_pktsnip_t*) head->data; _free_node((gnrc_priority_pktqueue_node_t *)head); return pkt; }
int _utspace_trickle_add_uts(allocman_t *alloc, void *_trickle, uint32_t num, cspacepath_t *uts, uint32_t *size_bits, uint32_t *paddr) { utspace_trickle_t *trickle = (utspace_trickle_t*) _trickle; struct utspace_trickle_node *nodes[num]; cspacepath_t *uts_copy[num]; int error; int i; for (i = 0; i < num; i++) { nodes[i] = _make_node(alloc, &error); if (error) { for (i--; i >= 0; i--) { _free_node(alloc, nodes[i]); allocman_mspace_free(alloc, uts_copy[i], sizeof(cspacepath_t)); } return error; } uts_copy[i] = allocman_mspace_alloc(alloc, sizeof(cspacepath_t), &error); if (error) { _free_node(alloc, nodes[i]); for (i--; i >= 0; i--) { _free_node(alloc, nodes[i]); allocman_mspace_free(alloc, uts_copy[i], sizeof(cspacepath_t)); } } } for (i = 0; i < num; i++) { *uts_copy[i] = uts[i]; nodes[i]->ut = uts_copy[i]; nodes[i]->offset = 0; nodes[i]->paddr = paddr[i]; nodes[i]->parent_cookie = 0; nodes[i]->next = nodes[i]->prev = NULL; /* Start with only 1 thing free */ nodes[i]->bitmap = BIT(31); nodes[i]->bitmap_bits = 1; _insert_node(&trickle->heads[size_bits[i]], nodes[i]); } return 0; }
void gnrc_priority_pktqueue_flush(gnrc_priority_pktqueue_t* queue) { assert(queue != NULL); if(gnrc_priority_pktqueue_length(queue) == 0){ return; } gnrc_priority_pktqueue_node_t* node; while( (node = (gnrc_priority_pktqueue_node_t *)priority_queue_remove_head(queue)) ) { gnrc_pktbuf_release(node->pkt); _free_node(node); } }
static int _refill_pool(struct allocman *alloc, utspace_trickle_t *trickle, uint32_t size_bits) { uint32_t i; int error; struct utspace_trickle_node *node; uint32_t cookie; node = _make_node(alloc, &error); if (error) { return error; } /* Check if there are untypeds >= 5 size_bits from us */ for (i = size_bits + 5 > 31 ? 31 : size_bits + 5; i < 32; i++) { if (trickle->heads[i]) { i = size_bits + 5; break; } } if (i == 32) { /* Search for the biggest one near us */ for (i = size_bits + 5 > 31 ? 31 : size_bits + 5; i > size_bits; i--) { if (trickle->heads[i]) { break; } } } if (i != size_bits) { cookie = _utspace_trickle_alloc(alloc, trickle, i, seL4_UntypedObject, NULL, &error); if (!error) { struct utspace_trickle_node *parent = _cookie_to_node(cookie); uint32_t offset = _cookie_to_offset(cookie); node->ut = parent->ut; node->offset = parent->offset + (offset << (i)); if (parent->paddr) { node->paddr = parent->paddr + (offset << (i)); } else { node->paddr = 0; } node->parent_cookie = cookie; node->bitmap_bits = i - size_bits + 1; node->bitmap = _make_bitmap(node->bitmap_bits); node->next = node->prev = NULL; _insert_node(&trickle->heads[size_bits], node); return 0; } } _free_node(alloc, node); return 1; }
void _utspace_trickle_free(struct allocman *alloc, void *_trickle, uint32_t cookie, uint32_t size_bits) { utspace_trickle_t *trickle = (utspace_trickle_t*)_trickle; struct utspace_trickle_node *node = _cookie_to_node(cookie); uint32_t offset = _cookie_to_offset(cookie); int in_list = !(node->bitmap == 0); node->bitmap |= BIT(31 - offset); if (node->bitmap == _make_bitmap(node->bitmap_bits)) { if (node->parent_cookie) { if (in_list) { _remove_node(&trickle->heads[size_bits], node); } _utspace_trickle_free(alloc, trickle, node->parent_cookie, size_bits + node->bitmap_bits - 1); _free_node(alloc, node); } else if (!in_list) { _insert_node(&trickle->heads[size_bits], node); } } else if (!in_list) { _insert_node(&trickle->heads[size_bits], node); } }