static Module* put_module(Eterm mod, IndexTable* mod_tab) { Module e; int oldsz, newsz; Module* res; ASSERT(is_atom(mod)); e.module = atom_val(mod); oldsz = index_table_sz(mod_tab); res = (Module*) index_put_entry(mod_tab, (void*) &e); newsz = index_table_sz(mod_tab); erts_atomic_add_nob(&tot_module_bytes, (newsz - oldsz)); return res; }
void module_end_staging(int commit) { ASSERT(dbg_load_code_ix == erts_staging_code_ix()); if (!commit) { /* abort */ IndexTable* tab = &module_tables[erts_staging_code_ix()]; int oldsz, newsz; ASSERT(entries_at_start_staging <= tab->entries); oldsz = index_table_sz(tab); index_erase_latest_from(tab, entries_at_start_staging); newsz = index_table_sz(tab); erts_atomic_add_nob(&tot_module_bytes, (newsz - oldsz)); } IF_DEBUG(dbg_load_code_ix = -1); }
void module_start_staging(void) { IndexTable* src = &module_tables[erts_active_code_ix()]; IndexTable* dst = &module_tables[erts_staging_code_ix()]; Module* src_mod; Module* dst_mod; int i, oldsz, newsz; ASSERT(dbg_load_code_ix == -1); ASSERT(dst->entries <= src->entries); /* * Make sure our existing modules are up-to-date */ for (i = 0; i < dst->entries; i++) { src_mod = (Module*) erts_index_lookup(src, i); dst_mod = (Module*) erts_index_lookup(dst, i); ASSERT(src_mod->module == dst_mod->module); copy_module(dst_mod, src_mod); } /* * Copy all new modules from active table */ oldsz = index_table_sz(dst); for (i = dst->entries; i < src->entries; i++) { src_mod = (Module*) erts_index_lookup(src, i); dst_mod = (Module*) index_put_entry(dst, src_mod); ASSERT(dst_mod != src_mod); copy_module(dst_mod, src_mod); } newsz = index_table_sz(dst); erts_atomic_add_nob(&tot_module_bytes, (newsz - oldsz)); entries_at_start_staging = dst->entries; IF_DEBUG(dbg_load_code_ix = erts_staging_code_ix()); }
int module_table_sz(void) { return index_table_sz(&module_table); }