static int assign_base(dary *da, int n, uchar k) { int free_node = find_free_node(da, k); if (free_node >= k) { da->base[n] = free_node - k; dprint("found freenode in %d", free_node); return free_node; } else { dprint("freenode not found"); da->base[n] = da->length - k; return da->length; } }
static int insert_cbr(struct cbr_record * record, cbr_func cbr, unsigned int prio) { ASSERT(record != NULL && cbr != NULL); struct cbr_node * new_node = find_free_node(); if (new_node == NULL) { struct cbr_node_arena * new_arena = expand_cbr_node_pool(); if (new_arena == NULL || &(new_arena->pool[0]) == NULL) { return -1; } else { new_node = &(new_arena->pool[0]); } } new_node->cbr = cbr; new_node->priority = prio; if (record->first == NULL) { dbg_printf("First record is new, assigning\n"); record->first = new_node; } else { struct cbr_node * current = record->first; struct cbr_node * prev = NULL; while (current != NULL) { if (current->priority < prio) { if (prev == NULL) { record->first = new_node; new_node->next = current; return 0; } else { prev->next = new_node; new_node->next = current; return 0; } } prev = current; if (current->next == NULL) { current->next = new_node; return 0; } else { current = current->next; } } return -1; } return 0; }