commit 69f7598147fb5e22d882103216c1bbe854cbf43e
parent ac4d76a73ddec14cd66b25e05f5059899f2a6c8b
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 13 Jul 2018 16:52:05 +0200
Stop using dedicated atomic stuff for pointers
Diffstat:
1 file changed, 12 insertions(+), 18 deletions(-)
diff --git a/src/senc2d_scene_analyze.c b/src/senc2d_scene_analyze.c
@@ -26,16 +26,6 @@
#include <rsys/hash_table.h>
#include <rsys/dynamic_array.h>
-#if defined(COMPILER_GCC)
-#define ATOMIC_CAS_PTR(Atom, NewVal, Comparand) /* Return the initial value */ \
- ATOMIC_CAS((Atom), (NewVal), (Comparand))
-#elif defined(COMPILER_CL)
-#define ATOMIC_CAS_PTR(Atom, NewVal, Comparand) /* Return the initial value */ \
- (InterlockedCompareExchangePointer(Atom, NewVal, Comparand))
-#else
-#error "Undefined atomic operations"
-#endif
-
#include <star/s2d.h>
#include <omp.h>
@@ -549,7 +539,7 @@ group_connex_components
struct darray_ptr_component_descriptor* connex_components,
struct s2d_scene_view* s2d_view,
ATOMIC* next_enclosure_id,
- struct cc_descriptor** infinity_first_cc,
+ ATOMIC* infinity_first_cc,
/* Shared error status.
* We accept to overwritte an error with a different error */
res_T* res)
@@ -610,29 +600,31 @@ group_connex_components
}
/* If no hit, the component is facing an infinite medium */
if(S2D_HIT_NONE(&hit)) {
+ struct cc_descriptor* inf_first_cc;
cc->cc_group_root = CC_GROUP_ROOT_INFINITE;
cc->enclosure_id = 0;
/* Keep track of the first component facing infinity */
- ATOMIC_CAS_PTR(infinity_first_cc, cc, NULL);
- if((*infinity_first_cc)->medium != cc->medium) {
+ ATOMIC_CAS(infinity_first_cc, (ATOMIC)cc, (ATOMIC)NULL);
+ inf_first_cc = (struct cc_descriptor*)ATOMIC_GET(infinity_first_cc);
+ if(inf_first_cc->medium != cc->medium) {
/* Medium mismatch! Model topology is broken. */
const double* infinity_max_vrtx =
- positions[(*infinity_first_cc)->max_y_vrtx_id].vec;
+ positions[inf_first_cc->max_y_vrtx_id].vec;
log_err(desc->scene->dev,
"Medium mismatch found between vertex %lu and vertex %lu,"
" both facing infinity.\n",
- (unsigned long)(*infinity_first_cc)->max_y_vrtx_id,
+ (unsigned long) inf_first_cc->max_y_vrtx_id,
(unsigned long)cc->max_y_vrtx_id);
log_err(desc->scene->dev,
"Vertex %lu: (%g %g)\n",
- (unsigned long)(*infinity_first_cc)->max_y_vrtx_id,
+ (unsigned long) inf_first_cc->max_y_vrtx_id,
SPLIT2(infinity_max_vrtx));
log_err(desc->scene->dev,
"Vertex %lu: (%g %g)\n",
(unsigned long)cc->max_y_vrtx_id,
SPLIT2(max_vrtx));
log_err(desc->scene->dev, "Media: %lu VS %lu\n",
- (unsigned long)(*infinity_first_cc)->medium, (unsigned long)cc->medium);
+ (unsigned long) inf_first_cc->medium, (unsigned long)cc->medium);
*res = RES_BAD_ARG;
}
/* Same medium as previous members of the group: OK */
@@ -1079,7 +1071,9 @@ senc2d_scene_analyze
ATOMIC component_count = 0;
ATOMIC next_enclosure_id = 1;
/* Used as args to have shared vars between threads in functions */
- struct cc_descriptor* infinity_first_cc = NULL;
+ static_assert(sizeof(intptr_t) == sizeof(ATOMIC),
+ "Cannot use ATOMIC to store pointers");
+ ATOMIC infinity_first_cc = (ATOMIC) NULL;
res_T res = RES_OK;
res_T res2 = RES_OK;