commit 84945198e83707fb23388d4858849a97f4346fdf
parent 5441ee76ecbdd9721bcc10685f04b94f54087345
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 27 Jan 2021 13:24:50 +0100
Fix a possible deadlock un the octree building
Diffstat:
3 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/src/atrstm_partition.c b/src/atrstm_partition.c
@@ -97,7 +97,7 @@ pool_release(struct pool* pool)
}
struct part*
-pool_new_partition(struct pool* pool, const size_t ipart)
+pool_next_partition(struct pool* pool)
{
struct list_node* node = NULL;
struct part* part = NULL;
@@ -111,8 +111,10 @@ pool_new_partition(struct pool* pool, const size_t ipart)
part = NULL;
mutex_unlock(pool->mutex);
} else {
+ size_t ipart;
node = list_head(&pool->parts_free);
list_del(node);
+ ipart = pool->next_part_id++;
mutex_unlock(pool->mutex);
part = CONTAINER_OF(node, struct part, node);
@@ -151,7 +153,7 @@ pool_commit_partition(struct pool* pool, struct part* part)
}
struct part*
-pool_fetch_partition(struct pool* pool, size_t part_id)
+pool_fetch_partition(struct pool* pool, const size_t part_id)
{
struct part* found_part = NULL;
struct list_node* node = NULL;
diff --git a/src/atrstm_partition.h b/src/atrstm_partition.h
@@ -51,6 +51,8 @@ struct pool {
struct cond* cond_new;
struct cond* cond_fetch;
+ size_t next_part_id; /* Indentifier of the next partition */
+
struct mem_allocator* allocator;
ATOMIC error;
@@ -103,9 +105,8 @@ pool_release
/* Return a free partition. Wait until a free partition is available. Return
* NULL on error. */
extern LOCAL_SYM struct part*
-pool_new_partition
- (struct pool* pool,
- const size_t ipart); /* Identifier of the partition */
+pool_next_partition
+ (struct pool* pool);
/* Register the partition as a free partition against the pool */
extern LOCAL_SYM void
diff --git a/src/atrstm_setup_octrees.c b/src/atrstm_setup_octrees.c
@@ -266,7 +266,6 @@ voxelize_volumetric_mesh
double vxsz[3];
int64_t i;
int progress = 0;
- ATOMIC part_mcode = -1;
ATOMIC nparts_voxelized = 0;
ATOMIC res = RES_OK;
ASSERT(atrstm && pool);
@@ -309,7 +308,6 @@ voxelize_volumetric_mesh
struct part* part = NULL;
int pcent;
size_t n;
- uint64_t ipart;
res_T res_local = RES_OK;
/* Handle error */
@@ -319,14 +317,21 @@ voxelize_volumetric_mesh
prims = darray_prims_list_data_get(&prims_list)+ithread;
darray_size_t_clear(prims);
- ipart = (uint64_t)ATOMIC_INCR(&part_mcode);
- morton_xyz_decode_u21(ipart, part_ids);
+ part = pool_next_partition(pool);
+ if(!part) { /* An error occurs */
+ ATOMIC_SET(&res, RES_UNKNOWN_ERR);
+ continue;
+ }
+
+ morton_xyz_decode_u21((uint64_t)part->id, part_ids);
/* Check that the partition is not out of bound due to Morton indexing */
if(part_ids[0] >= nparts[0]
|| part_ids[1] >= nparts[1]
- || part_ids[2] >= nparts[2])
+ || part_ids[2] >= nparts[2]) {
+ pool_free_partition(pool, part);
continue;
+ }
/* Compute the partition AABB */
part_low[0] = (double)(part_ids[0] * part_def) * vxsz[0] + vol_low[0];
@@ -344,11 +349,6 @@ voxelize_volumetric_mesh
continue;
}
- part = pool_new_partition(pool, ipart);
- if(!part) { /* An error occurs */
- ATOMIC_SET(&res, res_local);
- continue;
- }
res = voxelize_partition
(atrstm, prims, part_low, part_upp, vxsz, refract_id, part);
if(res != RES_OK) {