Skip to content

Commit

Permalink
Support suspending readonly outside of multithreaded systens
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Sep 22, 2024
1 parent 02acb11 commit 2aaf782
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions distr/flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -10906,7 +10906,7 @@ ecs_entity_t ecs_add_path_w_sep(
* immediately updated. Without this, we could create multiple entities for
* the same name in a single command queue. */
bool suspend_defer = ecs_is_deferred(world) &&
(ecs_get_stage_count(world) <= 1);
!(world->flags & EcsWorldMultiThreaded);

ecs_entity_t cur = parent;
char *name = NULL;
Expand Down Expand Up @@ -17935,7 +17935,7 @@ ecs_world_t* flecs_suspend_readonly(

/* Cannot suspend when running with multiple threads */
ecs_assert(!(world->flags & EcsWorldReadonly) ||
(ecs_get_stage_count(world) <= 1), ECS_INVALID_WHILE_READONLY, NULL);
!(world->flags & EcsWorldMultiThreaded), ECS_INVALID_WHILE_READONLY, NULL);

state->is_readonly = is_readonly;
state->is_deferred = stage->defer != 0;
Expand Down
2 changes: 1 addition & 1 deletion src/entity_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ ecs_entity_t ecs_add_path_w_sep(
* immediately updated. Without this, we could create multiple entities for
* the same name in a single command queue. */
bool suspend_defer = ecs_is_deferred(world) &&
(ecs_get_stage_count(world) <= 1);
!(world->flags & EcsWorldMultiThreaded);

ecs_entity_t cur = parent;
char *name = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ ecs_world_t* flecs_suspend_readonly(

/* Cannot suspend when running with multiple threads */
ecs_assert(!(world->flags & EcsWorldReadonly) ||
(ecs_get_stage_count(world) <= 1), ECS_INVALID_WHILE_READONLY, NULL);
!(world->flags & EcsWorldMultiThreaded), ECS_INVALID_WHILE_READONLY, NULL);

state->is_readonly = is_readonly;
state->is_deferred = stage->defer != 0;
Expand Down
3 changes: 2 additions & 1 deletion test/core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,8 @@
"add_set_isa_w_override_batched",
"add_batched_set_with",
"defer_emplace_after_remove",
"batched_w_table_change_in_observer"
"batched_w_table_change_in_observer",
"redefine_named_in_threaded_app"
]
}, {
"id": "SingleThreadStaging",
Expand Down
19 changes: 19 additions & 0 deletions test/core/src/Commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -4190,3 +4190,22 @@ void Commands_batched_w_table_change_in_observer(void) {

ecs_fini(world);
}

void Commands_redefine_named_in_threaded_app(void) {
ecs_world_t *world = ecs_init();

ecs_set_threads(world, 2);

ecs_defer_begin(world);
ecs_entity_t c1 = ecs_entity(world, { .name = "parent.child_1" });
ecs_entity_t c2 = ecs_entity(world, { .name = "parent.child_2" });
ecs_defer_end(world);

ecs_entity_t p1 = ecs_get_target(world, c1, EcsChildOf, 0);
test_assert(p1 != 0);
ecs_entity_t p2 = ecs_get_target(world, c2, EcsChildOf, 0);
test_assert(p2 != 0);
test_assert(p1 == p2);

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/core/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,7 @@ void Commands_add_set_isa_w_override_batched(void);
void Commands_add_batched_set_with(void);
void Commands_defer_emplace_after_remove(void);
void Commands_batched_w_table_change_in_observer(void);
void Commands_redefine_named_in_threaded_app(void);

// Testsuite 'SingleThreadStaging'
void SingleThreadStaging_setup(void);
Expand Down Expand Up @@ -10354,6 +10355,10 @@ bake_test_case Commands_testcases[] = {
{
"batched_w_table_change_in_observer",
Commands_batched_w_table_change_in_observer
},
{
"redefine_named_in_threaded_app",
Commands_redefine_named_in_threaded_app
}
};

Expand Down Expand Up @@ -11210,7 +11215,7 @@ static bake_test_suite suites[] = {
"Commands",
NULL,
NULL,
140,
141,
Commands_testcases
},
{
Expand Down

0 comments on commit 2aaf782

Please sign in to comment.