void snd_seq_cell_free(struct snd_seq_event_cell * cell) { unsigned long flags; struct snd_seq_pool *pool; if (snd_BUG_ON(!cell)) return; pool = cell->pool; if (snd_BUG_ON(!pool)) return; spin_lock_irqsave(&pool->lock, flags); free_cell(pool, cell); if (snd_seq_ev_is_variable(&cell->event)) { if (cell->event.data.ext.len & SNDRV_SEQ_EXT_CHAINED) { struct snd_seq_event_cell *curp, *nextptr; curp = cell->event.data.ext.ptr; for (; curp; curp = nextptr) { nextptr = curp->next; curp->next = pool->free; free_cell(pool, curp); } } } if (waitqueue_active(&pool->output_sleep)) { if (snd_seq_output_ok(pool)) wake_up(&pool->output_sleep); } spin_unlock_irqrestore(&pool->lock, flags); }
void snd_seq_cell_free(snd_seq_event_cell_t * cell) { unsigned long flags; pool_t *pool; snd_assert(cell != NULL, return); pool = cell->pool; snd_assert(pool != NULL, return); spin_lock_irqsave(&pool->lock, flags); free_cell(pool, cell); if (snd_seq_ev_is_variable(&cell->event)) { if (cell->event.data.ext.len & SNDRV_SEQ_EXT_CHAINED) { snd_seq_event_cell_t *curp, *nextptr; curp = cell->event.data.ext.ptr; for (; curp; curp = nextptr) { nextptr = curp->next; curp->next = pool->free; free_cell(pool, curp); } } } if (waitqueue_active(&pool->output_sleep)) { /* has enough space now? */ if (snd_seq_output_ok(pool)) wake_up(&pool->output_sleep); } spin_unlock_irqrestore(&pool->lock, flags); }
void free_one_cell(C *c) { switch (c->type) { case LABEL: case TRUTH: free(c->val.label); free(c); break; case LIST: free_cell(c->val.list); free(c); break; case BUILTIN: free(c->val.func.name); free(c); break; case PROC: free_cell(c->val.proc.args); free_cell(c->val.proc.body); // c->val.proc.env points to the evaluating env, open question on // when that gets collected! free(c); break; case NIL: break; } }
/* returns number of ticks before retrying the del, or 0 if the del. * was succesfull */ inline static ticks_t delete_cell(struct cell *p_cell, int unlock) { /* there may still be FR/RETR timers, which have been reset (i.e., time_out==TIMER_DELETED) but are stilled linked to timer lists and must be removed from there before the structures are released */ unlink_timers(p_cell); /* still in use ... don't delete */ if(IS_REFFED_UNSAFE(p_cell)) { if(unlock) UNLOCK_HASH(p_cell->hash_index); LM_DBG("%p: can't delete -- still reffed (%d)\n", p_cell, p_cell->ref_count); /* delay the delete */ /* TODO: change refcnts and delete on refcnt==0 */ return cfg_get(tm, tm_cfg, delete_timeout); } else { if(unlock) UNLOCK_HASH(p_cell->hash_index); #ifdef EXTRA_DEBUG LM_DBG("delete transaction %p\n", p_cell); #endif free_cell(p_cell); return 0; } }
object_type remove_of_list(list_pointer *p, list_type *list) { list_pointer aux; object_type item; /* Tests is the list is empty or the pointer is null */ if (is_empty(list) || !(*p) || (*p==list->first)) { printf("Error: List is_empty or position doesn't exists.\n"); item.dimension_values.categorical_values=NULL; item.dimension_values.real_values=NULL; item.dimension_values.ordinal_values=NULL; item.number=0; } else { item=(*p)->item; (*p)->next->previous=(*p)->previous; (*p)->previous->next=(*p)->next; if ((*p)==list->last) list->last=(*p)->previous; aux=(*p); (*p)=(*p)->previous; free_cell(aux); list->length--; } return item; }
void free_table(vtab_p table) { if (table->cell != NULL) { for (int row = 0; (row < ALL_TABLE_ROWS); row++) { for (int col = 0; (col < ALL_TABLE_COLS); col++) { free_cell(table, row, col); } } free(table->cell); } if (table->row_ix_map != NULL) { free(table->row_ix_map); } if (table->row_flags != NULL) { free(table->row_flags); } if (table->col_flags != NULL) { free(table->col_flags); } if (table->col_width != NULL) { free(table->col_width); } if (table->col_decimal_places != NULL) { free(table->col_decimal_places); } }
/* * Send a request using data from the dialog structure * ret_index and ret_label will identify the new cell */ int t_uac_with_ids(str* method, str* headers, str* body, dlg_t* dialog, transaction_cb cb, void* cbp, unsigned int *ret_index, unsigned int *ret_label) { struct retr_buf *request; struct cell *cell; int ret; int is_ack; ret = t_uac_prepare(method, headers, body, dialog, cb, cbp, &request, &cell); if (ret < 0) return ret; is_ack = (method->len == 3) && (memcmp("ACK", method->s, 3)==0) ? 1 : 0; send_prepared_request_impl(request, !is_ack /* retransmit */); if (is_ack) { if (cell) free_cell(cell); if (ret_index && ret_label) *ret_index = *ret_label = 0; } else { if (ret_index && ret_label) { *ret_index = cell->hash_index; *ret_label = cell->label; } } return ret; }
static cell_t *read_bytevector(secd_parser_t *p) { secd_t *secd = p->secd; assert(p->token == '(', "read_bytevector: '(' expected"); cell_t *tmplist = SECD_NIL; cell_t *cur; size_t len = 0; while (lexnext(p) == TOK_NUM) { assert((0 <= p->numtok) && (p->numtok < 256), "read_bytevector: out of range"); cell_t *newc = new_cons(secd, new_number(secd, p->numtok), SECD_NIL); if (not_nil(tmplist)) { cur->as.cons.cdr = share_cell(secd, newc); cur = newc; } else { tmplist = cur = newc; } ++len; } cell_t *bvect = new_bytevector_of_size(secd, len); assert_cell(bvect, "read_bytevector: failed to allocate"); unsigned char *mem = (unsigned char *)strmem(bvect); cur = tmplist; size_t i; for (i = 0; i < len; ++i) { mem[i] = (unsigned char)numval(list_head(cur)); cur = list_next(secd, cur); } free_cell(secd, tmplist); return bvect; }
int state_fits(int i, int j, int k) { int c; for (c=1; c<=k; c++) if (state(i,c)!=0 && !free_cell(j+c)) return(FALSE); return(TRUE); }
void unlink_timer_lists(void) { struct timer_link *tl, *end, *tmp; enum lists i; unsigned int set; if (timertable==0) return; /* nothing to do */ for ( set=0 ; set<timer_sets ; set++) { /* remember the DELETE LIST */ tl = timertable[set].timers[DELETE_LIST].first_tl.next_tl; end = & timertable[set].timers[DELETE_LIST].last_tl; /* unlink the timer lists */ for( i=0; i<NR_OF_TIMER_LISTS ; i++ ) reset_timer_list( set, i ); LM_DBG("emptying DELETE list for set %d\n",set); /* deletes all cells from DELETE_LIST list (they are no more accessible from entries) */ while (tl!=end) { tmp=tl->next_tl; free_cell( get_dele_timer_payload(tl) ); tl=tmp; } } }
void test_cell_add_neighbour(void) { printf("\ntest_cell_add_neighbour\n"); s_cell cells[4]; int c, result; uint8_t nb_cells; nb_cells = 3; for (c = 0; c < 4; c++) { init_cell(&cells[c], c, nb_cells); } result = cell_add_neighbour(&cells[0], &cells[1]); assert_int_equals(result, CELL_ADD_NEIGHBOUR_OK); assert_int_equals(cells[0].nb_neighbours, 1); assert_int_equals(cells[1].nb_neighbours, 1); result = cell_add_neighbour(&cells[0], &cells[1]); assert_int_equals(result, CELL_ERROR_ALREADY_NEIGHBOUR); assert_int_equals(cells[0].nb_neighbours, 1); assert_int_equals(cells[1].nb_neighbours, 1); cell_add_neighbour(&cells[0], &cells[2]); result = cell_add_neighbour(&cells[0], &cells[3]); assert_int_equals(result, CELL_ERROR_MAX_NEIGHBOURS_REACHED); assert_int_equals(cells[0].nb_neighbours, nb_cells - 1); assert_int_equals(cells[3].nb_neighbours, 0); for (c = 0; c < 4; c++) { free_cell(&cells[c]); } }
void test_cell_set_nb_pawns(void) { printf("\ntest_cell_set_nb_pawns\n"); s_cell c; s_player p; int result; init_cell(&c, 1, 4); init_player(&p, 1, "test", 1, STRATEGY_NONE, 10); result = cell_set_nb_pawns(&c, 13); assert_int_equals(result, CELL_ERROR_SET_PAWNS_NO_OWNER); assert_int_equals(c.nb_pawns, 0); cell_set_owner(&c, &p); result = cell_set_nb_pawns(&c, 13); assert_int_equals(result, CELL_ERROR_SET_PAWNS_NOT_ENOUGH_PAWNS); assert_int_equals(c.nb_pawns, 0); result = cell_set_nb_pawns(&c, 10); assert_int_equals(result, CELL_SET_PAWNS_OK); assert_int_equals(c.nb_pawns, 10); free_cell(&c); }
void free_cell(struct s_Cell *cell) { if (cell != 0) { free_cell(cell->next_cell); free(cell); } }
// ----------------------------------------------------- // Free a linked chain of cells void free_chain( cell c ) { cell next; while (c != NULL) { next = c->next; free_cell( c ); c = next; } }
void test_free_cell(void) { printf("\ntest_free_cell\n"); s_cell c; init_cell(&c, 1, 4); free_cell(&c); assert_null(c.neighbours); }
void free_pd_op(pd_op_t *pdo) { if(pdo==NULL) return; free_cell(pdo->cell); shm_free(pdo); pdo = NULL; return; }
/* free allocated space for an entry */ void free_entry(entry_t *e, int erase_cell) { if(!e) return; if(erase_cell && e->dc) free_cell(e->dc); shm_free(e); }
int secd_dump_state(secd_t *secd, cell_t *fname) { cell_t *p = secd_newport(secd, "w", "file", fname); secd_pprintf(secd, p, ";; secd->fixedptr = %ld\n", cell_index(secd, secd->fixedptr)); secd_pprintf(secd, p, ";; secd->arrayptr = %ld\n", cell_index(secd, secd->arrayptr)); secd_pprintf(secd, p, ";; secd->end = %ld\n", cell_index(secd, secd->end)); secd_pprintf(secd, p, ";; secd->input_port = %ld, secd->output_port = %ld\n", cell_index(secd, secd->input_port), cell_index(secd, secd->output_port)); secd_pprintf(secd, p, ";; SECD = (%ld, %ld, %ld, %ld)\n", cell_index(secd, secd->stack), cell_index(secd, secd->env), cell_index(secd, secd->control), cell_index(secd, secd->dump)); secd_pprintf(secd, p, ";; secd->free = %ld (%ld free)\n", cell_index(secd, secd->free), secd->stat.free_cells); /* dump fixed heap */ long i; long n_fixed = secd->fixedptr - secd->begin; secd_pprintf(secd, p, "\n;; SECD persistent heap:\n"); for (i = 0; i < n_fixed; ++i) { cell_t *cell_info = serialize_cell(secd, secd->begin + i); sexp_pprint(secd, p, cell_info); secd_pprintf(secd, p, "\n"); free_cell(secd, cell_info); } secd_pprintf(secd, p, "\n;; SECD array heap:\n"); cell_t *mcons = secd->arrlist; while (mcons_next(mcons)) { cell_t *cell_info = serialize_cell(secd, mcons); sexp_pprint(secd, p, cell_info); if (!mcons->as.mcons.free) secd_pdump_array(secd, p, mcons); secd_pprintf(secd, p, "\n"); free_cell(secd, cell_info); mcons = mcons_next(mcons); } secd_pclose(secd, p); free_cell(secd, p); return 0; }
/********************************************************************** * d e s t r o y * * Return the space taken by a list to the heap. **********************************************************************/ LIST destroy(LIST list) { LIST next; while (list != NIL_LIST) { next = list_rest (list); free_cell(list); list = next; } return (NIL_LIST); }
/********************************************************************** * p o p * * Return the list with the first element removed. Destroy the space * that it occupied in the list. **********************************************************************/ LIST pop(LIST list) { LIST temp; temp = list_rest (list); if (list != NIL_LIST) { free_cell(list); } return (temp); }
int pdt_remove_from_hash(pdt_hash_t *hash, str *sd) { int hash_entry=0; unsigned int dhash; pd_t *it, *tmp; if(sd==NULL) return 0; if(hash==NULL) { LOG(L_ERR, "PDT:pdt_remove_from_hash: bad parameters\n"); return -1; } /* find the list where the cell must be */ dhash = pdt_compute_hash(sd->s); hash_entry = get_hash_entry(dhash, hash->hash_size); lock_get(&hash->dhash[hash_entry].lock); /* first element of the list */ it = hash->dhash[hash_entry].e; /* find the cell in the list */ /* a double linked list in the hash is kept alphabetically * or numerical ordered */ tmp = NULL; while(it!=NULL) { if( it->dhash==dhash && it->domain.len==sd->len && strncasecmp(it->domain.s, sd->s, sd->len)==0) break; tmp = it; it = it->n; } if(it!=NULL) { if(tmp!=NULL) tmp->n = it->n; else hash->dhash[hash_entry].e = it->n; if(it->n) it->n->p = it->p; free_cell(it); } lock_release(&hash->dhash[hash_entry].lock); return 0; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // AK add c/g gor cells cell * del_cell(cell *c) { cell *cc; cc = c->prev; // AK add c/g if (!(c->next)) AKCheckChain(); del_retain_cell(c); free_cell(c); return cc; }
void free_row(struct s_Row *row) { if (row != 0) { free_row(row->next_row); free_cell(row->first_cell); free(row); } }
/** * insert temp. state into the compressed array */ int new_state(int i, int k) { int j,c; for (j=first_free_cell; ; j++) { if (j>=cells_size-k) { if ((cells=realloc(cells,(cells_size+=cells_delta)*sizeof(tcell)))==NULL) error("Memory full"); memset(cells+(cells_size-cells_delta),0,cells_delta*sizeof(tcell)); } if (free_cell(j) && state_fits(i,j,k)) { for (c=1; c<=k; c++) if (state(i,c)!=0) save_cell(j+c, c, state(i,c)); save_cell(j, (state(i,0)==0 ? letter_count : 0), string_set(i)); break; } } if (j-COMPWIN > first_free_cell) first_free_cell = j-COMPWIN; for ( ; !free_cell(first_free_cell); first_free_cell++) ; if (j+k > last_full_cell) last_full_cell = j+k; return(j); }
/** * Function to free the memory used by a board. Will free the board's cells and * players, which have been allocated with a calloc. * * @param s_board *b The board to free * * @return void */ void free_board(s_board *b) { int c; for (c = 0; c < b->nb_cells; c++) { free_cell(&b->cells[c]); } free(b->cells); free(b->players); b->cells = NULL; b->players = NULL; }
static void finalize_heap(void) { size_t i; ScmCell *cell; ScmObjHeap heap; for (i = 0; i < l_n_heaps; i++) { heap = l_heaps[i]; for (cell = &heap[0]; cell < &heap[l_heap_size]; cell++) free_cell(cell); free(heap); } free(l_heaps); }
void test_cell_set_owner(void) { printf("\ntest_cell_set_owner\n"); s_cell c; s_player p; init_cell(&c, 1, 4); init_player(&p, 1, "test", 1, STRATEGY_NONE, 10); assert_null(c.owner); cell_set_owner(&c, &p); assert_str_equals(c.owner->name, "test"); assert_int_equals(c.owner->nb_cells, 1); free_cell(&c); }
/* remove_from_list removes a cell from cache * and frees that cell */ void remove_from_list(struct cache_cell *cell) { cache_size -= cell->size; if (cell->previous != NULL) (cell->previous)->next = cell->next; else head = cell->next; if (cell->next != NULL) (cell->next)->previous = cell->previous; free_cell(cell); return; }
void test_init_cell(void) { printf("\ntest_init_cell\n"); s_cell c; int result; result = init_cell(&c, 1, 4); assert_null(c.owner); assert_int_equals(result, 1); assert_int_equals(c.id, 1); assert_int_equals(c.nb_pawns, 0); assert_int_equals(c.nb_neighbours, 0); assert_int_equals(c.nb_max_neighbours, 3); free_cell(&c); }
/* * Send a request using data from the dialog structure */ int t_uac(str* method, str* headers, str* body, dlg_t* dialog, transaction_cb cb, void* cbp) { struct retr_buf *request; struct cell *cell; int ret; int is_ack; ret = t_uac_prepare(method, headers, body, dialog, cb, cbp, &request, &cell); if (ret < 0) return ret; is_ack = (method->len == 3) && (memcmp("ACK", method->s, 3)==0) ? 1 : 0; send_prepared_request_impl(request, !is_ack /* retransmit */); if (cell && is_ack) free_cell(cell); return ret; }