diff --git a/src/atomic.h b/src/atomic.h index 97e0935f5b2dd76ec0dd6cb14699216e1e25d8b7..43da9823466b200c11dd55d43c9762c93df364ea 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -29,6 +29,7 @@ #define atomic_add(v, i) __sync_fetch_and_add(v, i) #define atomic_sub(v, i) __sync_fetch_and_sub(v, i) #define atomic_or(v, i) __sync_fetch_and_or(v, i) +#define atomic_and(v, i) __sync_fetch_and_and(v, i) #define atomic_inc(v) atomic_add(v, 1) #define atomic_dec(v) atomic_sub(v, 1) #define atomic_cas(v, o, n) __sync_val_compare_and_swap(v, o, n) diff --git a/src/cell.c b/src/cell.c index 392e5bb447d1d580c043452e32d876724a63bc61..f14fcb711f1fd6f181785656b654ad91b0a28fb0 100644 --- a/src/cell.c +++ b/src/cell.c @@ -4097,7 +4097,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { float cell_h_max = 0.f; /* Drift irrespective of cell flags? */ - force |= cell_get_flag(c, cell_flag_do_hydro_drift); + force = (force || cell_get_flag(c, cell_flag_do_hydro_drift)); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ @@ -4279,7 +4279,7 @@ void cell_drift_gpart(struct cell *c, const struct engine *e, int force) { struct gpart *const gparts = c->grav.parts; /* Drift irrespective of cell flags? */ - force |= cell_get_flag(c, cell_flag_do_grav_drift); + force = (force || cell_get_flag(c, cell_flag_do_grav_drift)); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ @@ -4407,7 +4407,7 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) { float cell_h_max = 0.f; /* Drift irrespective of cell flags? */ - force |= cell_get_flag(c, cell_flag_do_stars_drift); + force = (force || cell_get_flag(c, cell_flag_do_stars_drift)); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ @@ -4574,7 +4574,7 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) { float cell_h_max = 0.f; /* Drift irrespective of cell flags? */ - force |= cell_get_flag(c, cell_flag_do_bh_drift); + force = (force || cell_get_flag(c, cell_flag_do_bh_drift)); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ diff --git a/src/cell.h b/src/cell.h index e53b02036d92269ff63b8c1802bf6cf51d93f7e4..117eb708f2291426c5d546cd9363a4e42649cc87 100644 --- a/src/cell.h +++ b/src/cell.h @@ -269,7 +269,7 @@ struct cell { struct cell *super; /*! Cell flags bit-mask. */ - uint16_t flags; + uint32_t flags; /*! Hydro variables */ struct { @@ -1292,19 +1292,19 @@ __attribute__((always_inline)) INLINE static void cell_free_stars_sorts( /** Set the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_set_flag(struct cell *c, - uint16_t flag) { - c->flags |= flag; + uint32_t flag) { + atomic_or(&c->flags, flag); } /** Clear the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_clear_flag( - struct cell *c, uint16_t flag) { - c->flags &= ~flag; + struct cell *c, uint32_t flag) { + atomic_and(&c->flags, ~flag); } /** Get the given flag for the given cell. */ __attribute__((always_inline)) INLINE static int cell_get_flag( - const struct cell *c, uint16_t flag) { + const struct cell *c, uint32_t flag) { return (c->flags & flag) > 0; } diff --git a/src/runner.c b/src/runner.c index b6878935b3c1101da676435df06e54112e927467..1a15ce53711bc342eb5cfe11fd5abb5393133c22 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2938,7 +2938,7 @@ void runner_do_limiter(struct runner *r, struct cell *c, int force, int timer) { ti_gravity_beg_max = 0; /* Limit irrespective of cell flags? */ - force |= cell_get_flag(c, cell_flag_do_hydro_limiter); + force = (force || cell_get_flag(c, cell_flag_do_hydro_limiter)); /* Early abort? */ if (c->hydro.count == 0) {