rnatm

Load and structure data describing an atmosphere
git clone git://git.meso-star.fr/rnatm.git
Log | Files | Refs | README | LICENSE

commit 7698d182cec3bcff5598fd495372f53b3480b8fd
parent 44b69858c022bb9e641a553282e55fc24b716977
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  4 Nov 2022 17:47:23 +0100

Make loading from octree storage safe for multi-threading

Diffstat:
Msrc/rnatm.c | 24++++++++++++++++++++++--
Msrc/rnatm_c.h | 2++
2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/rnatm.c b/src/rnatm.c @@ -34,6 +34,7 @@ #include <rsys/cstr.h> #include <rsys/mem_allocator.h> +#include <rsys/mutex.h> #include <omp.h> @@ -235,6 +236,13 @@ create_rnatm } atm->svx_allocator_is_init = 1; + atm->mutex = mutex_create(); + if(!atm->mutex) { + log_err(atm, "unable to create Rad-Net ATMopshere library mutex\n"); + res = RES_MEM_ERR; + goto error; + } + exit: if(out_atm) *out_atm = atm; return res; @@ -250,6 +258,7 @@ release_rnatm(ref_T* ref) ASSERT(ref); if(atm->logger == &atm->logger__) logger_release(&atm->logger__); if(atm->svx) SVX(device_ref_put(atm->svx)); + if(atm->mutex) mutex_destroy(atm->mutex); darray_aerosol_release(&atm->aerosols); darray_accel_struct_release(&atm->accel_structs); darray_band_release(&atm->bands); @@ -750,14 +759,25 @@ make_sure_octree_is_loaded(struct rnatm* atm, const size_t istruct) accel_struct = darray_accel_struct_data_get(&atm->accel_structs) + istruct; if(accel_struct->octree) goto exit; /* The octree is already loaded */ + mutex_lock(atm->mutex); + /* Prepare to read the octree's data */ err = fsetpos(atm->octrees_storage, &accel_struct->fpos); - if(err != 0) { res = RES_IO_ERR; goto error; } + if(err != 0) { + res = RES_IO_ERR; + mutex_unlock(atm->mutex); + goto error; + } /* Deserialize the octree */ res = svx_tree_create_from_stream (atm->svx, atm->octrees_storage, &accel_struct->octree); - if(res != RES_OK) goto error; + if(res != RES_OK) { + mutex_unlock(atm->mutex); + goto error; + } + + mutex_unlock(atm->mutex); exit: return res; diff --git a/src/rnatm_c.h b/src/rnatm_c.h @@ -259,6 +259,8 @@ struct rnatm { struct mem_allocator* allocator; struct mem_allocator svx_allocator; + struct mutex* mutex; + struct svx_device* svx; int svx_allocator_is_init; ref_T ref;