Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions distr/flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -43938,6 +43938,15 @@ void ecs_table_unlock(
}
}

bool ecs_table_is_locked(
const ecs_table_t *table)
{
if (!table) {
return false;
}
return table->_->lock != 0;
}

const ecs_type_t* ecs_table_get_type(
const ecs_table_t *table)
{
Expand Down
11 changes: 11 additions & 0 deletions distr/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10929,6 +10929,17 @@ void ecs_table_unlock(
ecs_world_t *world,
ecs_table_t *table);

/** Check if a table is locked.
* Can be used to check whether an operation that modifies the table would
* run into a table lock assert.
*
* @param table The table.
* @return True if the table is locked, false if not (or if table is NULL).
*/
FLECS_API
bool ecs_table_is_locked(
const ecs_table_t *table);

/** Test a table for flags.
* Test if a table has all of the provided flags. See
* include/flecs/private/api_flags.h for a list of table flags that can be used
Expand Down
9 changes: 9 additions & 0 deletions distr/flecs_no_addons.c
Original file line number Diff line number Diff line change
Expand Up @@ -31627,6 +31627,15 @@ void ecs_table_unlock(
}
}

bool ecs_table_is_locked(
const ecs_table_t *table)
{
if (!table) {
return false;
}
return table->_->lock != 0;
}

const ecs_type_t* ecs_table_get_type(
const ecs_table_t *table)
{
Expand Down
11 changes: 11 additions & 0 deletions distr/flecs_no_addons.h
Original file line number Diff line number Diff line change
Expand Up @@ -10033,6 +10033,17 @@ void ecs_table_unlock(
ecs_world_t *world,
ecs_table_t *table);

/** Check if a table is locked.
* Can be used to check whether an operation that modifies the table would
* run into a table lock assert.
*
* @param table The table.
* @return True if the table is locked, false if not (or if table is NULL).
*/
FLECS_API
bool ecs_table_is_locked(
const ecs_table_t *table);

/** Test a table for flags.
* Test if a table has all of the provided flags. See
* include/flecs/private/api_flags.h for a list of table flags that can be used
Expand Down
11 changes: 11 additions & 0 deletions include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5946,6 +5946,17 @@ void ecs_table_unlock(
ecs_world_t *world,
ecs_table_t *table);

/** Check if a table is locked.
* Can be used to check whether an operation that modifies the table would
* run into a table lock assert.
*
* @param table The table.
* @return True if the table is locked, false if not (or if table is NULL).
*/
FLECS_API
bool ecs_table_is_locked(
const ecs_table_t *table);

/** Test a table for flags.
* Test if a table has all of the provided flags. See
* include/flecs/private/api_flags.h for a list of table flags that can be used
Expand Down
9 changes: 9 additions & 0 deletions src/storage/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,15 @@ void ecs_table_unlock(
}
}

bool ecs_table_is_locked(
const ecs_table_t *table)
{
if (!table) {
return false;
}
return table->_->lock != 0;
}

const ecs_type_t* ecs_table_get_type(
const ecs_table_t *table)
{
Expand Down
1 change: 1 addition & 0 deletions test/core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3701,6 +3701,7 @@
"lock_table",
"recursive_lock_table",
"modify_after_lock",
"table_is_locked",
"get_object_from_stage",
"add_to_world_while_readonly",
"add_to_world_and_stage_while_readonly",
Expand Down
22 changes: 22 additions & 0 deletions test/core/src/SingleThreadStaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -2898,3 +2898,25 @@ void SingleThreadStaging_delete_stage_entity_after_progress(void) {

ecs_fini(world);
}

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

ECS_COMPONENT(world, Position);

ecs_entity_t e = ecs_new_w(world, Position);
ecs_table_t *table = ecs_get_table(world, e);
test_assert(table != NULL);

test_bool(ecs_table_is_locked(NULL), false);
test_bool(ecs_table_is_locked(table), false);
ecs_table_lock(world, table);
test_bool(ecs_table_is_locked(table), true);
ecs_table_lock(world, table);
ecs_table_unlock(world, table);
test_bool(ecs_table_is_locked(table), true);
ecs_table_unlock(world, table);
test_bool(ecs_table_is_locked(table), false);

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 @@ -3610,6 +3610,7 @@ void SingleThreadStaging_on_add_after_new_type_in_progress(void);
void SingleThreadStaging_lock_table(void);
void SingleThreadStaging_recursive_lock_table(void);
void SingleThreadStaging_modify_after_lock(void);
void SingleThreadStaging_table_is_locked(void);
void SingleThreadStaging_get_object_from_stage(void);
void SingleThreadStaging_add_to_world_while_readonly(void);
void SingleThreadStaging_add_to_world_and_stage_while_readonly(void);
Expand Down Expand Up @@ -17921,6 +17922,10 @@ bake_test_case SingleThreadStaging_testcases[] = {
"modify_after_lock",
SingleThreadStaging_modify_after_lock
},
{
"table_is_locked",
SingleThreadStaging_table_is_locked
},
{
"get_object_from_stage",
SingleThreadStaging_get_object_from_stage
Expand Down Expand Up @@ -18828,7 +18833,7 @@ static bake_test_suite suites[] = {
"SingleThreadStaging",
SingleThreadStaging_setup,
NULL,
66,
67,
SingleThreadStaging_testcases
},
{
Expand Down
Loading