Commit a5a12a59 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Lock the space before attempting to remove a particle from the system. This...

Lock the space before attempting to remove a particle from the system. This should prevent duplicated removals.
parent 5c66158b
......@@ -4340,6 +4340,8 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) {
/* One last action before death? */
hydro_remove_part(p, xp);
lock_lock(&e->s->lock);
/* Remove the particle entirely */
struct gpart *gp = p->gpart;
cell_remove_part(e, c, p, xp);
......@@ -4349,6 +4351,9 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) {
cell_remove_gpart(e, c, gp);
}
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
continue;
}
}
......@@ -4497,9 +4502,14 @@ void cell_drift_gpart(struct cell *c, const struct engine *e, int force) {
(gp->x[1] > dim[1]) || (gp->x[1] < 0.) || // y
(gp->x[2] > dim[2]) || (gp->x[2] < 0.)) { // z
lock_lock(&e->s->lock);
/* Remove the particle entirely */
cell_remove_gpart(e, c, gp);
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
continue;
}
}
......@@ -4627,6 +4637,8 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) {
(sp->x[1] > dim[1]) || (sp->x[1] < 0.) || // y
(sp->x[2] > dim[2]) || (sp->x[2] < 0.)) { // z
lock_lock(&e->s->lock);
/* Remove the particle entirely */
struct gpart *gp = sp->gpart;
cell_remove_spart(e, c, sp);
......@@ -4634,6 +4646,9 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) {
/* and it's gravity friend */
cell_remove_gpart(e, c, gp);
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
continue;
}
}
......@@ -4792,6 +4807,8 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) {
(bp->x[1] > dim[1]) || (bp->x[1] < 0.) || // y
(bp->x[2] > dim[2]) || (bp->x[2] < 0.)) { // z
lock_lock(&e->s->lock);
/* Remove the particle entirely */
struct gpart *gp = bp->gpart;
cell_remove_bpart(e, c, bp);
......@@ -4799,6 +4816,9 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) {
/* and it's gravity friend */
cell_remove_gpart(e, c, gp);
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
continue;
}
}
......
......@@ -3820,10 +3820,15 @@ void runner_do_swallow(struct runner *r, struct cell *c, int timer) {
message("BH %lld removing particle %lld", bp->id, p->id);
lock_lock(&e->s->lock);
/* Finally, remove the gas particle from the system */
struct gpart *gp = p->gpart;
cell_remove_part(e, c, p, xp);
cell_remove_gpart(e, c, gp);
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
}
/* In any case, prevent the particle from being re-swallowed */
......@@ -3853,11 +3858,16 @@ void runner_do_swallow(struct runner *r, struct cell *c, int timer) {
message("BH %lld removing particle %lld (foreign BH case)",
bp->id, p->id);
lock_lock(&e->s->lock);
/* Finally, remove the gas particle from the system */
struct gpart *gp = p->gpart;
cell_remove_part(e, c, p, xp);
cell_remove_gpart(e, c, gp);
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
found = 1;
break;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment