diff options
author | Rickard Green <[email protected]> | 2017-02-27 16:18:05 +0100 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2017-03-22 15:27:17 +0100 |
commit | ba23c44add22306495b66d7258f835db00f12868 (patch) | |
tree | 6a1eb24c906f734e57daed244bd044e6cb3106c9 | |
parent | 14982307b07e899e888e5bfb93b3a138d4948459 (diff) | |
download | otp-ba23c44add22306495b66d7258f835db00f12868.tar.gz otp-ba23c44add22306495b66d7258f835db00f12868.tar.bz2 otp-ba23c44add22306495b66d7258f835db00f12868.zip |
erts: Remove now redundant 'id' from DbTableCommon
'the_name' keeps name of all tables.
'type' & DB_NAMED_TABLE mark tables as named.
table ref id is built from magic bin when needed.
-rw-r--r-- | erts/emulator/beam/erl_db.c | 94 | ||||
-rw-r--r-- | erts/emulator/beam/erl_db_util.h | 5 |
2 files changed, 50 insertions, 49 deletions
diff --git a/erts/emulator/beam/erl_db.c b/erts/emulator/beam/erl_db.c index 11936ed9dc..5d14530d84 100644 --- a/erts/emulator/beam/erl_db.c +++ b/erts/emulator/beam/erl_db.c @@ -261,6 +261,17 @@ is_table_alive(DbTable *tb) return !!rtb; } +static ERTS_INLINE int +is_table_named(DbTable *tb) +{ +#ifdef ERTS_SMP + return tb->common.type & DB_NAMED_TABLE; +#else + return tb->common.status & DB_NAMED_TABLE; +#endif +} + + static ERTS_INLINE void tid_clear(Process *c_p, DbTable *tb) { @@ -660,10 +671,7 @@ DbTable* db_get_table_aux(Process *p, */ ASSERT(erts_get_scheduler_data()); - tb = tid2tab(id); - if (tb) - id = tb->common.id; - else if (is_atom(id)) { + if (is_atom(id)) { struct meta_name_tab_entry* bucket = meta_name_tab_bucket(id,&mtl); if (!meta_already_locked) erts_smp_rwmtx_rlock(mtl); @@ -672,7 +680,7 @@ DbTable* db_get_table_aux(Process *p, || erts_lc_rwmtx_is_rwlocked(mtl)); mtl = NULL; } - + tb = NULL; if (bucket->pu.tb != NULL) { if (is_atom(bucket->u.name_atom)) { /* single */ if (bucket->u.name_atom == id) @@ -690,11 +698,13 @@ DbTable* db_get_table_aux(Process *p, } } } + else + tb = tid2tab(id); + if (tb) { db_lock(tb, kind); - if (tb->common.id != id - || ((tb->common.status & what) == 0 - && p->common.id != tb->common.owner)) { + if ((tb->common.status & what) == 0 + && p->common.id != tb->common.owner) { db_unlock(tb, kind); tb = NULL; } @@ -777,9 +787,10 @@ static int remove_named_tab(DbTable *tb, int have_lock) { int ret = 0; erts_smp_rwmtx_t* rwlock; - Eterm name_atom = tb->common.id; + Eterm name_atom = tb->common.the_name; struct meta_name_tab_entry* bucket = meta_name_tab_bucket(name_atom, &rwlock); + ASSERT(is_table_named(tb)); #ifdef ERTS_SMP if (!have_lock && erts_smp_rwmtx_tryrwlock(rwlock) == EBUSY) { db_unlock(tb, LCK_WRITE); @@ -1528,8 +1539,8 @@ BIF_RETTYPE ets_rename_2(BIF_ALIST_2) if (!tb) BIF_ERROR(BIF_P, BADARG); else { - if (is_atom(tb->common.id)) { - old_name = tb->common.id; + if (is_table_named(tb)) { + old_name = tb->common.the_name; goto named_tab; } lck2 = NULL; @@ -1544,24 +1555,19 @@ BIF_RETTYPE ets_rename_2(BIF_ALIST_2) if (!tb) goto badarg; - if (is_not_atom(tb->common.id)) { /* Not a named table */ - tb->common.the_name = BIF_ARG_2; - goto done; - } + if (is_table_named(tb)) { + if (!insert_named_tab(BIF_ARG_2, tb, 1)) + goto badarg; - if (!insert_named_tab(BIF_ARG_2, tb, 1)) - goto badarg; - - if (!remove_named_tab(tb, 1)) - erts_exit(ERTS_ERROR_EXIT,"Could not find named tab %s", tb->common.id); - - tb->common.id = tb->common.the_name = BIF_ARG_2; - - done: - if (is_atom(tb->common.id)) - ret = tb->common.id; - else + if (!remove_named_tab(tb, 1)) + erts_exit(ERTS_ERROR_EXIT,"Could not find named tab %s", tb->common.the_name); + ret = BIF_ARG_2; + } + else { /* Not a named table */ ret = BIF_ARG_1; + } + tb->common.the_name = BIF_ARG_2; + db_unlock(tb, LCK_WRITE); erts_smp_rwmtx_rwunlock(lck1); if (lck2) @@ -1691,6 +1697,7 @@ BIF_RETTYPE ets_new_2(BIF_ALIST_2) } else if (val == am_named_table) { is_named = 1; + status |= DB_NAMED_TABLE; } else if (val == am_compressed) { is_compressed = 1; @@ -1765,16 +1772,9 @@ BIF_RETTYPE ets_new_2(BIF_ALIST_2) make_btid(tb); - if (is_named) { - ret = BIF_ARG_1; - tb->common.id = ret; - } - else { - ret = make_tid(BIF_P, tb); - tb->common.id = THE_NON_VALUE; /* or what? */ - } - - if (!is_named) + if (is_named) + ret = BIF_ARG_1; + else ret = make_tid(BIF_P, tb); save_sched_table(BIF_P, tb); @@ -1951,7 +1951,7 @@ BIF_RETTYPE ets_delete_1(BIF_ALIST_1) tid_clear(BIF_P, tb); - if (is_atom(tb->common.id)) + if (is_table_named(tb)) remove_named_tab(tb, 0); /* disable inheritance */ @@ -2385,8 +2385,8 @@ ets_all_reply(ErtsSchedulerData *esdp, ErtsEtsAllReq **reqpp, while (1) { if (is_table_alive(tb)) { Eterm tid; - if (is_atom(tb->common.id)) - tid = tb->common.id; + if (is_table_named(tb)) + tid = tb->common.the_name; else tid = erts_mk_magic_ref(&hp, ohp, tb->common.btid); list = CONS(hp, tid, list); @@ -3446,7 +3446,7 @@ send_ets_transfer_message(Process *c_p, Process *proc, Eterm tid, hd_copy, msg, sender; hsz = 5; - if (is_not_atom(tb->common.id)) + if (!is_table_named(tb)) hsz += ERTS_MAGIC_REF_THING_SIZE; if (is_immed(heir_data)) hd_sz = 0; @@ -3456,8 +3456,8 @@ send_ets_transfer_message(Process *c_p, Process *proc, } mp = erts_alloc_message_heap(proc, locks, hsz, &hp, &ohp); - if (is_atom(tb->common.id)) - tid = tb->common.id; + if (is_table_named(tb)) + tid = tb->common.the_name; else tid = erts_mk_magic_ref(&hp, ohp, tb->common.btid); if (!hd_sz) @@ -3584,7 +3584,7 @@ erts_db_process_exiting(Process *c_p, ErtsProcLocks c_p_locks) tb->common.status &= ~(DB_PROTECTED | DB_PUBLIC | DB_PRIVATE); tb->common.status |= DB_DELETE; - if (is_atom(tb->common.id)) + if (is_table_named(tb)) remove_named_tab(tb, 0); free_heir_data(tb); @@ -3990,7 +3990,7 @@ static Eterm table_info(Process* p, DbTable* tb, Eterm What) } else if (What == am_node) { ret = erts_this_dist_entry->sysname; } else if (What == am_named_table) { - ret = is_atom(tb->common.id) ? am_true : am_false; + ret = is_table_named(tb) ? am_true : am_false; } else if (What == am_compressed) { ret = tb->common.compress ? am_true : am_false; } @@ -4097,8 +4097,8 @@ static void print_table(fmtfn_t to, void *to_arg, int show, DbTable* tb) Eterm tid; Eterm heap[ERTS_MAGIC_REF_THING_SIZE]; - if (is_atom(tb->common.id)) { - tid = tb->common.id; + if (is_table_named(tb)) { + tid = tb->common.the_name; } else { ErlOffHeap oh; ERTS_INIT_OFF_HEAP(&oh); diff --git a/erts/emulator/beam/erl_db_util.h b/erts/emulator/beam/erl_db_util.h index e22113b72f..198f339751 100644 --- a/erts/emulator/beam/erl_db_util.h +++ b/erts/emulator/beam/erl_db_util.h @@ -243,7 +243,6 @@ typedef struct db_table_common { UWord heir_data; /* To send in ETS-TRANSFER (is_immed or (DbTerm*) */ Uint64 heir_started_interval; /* To further identify the heir */ Eterm the_name; /* an atom */ - Eterm id; /* atom | integer */ Binary *btid; DbTableMethod* meth; /* table methods */ erts_smp_atomic_t nitems; /* Total number of items in table */ @@ -273,8 +272,10 @@ typedef struct db_table_common { #define DB_ORDERED_SET (1 << 9) #define DB_DELETE (1 << 10) /* table is being deleted */ #define DB_FREQ_READ (1 << 11) +#define DB_NAMED_TABLE (1 << 12) -#define ERTS_ETS_TABLE_TYPES (DB_BAG|DB_SET|DB_DUPLICATE_BAG|DB_ORDERED_SET|DB_FINE_LOCKED|DB_FREQ_READ) +#define ERTS_ETS_TABLE_TYPES (DB_BAG|DB_SET|DB_DUPLICATE_BAG|DB_ORDERED_SET\ + |DB_FINE_LOCKED|DB_FREQ_READ|DB_NAMED_TABLE) #define IS_HASH_TABLE(Status) (!!((Status) & \ (DB_BAG | DB_SET | DB_DUPLICATE_BAG))) |