aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/erl_db_hash.c
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2018-03-12 11:50:42 +0100
committerSverker Eriksson <[email protected]>2018-05-08 14:38:41 +0200
commit3ab4ac0371b8646246c8b029dd89f39c3a6981b4 (patch)
tree2a1f87590829ec2a82d16f6afe2d604f0e8fa300 /erts/emulator/beam/erl_db_hash.c
parentc26bfdd48c8deabe9cc0f67badb0d8a95a641845 (diff)
downloadotp-3ab4ac0371b8646246c8b029dd89f39c3a6981b4.tar.gz
otp-3ab4ac0371b8646246c8b029dd89f39c3a6981b4.tar.bz2
otp-3ab4ac0371b8646246c8b029dd89f39c3a6981b4.zip
erts: Make atomic ets:delete_all_objects yield
by using a cooperative strategy that will make any process accessing the table execute delelete_all_objects_continue until the table is empty. This is not an optimal solution as concurrent threads will still block on the table lock, but at least thread progress is made.
Diffstat (limited to 'erts/emulator/beam/erl_db_hash.c')
-rw-r--r--erts/emulator/beam/erl_db_hash.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/erts/emulator/beam/erl_db_hash.c b/erts/emulator/beam/erl_db_hash.c
index cb5c496e90..8bbd0cd9a3 100644
--- a/erts/emulator/beam/erl_db_hash.c
+++ b/erts/emulator/beam/erl_db_hash.c
@@ -411,7 +411,7 @@ static void db_foreach_offheap_hash(DbTable *,
void (*)(ErlOffHeap *, void *),
void *);
-static int db_delete_all_objects_hash(Process* p, DbTable* tbl);
+static SWord db_delete_all_objects_hash(Process* p, DbTable* tbl, SWord reds);
#ifdef HARDDEBUG
static void db_check_table_hash(DbTableHash *tb);
#endif
@@ -2255,7 +2255,7 @@ void db_initialize_hash(void)
}
-int db_mark_all_deleted_hash(DbTable *tbl)
+static SWord db_mark_all_deleted_hash(DbTable *tbl, SWord reds)
{
DbTableHash *tb = &tbl->hash;
HashDbTerm* list;
@@ -2270,10 +2270,11 @@ int db_mark_all_deleted_hash(DbTable *tbl)
list->hvalue = INVALID_HASH;
list = list->next;
}while(list != NULL);
+ reds--;
}
}
erts_atomic_set_nob(&tb->common.nitems, 0);
- return DB_ERROR_NONE;
+ return reds < 0 ? 0 : reds; /* ToDo: Yield! */
}
@@ -3073,16 +3074,20 @@ db_finalize_dbterm_hash(int cret, DbUpdateHandle* handle)
return;
}
-static int db_delete_all_objects_hash(Process* p, DbTable* tbl)
+static SWord db_delete_all_objects_hash(Process* p, DbTable* tbl, SWord reds)
{
if (IS_FIXED(tbl)) {
- db_mark_all_deleted_hash(tbl);
+ /* ToDo: Yield! */
+ reds = db_mark_all_deleted_hash(tbl, reds);
} else {
- db_free_table_hash(tbl);
+ reds = db_free_table_continue_hash(tbl, reds);
+ if (reds < 0)
+ return reds;
+
db_create_hash(p, tbl);
erts_atomic_set_nob(&tbl->hash.common.nitems, 0);
}
- return 0;
+ return reds;
}
void db_foreach_offheap_hash(DbTable *tbl,