commit cf4f816ae2023f193c4adec925ff10b419024e23
parent a5d3b10122778bc88957ba3170b15b455903989f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 23 Mar 2015 10:18:42 +0100
Make the s3d_shape_get_attrib function thread safe
Diffstat:
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/s3d_shape.c b/src/s3d_shape.c
@@ -387,6 +387,7 @@ s3d_shape_get_attrib
{
const uint32_t* ids;
float w;
+ res_T res = RES_OK;
if(!shape || !usage == S3D_ATTRIBS_COUNT__ || !uv || !attrib)
return RES_BAD_ARG;
@@ -394,18 +395,24 @@ s3d_shape_get_attrib
/* Unsupported mesh type */
if(shape->type != SHAPE_MESH)
return RES_BAD_ARG;
- /* The mesh haven't the required mesh attrib */
- if(usage != S3D_GEOMETRY_NORMAL
- && !darray_float_size_get(shape->data.mesh.attribs + usage))
- return RES_BAD_ARG;
- /* Out of bound primitive index */
- if(iprim >= darray_u32_size_get(&shape->data.mesh.indices) / 3/*# prim ids*/)
- return RES_BAD_ARG;
/* Unormalized barycentric coordinates */
w = 1.f - uv[0] - uv[1];
if(uv[0] < 0.f || uv[1] < 0.f || !eq_eps(w, 1.f, 1.e-6f))
return RES_BAD_ARG;
+ mutex_rw_rlock(shape->lock);
+
+ /* The mesh haven't the required mesh attrib */
+ if(usage != S3D_GEOMETRY_NORMAL
+ && !darray_float_size_get(shape->data.mesh.attribs + usage)) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+ /* Out of bound primitive index */
+ if(iprim >= darray_u32_size_get(&shape->data.mesh.indices) / 3/*# prim ids*/) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
ids = darray_u32_cdata_get(&shape->data.mesh.indices) + iprim * 3;
attrib->usage = usage;
@@ -445,7 +452,11 @@ s3d_shape_get_attrib
attrib->value[i] = v0[i]*uv[0] + v1[i]*uv[1] + v2[i]*w;
}
}
- return RES_OK;
+exit:
+ mutex_rw_unlock(shape->lock);
+ return res;
+error:
+ goto exit;
}
res_T