static int so_atom_delete_oldest(session_opt_t *so) { atom_t *atom, *oldest; size_t count, i; dbg_err_if (so == NULL); count = atoms_count(so->atoms); nop_err_if(count == 0); dbg_err_if(atoms_getn(so->atoms, 0, &oldest)); for(i = 1; i < count; ++i) { dbg_err_if(atoms_getn(so->atoms, i, &atom)); /* save if older */ if(atom->arg <= oldest->arg) oldest = atom; } dbg_err_if(atoms_remove(so->atoms, oldest)); return 0; err: return ~0; }
static int so_atom_add(session_opt_t *so, const char *id, char *buf, size_t size, void *arg) { atom_t *atom = NULL, *old = NULL; size_t new_size, old_found = 0; dbg_err_if (so == NULL); dbg_err_if (id == NULL); dbg_err_if (buf == NULL); /* get the old atom associated to this id */ if(!atoms_get(so->atoms, id, &old)) old_found = 1; /* delete the oldest session if there are already max_count sessions */ if(so->max_count && atoms_count(so->atoms) - old_found >= so->max_count) dbg_err_if(session_delete_oldest(so)); /* delete the oldest session(s) if we are using already mem_limit bytes */ if(so->mem_limit) { warn_err_ifm(size > so->mem_limit, "session size is bigger the memory.limit, save aborted..."); for(;;) { /* new_size = size of all atoms + size of the atom we're going to add - the size of the atom (if found) we're going to remove */ new_size = atoms_size(so->atoms) + size - (old ? old->size : 0); if(atoms_count(so->atoms) && new_size > so->mem_limit) dbg_err_if(session_delete_oldest(so)); else break; } } /* create a new atom */ dbg_err_if(atom_create(id, buf, size, arg, &atom)); /* add it to the list */ dbg_err_if(atoms_add(so->atoms, atom)); /* remove the old atom associated to this id */ if(old) { dbg_err_if(atoms_remove(so->atoms, old)); atom_free(old); } return 0; err: if(atom) atom_free(atom); return ~0; }
void sys_remove_atom(struct sys *sys, int idx) { struct atoms *atoms = sys_get_atoms(sys, sys->current_frame); assert(sys_single_frame(sys)); atoms_remove(atoms, idx); graph_vertex_remove(sys->graph, idx); sel_contract(sys->sel, idx); sel_contract(sys->visible, idx); sys->is_modified = TRUE; }
static int so_atom_remove(session_opt_t *so, const char *id) { atom_t *atom = NULL; dbg_err_if (so == NULL); dbg_err_if (id == NULL); /* find the atom bound to this session */ if(atoms_get(so->atoms, id, &atom)) return 0; /* remove it from the list */ dbg_err_if(atoms_remove(so->atoms, atom)); atom_free(atom); return 0; err: return ~0; }