diff --git a/src/cell.c b/src/cell.c index 115a0e253e187758b448909558c02809dbd32f9f..63f28a4719d97f981f8feef980c3aa8de4d41afb 100644 --- a/src/cell.c +++ b/src/cell.c @@ -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; } } diff --git a/src/runner.c b/src/runner.c index 622bd337170ed9939be168ec63d125bf67b9bf69..8a966e9bc9acfd90aaafaa746b7ee7a699e44f19 100644 --- a/src/runner.c +++ b/src/runner.c @@ -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; }