Skip to content

Commit 4602033

Browse files
committed
do not resize locks when stage count is set to 0 at ecs fini
1 parent a0f5059 commit 4602033

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

distr/flecs.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42669,16 +42669,33 @@ void flecs_tables_resize_column_locks(
4266942669
int32_t new_stage_count)
4267042670
{
4267142671
flecs_poly_assert(world, ecs_world_t);
42672-
//no need to resize, or world not initialized yet, or being destroyed, or the same stage count
42673-
if (world->flags & (EcsWorldInit|EcsWorldFini) || previous_stage_count == new_stage_count) {
42672+
//no need to resize when is world not initialized yet or changing to the same stage count
42673+
if (world->flags & EcsWorldInit || previous_stage_count == new_stage_count) {
4267442674
return;
4267542675
}
4267642676

42677-
int32_t i, count = flecs_sparse_count(&world->store.tables);
42678-
for (i = 1; i < count; i ++) {
42679-
ecs_table_t *table = flecs_sparse_get_dense_t(&world->store.tables,
42680-
ecs_table_t, i);
42681-
flecs_table_resize_column_locks(world, table, previous_stage_count, new_stage_count);
42677+
if (!(world->flags & EcsWorldFini)) {
42678+
int32_t i, count = flecs_sparse_count(&world->store.tables);
42679+
for (i = 1; i < count; i ++) {
42680+
ecs_table_t *table = flecs_sparse_get_dense_t(&world->store.tables,
42681+
ecs_table_t, i);
42682+
flecs_table_resize_column_locks(world, table, previous_stage_count, new_stage_count);
42683+
}
42684+
// at world fini, we instead want to free the table locks, not resize.
42685+
// at world fini, the world returns to single threaded mode and sets the stage, this is where we clear the tables
42686+
// at the end of world fini, it sets the stage count to 0, we don't want to clean up here as it's already done so.
42687+
} else if (new_stage_count != 0) {
42688+
int32_t i, count = flecs_sparse_count(&world->store.tables);
42689+
for (i = 1; i < count; i ++) {
42690+
ecs_table_t *table = flecs_sparse_get_dense_t(&world->store.tables,
42691+
ecs_table_t, i);
42692+
42693+
if(table->column_lock)
42694+
{
42695+
flecs_wfree_n(world, int32_t, previous_stage_count * table->column_count, table->column_lock);
42696+
table->column_lock = NULL;
42697+
}
42698+
}
4268242699
}
4268342700
}
4268442701

src/storage/table.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,16 +2902,33 @@ void flecs_tables_resize_column_locks(
29022902
int32_t new_stage_count)
29032903
{
29042904
flecs_poly_assert(world, ecs_world_t);
2905-
//no need to resize, or world not initialized yet, or being destroyed, or the same stage count
2906-
if (world->flags & (EcsWorldInit|EcsWorldFini) || previous_stage_count == new_stage_count) {
2905+
//no need to resize when is world not initialized yet or changing to the same stage count
2906+
if (world->flags & EcsWorldInit || previous_stage_count == new_stage_count) {
29072907
return;
29082908
}
29092909

2910-
int32_t i, count = flecs_sparse_count(&world->store.tables);
2911-
for (i = 1; i < count; i ++) {
2912-
ecs_table_t *table = flecs_sparse_get_dense_t(&world->store.tables,
2913-
ecs_table_t, i);
2914-
flecs_table_resize_column_locks(world, table, previous_stage_count, new_stage_count);
2910+
if (!(world->flags & EcsWorldFini)) {
2911+
int32_t i, count = flecs_sparse_count(&world->store.tables);
2912+
for (i = 1; i < count; i ++) {
2913+
ecs_table_t *table = flecs_sparse_get_dense_t(&world->store.tables,
2914+
ecs_table_t, i);
2915+
flecs_table_resize_column_locks(world, table, previous_stage_count, new_stage_count);
2916+
}
2917+
// at world fini, we instead want to free the table locks, not resize.
2918+
// at world fini, the world returns to single threaded mode and sets the stage, this is where we clear the tables
2919+
// at the end of world fini, it sets the stage count to 0, we don't want to clean up here as it's already done so.
2920+
} else if (new_stage_count != 0) {
2921+
int32_t i, count = flecs_sparse_count(&world->store.tables);
2922+
for (i = 1; i < count; i ++) {
2923+
ecs_table_t *table = flecs_sparse_get_dense_t(&world->store.tables,
2924+
ecs_table_t, i);
2925+
2926+
if(table->column_lock)
2927+
{
2928+
flecs_wfree_n(world, int32_t, previous_stage_count * table->column_count, table->column_lock);
2929+
table->column_lock = NULL;
2930+
}
2931+
}
29152932
}
29162933
}
29172934

0 commit comments

Comments
 (0)